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; |
Brad Fitzpatrick | 0721861 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 88 | import android.os.StrictMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | import android.os.SystemClock; |
| 90 | import android.os.SystemProperties; |
| 91 | import android.os.TokenWatcher; |
| 92 | import android.provider.Settings; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 93 | import android.util.DisplayMetrics; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | import android.util.EventLog; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 95 | import android.util.Log; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 96 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | import android.util.SparseIntArray; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 98 | import android.util.TypedValue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | import android.view.Display; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 100 | import android.view.DragEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | import android.view.Gravity; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 102 | import android.view.HapticFeedbackConstants; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | import android.view.IApplicationToken; |
| 104 | import android.view.IOnKeyguardExitResult; |
| 105 | import android.view.IRotationWatcher; |
| 106 | import android.view.IWindow; |
| 107 | import android.view.IWindowManager; |
| 108 | import android.view.IWindowSession; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 109 | import android.view.InputChannel; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 110 | import android.view.InputDevice; |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 111 | import android.view.InputEvent; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 112 | import android.view.InputHandler; |
| 113 | import android.view.InputQueue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | import android.view.KeyEvent; |
| 115 | import android.view.MotionEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | import android.view.Surface; |
| 117 | import android.view.SurfaceSession; |
| 118 | import android.view.View; |
| 119 | import android.view.ViewTreeObserver; |
| 120 | import android.view.WindowManager; |
| 121 | import android.view.WindowManagerImpl; |
| 122 | import android.view.WindowManagerPolicy; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 123 | import android.view.Surface.OutOfResourcesException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | import android.view.WindowManager.LayoutParams; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 125 | import android.view.animation.AccelerateInterpolator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | import android.view.animation.Animation; |
| 127 | import android.view.animation.AnimationUtils; |
| 128 | import android.view.animation.Transformation; |
| 129 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 130 | import java.io.BufferedReader; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | import java.io.BufferedWriter; |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 132 | import java.io.DataInputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | import java.io.File; |
| 134 | import java.io.FileDescriptor; |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 135 | import java.io.FileInputStream; |
| 136 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | import java.io.IOException; |
| 138 | import java.io.OutputStream; |
| 139 | import java.io.OutputStreamWriter; |
| 140 | import java.io.PrintWriter; |
| 141 | import java.io.StringWriter; |
| 142 | import java.net.Socket; |
| 143 | import java.util.ArrayList; |
| 144 | import java.util.HashMap; |
| 145 | import java.util.HashSet; |
| 146 | import java.util.Iterator; |
| 147 | import java.util.List; |
| 148 | |
| 149 | /** {@hide} */ |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 150 | public class WindowManagerService extends IWindowManager.Stub |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 151 | implements Watchdog.Monitor { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | static final String TAG = "WindowManager"; |
| 153 | static final boolean DEBUG = false; |
| 154 | static final boolean DEBUG_FOCUS = false; |
| 155 | static final boolean DEBUG_ANIM = false; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 156 | static final boolean DEBUG_LAYOUT = false; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 157 | static final boolean DEBUG_RESIZE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | static final boolean DEBUG_LAYERS = false; |
| 159 | static final boolean DEBUG_INPUT = false; |
| 160 | static final boolean DEBUG_INPUT_METHOD = false; |
| 161 | static final boolean DEBUG_VISIBILITY = false; |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 162 | static final boolean DEBUG_WINDOW_MOVEMENT = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | static final boolean DEBUG_ORIENTATION = false; |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 164 | static final boolean DEBUG_CONFIGURATION = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 166 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 167 | static final boolean DEBUG_REORDER = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 168 | static final boolean DEBUG_WALLPAPER = false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 169 | static final boolean DEBUG_DRAG = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | static final boolean SHOW_TRANSACTIONS = false; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 171 | static final boolean HIDE_STACK_CRAWLS = true; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 172 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | static final boolean PROFILE_ORIENTATION = false; |
| 174 | static final boolean BLUR = true; |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 175 | static final boolean localLOGV = DEBUG; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 176 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | /** How much to multiply the policy's type layer, to reserve room |
| 178 | * for multiple windows of the same type and Z-ordering adjustment |
| 179 | * with TYPE_LAYER_OFFSET. */ |
| 180 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 181 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 183 | * or below others in the same layer. */ |
| 184 | static final int TYPE_LAYER_OFFSET = 1000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 185 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | /** How much to increment the layer for each window, to reserve room |
| 187 | * for effect surfaces between them. |
| 188 | */ |
| 189 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | /** The maximum length we will accept for a loaded animation duration: |
| 192 | * this is 10 seconds. |
| 193 | */ |
| 194 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 195 | |
| 196 | /** Amount of time (in milliseconds) to animate the dim surface from one |
| 197 | * value to another, when no window animation is driving it. |
| 198 | */ |
| 199 | static final int DEFAULT_DIM_DURATION = 200; |
| 200 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 201 | /** Amount of time (in milliseconds) to animate the fade-in-out transition for |
| 202 | * compatible windows. |
| 203 | */ |
| 204 | static final int DEFAULT_FADE_IN_OUT_DURATION = 400; |
| 205 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 | /** Adjustment to time to perform a dim, to make it more dramatic. |
| 207 | */ |
| 208 | static final int DIM_DURATION_MULTIPLIER = 6; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 209 | |
| 210 | // Maximum number of milliseconds to wait for input event injection. |
| 211 | // FIXME is this value reasonable? |
| 212 | private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 213 | |
| 214 | // Default input dispatching timeout in nanoseconds. |
| 215 | private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 216 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 218 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 219 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 220 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 221 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | private static final String SYSTEM_SECURE = "ro.secure"; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 223 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | |
| 225 | /** |
| 226 | * Condition waited on by {@link #reenableKeyguard} to know the call to |
| 227 | * the window policy has finished. |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 228 | * This is set to true only if mKeyguardTokenWatcher.acquired() has |
| 229 | * actually disabled the keyguard. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | */ |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 231 | private boolean mKeyguardDisabled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 233 | private static final int ALLOW_DISABLE_YES = 1; |
| 234 | private static final int ALLOW_DISABLE_NO = 0; |
| 235 | private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager |
| 236 | private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher |
| 237 | |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 238 | final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher( |
| 239 | new Handler(), "WindowManagerService.mKeyguardTokenWatcher") { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | public void acquired() { |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 241 | if (shouldAllowDisableKeyguard()) { |
| 242 | mPolicy.enableKeyguard(false); |
| 243 | mKeyguardDisabled = true; |
| 244 | } else { |
| 245 | Log.v(TAG, "Not disabling keyguard since device policy is enforced"); |
| 246 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | } |
| 248 | public void released() { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 249 | mPolicy.enableKeyguard(true); |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 250 | synchronized (mKeyguardTokenWatcher) { |
| 251 | mKeyguardDisabled = false; |
| 252 | mKeyguardTokenWatcher.notifyAll(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | }; |
| 256 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 257 | final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 258 | @Override |
| 259 | public void onReceive(Context context, Intent intent) { |
| 260 | mPolicy.enableKeyguard(true); |
| 261 | synchronized(mKeyguardTokenWatcher) { |
| 262 | // lazily evaluate this next time we're asked to disable keyguard |
| 263 | mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; |
| 264 | mKeyguardDisabled = false; |
| 265 | } |
| 266 | } |
| 267 | }; |
| 268 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 269 | final Context mContext; |
| 270 | |
| 271 | final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 272 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 273 | final boolean mLimitedAlphaCompositing; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 274 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 276 | |
| 277 | final IActivityManager mActivityManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 278 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 279 | final IBatteryStats mBatteryStats; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 280 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 281 | /** |
| 282 | * All currently active sessions with clients. |
| 283 | */ |
| 284 | final HashSet<Session> mSessions = new HashSet<Session>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 285 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | /** |
| 287 | * Mapping from an IWindow IBinder to the server's Window object. |
| 288 | * This is also used as the lock for all of our state. |
| 289 | */ |
| 290 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 291 | |
| 292 | /** |
| 293 | * Mapping from a token IBinder to a WindowToken object. |
| 294 | */ |
| 295 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 296 | new HashMap<IBinder, WindowToken>(); |
| 297 | |
| 298 | /** |
| 299 | * The same tokens as mTokenMap, stored in a list for efficient iteration |
| 300 | * over them. |
| 301 | */ |
| 302 | final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 303 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | /** |
| 305 | * Window tokens that are in the process of exiting, but still |
| 306 | * on screen for animations. |
| 307 | */ |
| 308 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 309 | |
| 310 | /** |
| 311 | * Z-ordered (bottom-most first) list of all application tokens, for |
| 312 | * controlling the ordering of windows in different applications. This |
| 313 | * contains WindowToken objects. |
| 314 | */ |
| 315 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
| 316 | |
| 317 | /** |
| 318 | * Application tokens that are in the process of exiting, but still |
| 319 | * on screen for animations. |
| 320 | */ |
| 321 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 322 | |
| 323 | /** |
| 324 | * List of window tokens that have finished starting their application, |
| 325 | * and now need to have the policy remove their windows. |
| 326 | */ |
| 327 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 328 | |
| 329 | /** |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 330 | * This was the app token that was used to retrieve the last enter |
| 331 | * animation. It will be used for the next exit animation. |
| 332 | */ |
| 333 | AppWindowToken mLastEnterAnimToken; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 334 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 335 | /** |
| 336 | * These were the layout params used to retrieve the last enter animation. |
| 337 | * They will be used for the next exit animation. |
| 338 | */ |
| 339 | LayoutParams mLastEnterAnimParams; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 340 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 341 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | * Z-ordered (bottom-most first) list of all Window objects. |
| 343 | */ |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 344 | final ArrayList<WindowState> mWindows = new ArrayList<WindowState>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 345 | |
| 346 | /** |
| 347 | * Windows that are being resized. Used so we can tell the client about |
| 348 | * the resize after closing the transaction in which we resized the |
| 349 | * underlying surface. |
| 350 | */ |
| 351 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 352 | |
| 353 | /** |
| 354 | * Windows whose animations have ended and now must be removed. |
| 355 | */ |
| 356 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 357 | |
| 358 | /** |
| 359 | * Windows whose surface should be destroyed. |
| 360 | */ |
| 361 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 362 | |
| 363 | /** |
| 364 | * Windows that have lost input focus and are waiting for the new |
| 365 | * focus window to be displayed before they are told about this. |
| 366 | */ |
| 367 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 368 | |
| 369 | /** |
| 370 | * This is set when we have run out of memory, and will either be an empty |
| 371 | * list or contain windows that need to be force removed. |
| 372 | */ |
| 373 | ArrayList<WindowState> mForceRemoves; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 374 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 375 | IInputMethodManager mInputMethodManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 376 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 377 | SurfaceSession mFxSession; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 378 | private DimAnimator mDimAnimator = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 379 | Surface mBlurSurface; |
| 380 | boolean mBlurShown; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 381 | Watermark mWatermark; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 382 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 383 | int mTransactionSequence = 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 384 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 385 | final float[] mTmpFloats = new float[9]; |
| 386 | |
| 387 | boolean mSafeMode; |
| 388 | boolean mDisplayEnabled = false; |
| 389 | boolean mSystemBooted = false; |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 390 | int mInitialDisplayWidth = 0; |
| 391 | int mInitialDisplayHeight = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 392 | int mRotation = 0; |
| 393 | int mRequestedRotation = 0; |
| 394 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 395 | int mLastRotationFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 396 | ArrayList<IRotationWatcher> mRotationWatchers |
| 397 | = new ArrayList<IRotationWatcher>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 398 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 399 | boolean mLayoutNeeded = true; |
| 400 | boolean mAnimationPending = false; |
| 401 | boolean mDisplayFrozen = false; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 402 | boolean mWaitingForConfig = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 403 | boolean mWindowsFreezingScreen = false; |
| 404 | long mFreezeGcPending = 0; |
| 405 | int mAppsFreezingScreen = 0; |
| 406 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 407 | int mLayoutSeq = 0; |
| 408 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 409 | // State while inside of layoutAndPlaceSurfacesLocked(). |
| 410 | boolean mFocusMayChange; |
| 411 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 412 | Configuration mCurConfiguration = new Configuration(); |
| 413 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | // This is held as long as we have the screen frozen, to give us time to |
| 415 | // perform a rotation animation when turning off shows the lock screen which |
| 416 | // changes the orientation. |
| 417 | PowerManager.WakeLock mScreenFrozenLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 418 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | // State management of app transitions. When we are preparing for a |
| 420 | // transition, mNextAppTransition will be the kind of transition to |
| 421 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 422 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 423 | // made visible or hidden at the next transition. |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 424 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 425 | String mNextAppTransitionPackage; |
| 426 | int mNextAppTransitionEnter; |
| 427 | int mNextAppTransitionExit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 428 | boolean mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 429 | boolean mAppTransitionRunning = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 430 | boolean mAppTransitionTimeout = false; |
| 431 | boolean mStartingIconInTransition = false; |
| 432 | boolean mSkipAppTransitionAnimation = false; |
| 433 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 434 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 435 | final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>(); |
| 436 | final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 437 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 438 | Display mDisplay; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 439 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 440 | H mH = new H(); |
| 441 | |
| 442 | WindowState mCurrentFocus = null; |
| 443 | WindowState mLastFocus = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 444 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 445 | // This just indicates the window the input method is on top of, not |
| 446 | // necessarily the window its input is going to. |
| 447 | WindowState mInputMethodTarget = null; |
| 448 | WindowState mUpcomingInputMethodTarget = null; |
| 449 | boolean mInputMethodTargetWaitingAnim; |
| 450 | int mInputMethodAnimLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 451 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 452 | WindowState mInputMethodWindow = null; |
| 453 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 454 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 455 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 456 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 457 | // If non-null, this is the currently visible window that is associated |
| 458 | // with the wallpaper. |
| 459 | WindowState mWallpaperTarget = null; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 460 | // If non-null, we are in the middle of animating from one wallpaper target |
| 461 | // to another, and this is the lower one in Z-order. |
| 462 | WindowState mLowerWallpaperTarget = null; |
| 463 | // If non-null, we are in the middle of animating from one wallpaper target |
| 464 | // to another, and this is the higher one in Z-order. |
| 465 | WindowState mUpperWallpaperTarget = null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 466 | int mWallpaperAnimLayerAdjustment; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 467 | float mLastWallpaperX = -1; |
| 468 | float mLastWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 469 | float mLastWallpaperXStep = -1; |
| 470 | float mLastWallpaperYStep = -1; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 471 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 472 | // changing its scroll position. |
| 473 | WindowState mWaitingOnWallpaper; |
| 474 | // The last time we had a timeout when waiting for a wallpaper. |
| 475 | long mLastWallpaperTimeoutTime; |
| 476 | // We give a wallpaper up to 150ms to finish scrolling. |
| 477 | static final long WALLPAPER_TIMEOUT = 150; |
| 478 | // Time we wait after a timeout before trying to wait again. |
| 479 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 480 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 481 | AppWindowToken mFocusedApp = null; |
| 482 | |
| 483 | PowerManagerService mPowerManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 484 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 485 | float mWindowAnimationScale = 1.0f; |
| 486 | float mTransitionAnimationScale = 1.0f; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 487 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 488 | final InputManager mInputManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 489 | |
| 490 | // Who is holding the screen on. |
| 491 | Session mHoldingScreenOn; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 492 | PowerManager.WakeLock mHoldingScreenWakeLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 493 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 494 | boolean mTurnOnScreen; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 495 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | /** |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 497 | * Drag/drop state |
| 498 | */ |
| 499 | class DragState { |
| 500 | IBinder mToken; |
| 501 | Surface mSurface; |
| 502 | boolean mLocalOnly; |
| 503 | ClipData mData; |
| 504 | ClipDescription mDataDescription; |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 505 | boolean mDragResult; |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 506 | float mCurrentX, mCurrentY; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 507 | float mThumbOffsetX, mThumbOffsetY; |
| 508 | InputChannel mServerChannel, mClientChannel; |
| 509 | WindowState mTargetWindow; |
| 510 | ArrayList<WindowState> mNotifiedWindows; |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 511 | boolean mDragInProgress; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 512 | |
| 513 | private final Rect tmpRect = new Rect(); |
| 514 | |
| 515 | DragState(IBinder token, Surface surface, boolean localOnly) { |
| 516 | mToken = token; |
| 517 | mSurface = surface; |
| 518 | mLocalOnly = localOnly; |
| 519 | mNotifiedWindows = new ArrayList<WindowState>(); |
| 520 | } |
| 521 | |
| 522 | void reset() { |
| 523 | if (mSurface != null) { |
| 524 | mSurface.destroy(); |
| 525 | } |
| 526 | mSurface = null; |
| 527 | mLocalOnly = false; |
| 528 | mToken = null; |
| 529 | mData = null; |
| 530 | mThumbOffsetX = mThumbOffsetY = 0; |
| 531 | mNotifiedWindows = null; |
| 532 | } |
| 533 | |
| 534 | void register() { |
| 535 | if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel"); |
| 536 | if (mClientChannel != null) { |
| 537 | Slog.e(TAG, "Duplicate register of drag input channel"); |
| 538 | } else { |
| 539 | InputChannel[] channels = InputChannel.openInputChannelPair("drag"); |
| 540 | mServerChannel = channels[0]; |
| 541 | mClientChannel = channels[1]; |
| 542 | mInputManager.registerInputChannel(mServerChannel); |
| 543 | InputQueue.registerInputChannel(mClientChannel, mDragInputHandler, |
| 544 | mH.getLooper().getQueue()); |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | void unregister() { |
| 549 | if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel"); |
| 550 | if (mClientChannel == null) { |
| 551 | Slog.e(TAG, "Unregister of nonexistent drag input channel"); |
| 552 | } else { |
| 553 | mInputManager.unregisterInputChannel(mServerChannel); |
| 554 | InputQueue.unregisterInputChannel(mClientChannel); |
| 555 | mClientChannel.dispose(); |
Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 556 | mServerChannel.dispose(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 557 | mClientChannel = null; |
| 558 | mServerChannel = null; |
| 559 | } |
| 560 | } |
| 561 | |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 562 | int getDragLayerLw() { |
| 563 | return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG) |
| 564 | * TYPE_LAYER_MULTIPLIER |
| 565 | + TYPE_LAYER_OFFSET; |
| 566 | } |
| 567 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 568 | /* call out to each visible window/session informing it about the drag |
| 569 | */ |
Chris Tate | b8203e9 | 2010-10-12 14:23:21 -0700 | [diff] [blame] | 570 | void broadcastDragStartedLw(final float touchX, final float touchY) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 571 | // Cache a base-class instance of the clip metadata so that parceling |
| 572 | // works correctly in calling out to the apps. |
Dianne Hackborn | f834dfa | 2010-10-26 12:43:57 -0700 | [diff] [blame] | 573 | mDataDescription = mData.getDescription(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 574 | mNotifiedWindows.clear(); |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 575 | mDragInProgress = true; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 576 | |
| 577 | if (DEBUG_DRAG) { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 578 | Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")"); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 579 | } |
| 580 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 581 | final int N = mWindows.size(); |
| 582 | for (int i = 0; i < N; i++) { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 583 | sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 584 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the |
| 588 | * designated window is potentially a drop recipient. There are race situations |
| 589 | * around DRAG_ENDED broadcast, so we make sure that once we've declared that |
| 590 | * 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] | 591 | * |
| 592 | * This method clones the 'event' parameter if it's being delivered to the same |
| 593 | * 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] | 594 | */ |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 595 | private void sendDragStartedLw(WindowState newWin, float touchX, float touchY, |
| 596 | ClipDescription desc) { |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 597 | if (mDragInProgress && newWin.isPotentialDragTarget()) { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 598 | DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED, |
| 599 | touchX - newWin.mFrame.left, touchY - newWin.mFrame.top, |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 600 | desc, null, false); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 601 | try { |
| 602 | newWin.mClient.dispatchDragEvent(event); |
| 603 | // track each window that we've notified that the drag is starting |
| 604 | mNotifiedWindows.add(newWin); |
| 605 | } catch (RemoteException e) { |
| 606 | Slog.w(TAG, "Unable to drag-start window " + newWin); |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 607 | } finally { |
| 608 | // if the callee was local, the dispatch has already recycled the event |
| 609 | if (Process.myPid() != newWin.mSession.mPid) { |
| 610 | event.recycle(); |
| 611 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 612 | } |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | /* helper - construct and send a DRAG_STARTED event only if the window has not |
| 617 | * previously been notified, i.e. it became visible after the drag operation |
| 618 | * was begun. This is a rare case. |
| 619 | */ |
| 620 | private void sendDragStartedIfNeededLw(WindowState newWin) { |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 621 | if (mDragInProgress) { |
| 622 | // If we have sent the drag-started, we needn't do so again |
| 623 | for (WindowState ws : mNotifiedWindows) { |
| 624 | if (ws == newWin) { |
| 625 | return; |
| 626 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 627 | } |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 628 | if (DEBUG_DRAG) { |
Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 629 | Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin); |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 630 | } |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 631 | sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 632 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 633 | } |
| 634 | |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 635 | void broadcastDragEndedLw() { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 636 | if (DEBUG_DRAG) { |
| 637 | Slog.d(TAG, "broadcasting DRAG_ENDED"); |
| 638 | } |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 639 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED, |
| 640 | 0, 0, null, null, mDragResult); |
| 641 | for (WindowState ws: mNotifiedWindows) { |
| 642 | try { |
| 643 | ws.mClient.dispatchDragEvent(evt); |
| 644 | } catch (RemoteException e) { |
| 645 | Slog.w(TAG, "Unable to drag-end window " + ws); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 646 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 647 | } |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 648 | mNotifiedWindows.clear(); |
| 649 | mDragInProgress = false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 650 | evt.recycle(); |
| 651 | } |
| 652 | |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 653 | void endDragLw() { |
| 654 | mDragState.broadcastDragEndedLw(); |
| 655 | |
| 656 | // stop intercepting input |
| 657 | mDragState.unregister(); |
| 658 | mInputMonitor.updateInputWindowsLw(); |
| 659 | |
| 660 | // free our resources and drop all the object references |
| 661 | mDragState.reset(); |
| 662 | mDragState = null; |
| 663 | } |
| 664 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 665 | void notifyMoveLw(float x, float y) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 666 | final int myPid = Process.myPid(); |
| 667 | |
| 668 | // Move the surface to the given touch |
| 669 | mSurface.openTransaction(); |
| 670 | mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY)); |
| 671 | mSurface.closeTransaction(); |
| 672 | |
| 673 | // Tell the affected window |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 674 | WindowState touchedWin = getTouchedWinAtPointLw(x, y); |
| 675 | try { |
| 676 | // have we dragged over a new window? |
| 677 | if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) { |
| 678 | if (DEBUG_DRAG) { |
| 679 | Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow); |
| 680 | } |
| 681 | // force DRAG_EXITED_EVENT if appropriate |
| 682 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED, |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 683 | x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top, |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 684 | null, null, false); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 685 | mTargetWindow.mClient.dispatchDragEvent(evt); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 686 | if (myPid != mTargetWindow.mSession.mPid) { |
| 687 | evt.recycle(); |
| 688 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 689 | } |
| 690 | if (touchedWin != null) { |
Chris Tate | 9d1ab88 | 2010-11-02 15:55:39 -0700 | [diff] [blame] | 691 | if (false && DEBUG_DRAG) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 692 | Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin); |
| 693 | } |
| 694 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION, |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 695 | x - touchedWin.mFrame.left, y - touchedWin.mFrame.top, |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 696 | null, null, false); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 697 | touchedWin.mClient.dispatchDragEvent(evt); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 698 | if (myPid != touchedWin.mSession.mPid) { |
| 699 | evt.recycle(); |
| 700 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 701 | } |
| 702 | } catch (RemoteException e) { |
| 703 | Slog.w(TAG, "can't send drag notification to windows"); |
| 704 | } |
| 705 | mTargetWindow = touchedWin; |
| 706 | } |
| 707 | |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 708 | // Tell the drop target about the data. Returns 'true' if we can immediately |
| 709 | // dispatch the global drag-ended message, 'false' if we need to wait for a |
| 710 | // result from the recipient. |
| 711 | boolean notifyDropLw(float x, float y) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 712 | WindowState touchedWin = getTouchedWinAtPointLw(x, y); |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 713 | if (touchedWin == null) { |
| 714 | // "drop" outside a valid window -- no recipient to apply a |
| 715 | // timeout to, and we can send the drag-ended message immediately. |
| 716 | mDragResult = false; |
| 717 | return true; |
| 718 | } |
| 719 | |
| 720 | if (DEBUG_DRAG) { |
| 721 | Slog.d(TAG, "sending DROP to " + touchedWin); |
| 722 | } |
| 723 | final int myPid = Process.myPid(); |
| 724 | final IBinder token = touchedWin.mClient.asBinder(); |
| 725 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP, |
| 726 | x - touchedWin.mFrame.left, y - touchedWin.mFrame.top, |
| 727 | null, mData, false); |
| 728 | try { |
| 729 | touchedWin.mClient.dispatchDragEvent(evt); |
| 730 | |
| 731 | // 5 second timeout for this window to respond to the drop |
| 732 | mH.removeMessages(H.DRAG_END_TIMEOUT, token); |
| 733 | Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token); |
| 734 | mH.sendMessageDelayed(msg, 5000); |
| 735 | } catch (RemoteException e) { |
| 736 | Slog.w(TAG, "can't send drop notification to win " + touchedWin); |
| 737 | return true; |
| 738 | } finally { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 739 | if (myPid != touchedWin.mSession.mPid) { |
| 740 | evt.recycle(); |
| 741 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 742 | } |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 743 | mToken = token; |
| 744 | return false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | // Find the visible, touch-deliverable window under the given point |
| 748 | private WindowState getTouchedWinAtPointLw(float xf, float yf) { |
| 749 | WindowState touchedWin = null; |
| 750 | final int x = (int) xf; |
| 751 | final int y = (int) yf; |
| 752 | final ArrayList<WindowState> windows = mWindows; |
| 753 | final int N = windows.size(); |
| 754 | for (int i = N - 1; i >= 0; i--) { |
| 755 | WindowState child = windows.get(i); |
| 756 | final int flags = child.mAttrs.flags; |
| 757 | if (!child.isVisibleLw()) { |
| 758 | // not visible == don't tell about drags |
| 759 | continue; |
| 760 | } |
| 761 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 762 | // not touchable == don't tell about drags |
| 763 | continue; |
| 764 | } |
| 765 | // account for the window's decor etc |
| 766 | tmpRect.set(child.mFrame); |
| 767 | if (child.mTouchableInsets == ViewTreeObserver |
| 768 | .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) { |
| 769 | // The point is inside of the window if it is |
| 770 | // inside the frame, AND the content part of that |
| 771 | // frame that was given by the application. |
| 772 | tmpRect.left += child.mGivenContentInsets.left; |
| 773 | tmpRect.top += child.mGivenContentInsets.top; |
| 774 | tmpRect.right -= child.mGivenContentInsets.right; |
| 775 | tmpRect.bottom -= child.mGivenContentInsets.bottom; |
| 776 | } else if (child.mTouchableInsets == ViewTreeObserver |
| 777 | .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) { |
| 778 | // The point is inside of the window if it is |
| 779 | // inside the frame, AND the visible part of that |
| 780 | // frame that was given by the application. |
| 781 | tmpRect.left += child.mGivenVisibleInsets.left; |
| 782 | tmpRect.top += child.mGivenVisibleInsets.top; |
| 783 | tmpRect.right -= child.mGivenVisibleInsets.right; |
| 784 | tmpRect.bottom -= child.mGivenVisibleInsets.bottom; |
| 785 | } |
| 786 | final int touchFlags = flags & |
| 787 | (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 788 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
| 789 | if (tmpRect.contains(x, y) || touchFlags == 0) { |
| 790 | // Found it |
| 791 | touchedWin = child; |
| 792 | break; |
| 793 | } |
| 794 | } |
| 795 | |
| 796 | return touchedWin; |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | DragState mDragState = null; |
| 801 | private final InputHandler mDragInputHandler = new BaseInputHandler() { |
| 802 | @Override |
| 803 | public void handleMotion(MotionEvent event, Runnable finishedCallback) { |
| 804 | boolean endDrag = false; |
| 805 | final float newX = event.getRawX(); |
| 806 | final float newY = event.getRawY(); |
| 807 | |
| 808 | try { |
| 809 | if (mDragState != null) { |
| 810 | switch (event.getAction()) { |
| 811 | case MotionEvent.ACTION_DOWN: { |
| 812 | if (DEBUG_DRAG) { |
| 813 | Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer"); |
| 814 | } |
| 815 | } break; |
| 816 | |
| 817 | case MotionEvent.ACTION_MOVE: { |
| 818 | synchronized (mWindowMap) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 819 | // move the surface and tell the involved window(s) where we are |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 820 | mDragState.notifyMoveLw(newX, newY); |
| 821 | } |
| 822 | } break; |
| 823 | |
| 824 | case MotionEvent.ACTION_UP: { |
| 825 | if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at " |
| 826 | + newX + "," + newY); |
| 827 | synchronized (mWindowMap) { |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 828 | endDrag = mDragState.notifyDropLw(newX, newY); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 829 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 830 | } break; |
| 831 | |
| 832 | case MotionEvent.ACTION_CANCEL: { |
| 833 | if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!"); |
| 834 | endDrag = true; |
| 835 | } break; |
| 836 | } |
| 837 | |
| 838 | if (endDrag) { |
| 839 | if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state"); |
| 840 | // tell all the windows that the drag has ended |
Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 841 | synchronized (mWindowMap) { |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 842 | mDragState.endDragLw(); |
Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 843 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 844 | } |
| 845 | } |
| 846 | } catch (Exception e) { |
| 847 | Slog.e(TAG, "Exception caught by drag handleMotion", e); |
| 848 | } finally { |
| 849 | finishedCallback.run(); |
| 850 | } |
| 851 | } |
| 852 | }; |
| 853 | |
| 854 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 855 | * Whether the UI is currently running in touch mode (not showing |
| 856 | * navigational focus because the user is directly pressing the screen). |
| 857 | */ |
| 858 | boolean mInTouchMode = false; |
| 859 | |
| 860 | private ViewServer mViewServer; |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 861 | private ArrayList<WindowChangeListener> mWindowChangeListeners = |
| 862 | new ArrayList<WindowChangeListener>(); |
| 863 | private boolean mWindowsChanged = false; |
| 864 | |
| 865 | public interface WindowChangeListener { |
| 866 | public void windowsChanged(); |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 867 | public void focusChanged(); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 868 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 869 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 870 | final Configuration mTempConfiguration = new Configuration(); |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 871 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 872 | |
| 873 | // The frame use to limit the size of the app running in compatibility mode. |
| 874 | Rect mCompatibleScreenFrame = new Rect(); |
| 875 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 876 | Surface mBackgroundFillerSurface = null; |
| 877 | boolean mBackgroundFillerShown = false; |
| 878 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 879 | public static WindowManagerService main(Context context, |
| 880 | PowerManagerService pm, boolean haveInputMethods) { |
| 881 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 882 | thr.start(); |
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 (thr) { |
| 885 | while (thr.mService == null) { |
| 886 | try { |
| 887 | thr.wait(); |
| 888 | } catch (InterruptedException e) { |
| 889 | } |
| 890 | } |
| 891 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 892 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 893 | return thr.mService; |
| 894 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 895 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 896 | static class WMThread extends Thread { |
| 897 | WindowManagerService mService; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 898 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 899 | private final Context mContext; |
| 900 | private final PowerManagerService mPM; |
| 901 | private final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 902 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 903 | public WMThread(Context context, PowerManagerService pm, |
| 904 | boolean haveInputMethods) { |
| 905 | super("WindowManager"); |
| 906 | mContext = context; |
| 907 | mPM = pm; |
| 908 | mHaveInputMethods = haveInputMethods; |
| 909 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 910 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 911 | public void run() { |
| 912 | Looper.prepare(); |
| 913 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 914 | mHaveInputMethods); |
| 915 | android.os.Process.setThreadPriority( |
| 916 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 917 | android.os.Process.setCanSelfBackground(false); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 918 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 919 | synchronized (this) { |
| 920 | mService = s; |
| 921 | notifyAll(); |
| 922 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 923 | |
Brad Fitzpatrick | 0721861 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 924 | // For debug builds, log event loop stalls to dropbox for analysis. |
| 925 | if (StrictMode.conditionallyEnableDebugLogging()) { |
| 926 | Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper"); |
| 927 | } |
| 928 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 929 | Looper.loop(); |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | static class PolicyThread extends Thread { |
| 934 | private final WindowManagerPolicy mPolicy; |
| 935 | private final WindowManagerService mService; |
| 936 | private final Context mContext; |
| 937 | private final PowerManagerService mPM; |
| 938 | boolean mRunning = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 939 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 940 | public PolicyThread(WindowManagerPolicy policy, |
| 941 | WindowManagerService service, Context context, |
| 942 | PowerManagerService pm) { |
| 943 | super("WindowManagerPolicy"); |
| 944 | mPolicy = policy; |
| 945 | mService = service; |
| 946 | mContext = context; |
| 947 | mPM = pm; |
| 948 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 949 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 950 | public void run() { |
| 951 | Looper.prepare(); |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 952 | WindowManagerPolicyThread.set(this, Looper.myLooper()); |
| 953 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 954 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 955 | // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 956 | android.os.Process.setThreadPriority( |
| 957 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 958 | android.os.Process.setCanSelfBackground(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 959 | mPolicy.init(mContext, mService, mPM); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 960 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 961 | synchronized (this) { |
| 962 | mRunning = true; |
| 963 | notifyAll(); |
| 964 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 965 | |
Brad Fitzpatrick | 0721861 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 966 | // For debug builds, log event loop stalls to dropbox for analysis. |
| 967 | if (StrictMode.conditionallyEnableDebugLogging()) { |
| 968 | Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper"); |
| 969 | } |
| 970 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 971 | Looper.loop(); |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | private WindowManagerService(Context context, PowerManagerService pm, |
| 976 | boolean haveInputMethods) { |
| 977 | mContext = context; |
| 978 | mHaveInputMethods = haveInputMethods; |
| 979 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 980 | com.android.internal.R.bool.config_sf_limitedAlpha); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 981 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 982 | mPowerManager = pm; |
| 983 | mPowerManager.setPolicy(mPolicy); |
| 984 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 985 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 986 | "SCREEN_FROZEN"); |
| 987 | mScreenFrozenLock.setReferenceCounted(false); |
| 988 | |
| 989 | mActivityManager = ActivityManagerNative.getDefault(); |
| 990 | mBatteryStats = BatteryStatsService.getService(); |
| 991 | |
| 992 | // Get persisted window scale setting |
| 993 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 994 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 995 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 996 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 997 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 998 | // Track changes to DevicePolicyManager state so we can enable/disable keyguard. |
| 999 | IntentFilter filter = new IntentFilter(); |
| 1000 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 1001 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 1002 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1003 | mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 1004 | "KEEP_SCREEN_ON_FLAG"); |
| 1005 | mHoldingScreenWakeLock.setReferenceCounted(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1006 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1007 | mInputManager = new InputManager(context, this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1008 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1009 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 1010 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1011 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1012 | synchronized (thr) { |
| 1013 | while (!thr.mRunning) { |
| 1014 | try { |
| 1015 | thr.wait(); |
| 1016 | } catch (InterruptedException e) { |
| 1017 | } |
| 1018 | } |
| 1019 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1020 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1021 | mInputManager.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1022 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1023 | // Add ourself to the Watchdog monitors. |
| 1024 | Watchdog.getInstance().addMonitor(this); |
| 1025 | } |
| 1026 | |
| 1027 | @Override |
| 1028 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 1029 | throws RemoteException { |
| 1030 | try { |
| 1031 | return super.onTransact(code, data, reply, flags); |
| 1032 | } catch (RuntimeException e) { |
| 1033 | // The window manager only throws security exceptions, so let's |
| 1034 | // log all others. |
| 1035 | if (!(e instanceof SecurityException)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1036 | Slog.e(TAG, "Window Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1037 | } |
| 1038 | throw e; |
| 1039 | } |
| 1040 | } |
| 1041 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1042 | private void placeWindowAfter(WindowState pos, WindowState window) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1043 | final int i = mWindows.indexOf(pos); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1044 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1045 | TAG, "Adding window " + window + " at " |
| 1046 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 1047 | mWindows.add(i+1, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1048 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1049 | } |
| 1050 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1051 | private void placeWindowBefore(WindowState pos, WindowState window) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1052 | final int i = mWindows.indexOf(pos); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1053 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1054 | TAG, "Adding window " + window + " at " |
| 1055 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 1056 | mWindows.add(i, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1057 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | //This method finds out the index of a window that has the same app token as |
| 1061 | //win. used for z ordering the windows in mWindows |
| 1062 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 1063 | //use a local variable to cache mWindows |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1064 | ArrayList<WindowState> localmWindows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1065 | int jmax = localmWindows.size(); |
| 1066 | if(jmax == 0) { |
| 1067 | return -1; |
| 1068 | } |
| 1069 | for(int j = (jmax-1); j >= 0; j--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1070 | WindowState wentry = localmWindows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1071 | if(wentry.mAppToken == win.mAppToken) { |
| 1072 | return j; |
| 1073 | } |
| 1074 | } |
| 1075 | return -1; |
| 1076 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1077 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1078 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 1079 | final IWindow client = win.mClient; |
| 1080 | final WindowToken token = win.mToken; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1081 | final ArrayList<WindowState> localmWindows = mWindows; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1082 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1083 | final int N = localmWindows.size(); |
| 1084 | final WindowState attached = win.mAttachedWindow; |
| 1085 | int i; |
| 1086 | if (attached == null) { |
| 1087 | int tokenWindowsPos = token.windows.size(); |
| 1088 | if (token.appWindowToken != null) { |
| 1089 | int index = tokenWindowsPos-1; |
| 1090 | if (index >= 0) { |
| 1091 | // If this application has existing windows, we |
| 1092 | // simply place the new window on top of them... but |
| 1093 | // keep the starting window on top. |
| 1094 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 1095 | // Base windows go behind everything else. |
| 1096 | placeWindowBefore(token.windows.get(0), win); |
| 1097 | tokenWindowsPos = 0; |
| 1098 | } else { |
| 1099 | AppWindowToken atoken = win.mAppToken; |
| 1100 | if (atoken != null && |
| 1101 | token.windows.get(index) == atoken.startingWindow) { |
| 1102 | placeWindowBefore(token.windows.get(index), win); |
| 1103 | tokenWindowsPos--; |
| 1104 | } else { |
| 1105 | int newIdx = findIdxBasedOnAppTokens(win); |
| 1106 | if(newIdx != -1) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1107 | //there is a window above this one associated with the same |
| 1108 | //apptoken note that the window could be a floating window |
| 1109 | //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] | 1110 | //windows associated with this token. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1111 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1112 | TAG, "Adding window " + win + " at " |
| 1113 | + (newIdx+1) + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1114 | localmWindows.add(newIdx+1, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1115 | mWindowsChanged = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1116 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1117 | } |
| 1118 | } |
| 1119 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1120 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1121 | TAG, "Figuring out where to add app window " |
| 1122 | + client.asBinder() + " (token=" + token + ")"); |
| 1123 | // Figure out where the window should go, based on the |
| 1124 | // order of applications. |
| 1125 | final int NA = mAppTokens.size(); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1126 | WindowState pos = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1127 | for (i=NA-1; i>=0; i--) { |
| 1128 | AppWindowToken t = mAppTokens.get(i); |
| 1129 | if (t == token) { |
| 1130 | i--; |
| 1131 | break; |
| 1132 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1133 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1134 | // We haven't reached the token yet; if this token |
| 1135 | // is not going to the bottom and has windows, we can |
| 1136 | // use it as an anchor for when we do reach the token. |
| 1137 | if (!t.sendingToBottom && t.windows.size() > 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1138 | pos = t.windows.get(0); |
| 1139 | } |
| 1140 | } |
| 1141 | // We now know the index into the apps. If we found |
| 1142 | // an app window above, that gives us the position; else |
| 1143 | // we need to look some more. |
| 1144 | if (pos != null) { |
| 1145 | // Move behind any windows attached to this one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1146 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1147 | if (atoken != null) { |
| 1148 | final int NC = atoken.windows.size(); |
| 1149 | if (NC > 0) { |
| 1150 | WindowState bottom = atoken.windows.get(0); |
| 1151 | if (bottom.mSubLayer < 0) { |
| 1152 | pos = bottom; |
| 1153 | } |
| 1154 | } |
| 1155 | } |
| 1156 | placeWindowBefore(pos, win); |
| 1157 | } else { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1158 | // Continue looking down until we find the first |
| 1159 | // token that has windows. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1160 | while (i >= 0) { |
| 1161 | AppWindowToken t = mAppTokens.get(i); |
| 1162 | final int NW = t.windows.size(); |
| 1163 | if (NW > 0) { |
| 1164 | pos = t.windows.get(NW-1); |
| 1165 | break; |
| 1166 | } |
| 1167 | i--; |
| 1168 | } |
| 1169 | if (pos != null) { |
| 1170 | // Move in front of any windows attached to this |
| 1171 | // one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1172 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1173 | if (atoken != null) { |
| 1174 | final int NC = atoken.windows.size(); |
| 1175 | if (NC > 0) { |
| 1176 | WindowState top = atoken.windows.get(NC-1); |
| 1177 | if (top.mSubLayer >= 0) { |
| 1178 | pos = top; |
| 1179 | } |
| 1180 | } |
| 1181 | } |
| 1182 | placeWindowAfter(pos, win); |
| 1183 | } else { |
| 1184 | // Just search for the start of this layer. |
| 1185 | final int myLayer = win.mBaseLayer; |
| 1186 | for (i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1187 | WindowState w = localmWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1188 | if (w.mBaseLayer > myLayer) { |
| 1189 | break; |
| 1190 | } |
| 1191 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1192 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1193 | TAG, "Adding window " + win + " at " |
| 1194 | + i + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1195 | localmWindows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1196 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1197 | } |
| 1198 | } |
| 1199 | } |
| 1200 | } else { |
| 1201 | // Figure out where window should go, based on layer. |
| 1202 | final int myLayer = win.mBaseLayer; |
| 1203 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1204 | if (localmWindows.get(i).mBaseLayer <= myLayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1205 | i++; |
| 1206 | break; |
| 1207 | } |
| 1208 | } |
| 1209 | if (i < 0) i = 0; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1210 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1211 | TAG, "Adding window " + win + " at " |
| 1212 | + i + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1213 | localmWindows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1214 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1215 | } |
| 1216 | if (addToToken) { |
| 1217 | token.windows.add(tokenWindowsPos, win); |
| 1218 | } |
| 1219 | |
| 1220 | } else { |
| 1221 | // Figure out this window's ordering relative to the window |
| 1222 | // it is attached to. |
| 1223 | final int NA = token.windows.size(); |
| 1224 | final int sublayer = win.mSubLayer; |
| 1225 | int largestSublayer = Integer.MIN_VALUE; |
| 1226 | WindowState windowWithLargestSublayer = null; |
| 1227 | for (i=0; i<NA; i++) { |
| 1228 | WindowState w = token.windows.get(i); |
| 1229 | final int wSublayer = w.mSubLayer; |
| 1230 | if (wSublayer >= largestSublayer) { |
| 1231 | largestSublayer = wSublayer; |
| 1232 | windowWithLargestSublayer = w; |
| 1233 | } |
| 1234 | if (sublayer < 0) { |
| 1235 | // For negative sublayers, we go below all windows |
| 1236 | // in the same sublayer. |
| 1237 | if (wSublayer >= sublayer) { |
| 1238 | if (addToToken) { |
| 1239 | token.windows.add(i, win); |
| 1240 | } |
| 1241 | placeWindowBefore( |
| 1242 | wSublayer >= 0 ? attached : w, win); |
| 1243 | break; |
| 1244 | } |
| 1245 | } else { |
| 1246 | // For positive sublayers, we go above all windows |
| 1247 | // in the same sublayer. |
| 1248 | if (wSublayer > sublayer) { |
| 1249 | if (addToToken) { |
| 1250 | token.windows.add(i, win); |
| 1251 | } |
| 1252 | placeWindowBefore(w, win); |
| 1253 | break; |
| 1254 | } |
| 1255 | } |
| 1256 | } |
| 1257 | if (i >= NA) { |
| 1258 | if (addToToken) { |
| 1259 | token.windows.add(win); |
| 1260 | } |
| 1261 | if (sublayer < 0) { |
| 1262 | placeWindowBefore(attached, win); |
| 1263 | } else { |
| 1264 | placeWindowAfter(largestSublayer >= 0 |
| 1265 | ? windowWithLargestSublayer |
| 1266 | : attached, |
| 1267 | win); |
| 1268 | } |
| 1269 | } |
| 1270 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1271 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1272 | if (win.mAppToken != null && addToToken) { |
| 1273 | win.mAppToken.allAppWindows.add(win); |
| 1274 | } |
| 1275 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1276 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1277 | static boolean canBeImeTarget(WindowState w) { |
| 1278 | final int fl = w.mAttrs.flags |
| 1279 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 1280 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 1281 | return w.isVisibleOrAdding(); |
| 1282 | } |
| 1283 | return false; |
| 1284 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1285 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1286 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1287 | final ArrayList<WindowState> localmWindows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1288 | final int N = localmWindows.size(); |
| 1289 | WindowState w = null; |
| 1290 | int i = N; |
| 1291 | while (i > 0) { |
| 1292 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1293 | w = localmWindows.get(i); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1294 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1295 | //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1296 | // + Integer.toHexString(w.mAttrs.flags)); |
| 1297 | if (canBeImeTarget(w)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1298 | //Slog.i(TAG, "Putting input method here!"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1299 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1300 | // Yet more tricksyness! If this window is a "starting" |
| 1301 | // window, we do actually want to be on top of it, but |
| 1302 | // it is not -really- where input will go. So if the caller |
| 1303 | // is not actually looking to move the IME, look down below |
| 1304 | // for a real window to target... |
| 1305 | if (!willMove |
| 1306 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 1307 | && i > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1308 | WindowState wb = localmWindows.get(i-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1309 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 1310 | i--; |
| 1311 | w = wb; |
| 1312 | } |
| 1313 | } |
| 1314 | break; |
| 1315 | } |
| 1316 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1317 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1318 | mUpcomingInputMethodTarget = w; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1319 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1320 | 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] | 1321 | + w + " willMove=" + willMove); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1322 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1323 | if (willMove && w != null) { |
| 1324 | final WindowState curTarget = mInputMethodTarget; |
| 1325 | if (curTarget != null && curTarget.mAppToken != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1326 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1327 | // Now some fun for dealing with window animations that |
| 1328 | // modify the Z order. We need to look at all windows below |
| 1329 | // the current target that are in this app, finding the highest |
| 1330 | // visible one in layering. |
| 1331 | AppWindowToken token = curTarget.mAppToken; |
| 1332 | WindowState highestTarget = null; |
| 1333 | int highestPos = 0; |
| 1334 | if (token.animating || token.animation != null) { |
| 1335 | int pos = 0; |
| 1336 | pos = localmWindows.indexOf(curTarget); |
| 1337 | while (pos >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1338 | WindowState win = localmWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1339 | if (win.mAppToken != token) { |
| 1340 | break; |
| 1341 | } |
| 1342 | if (!win.mRemoved) { |
| 1343 | if (highestTarget == null || win.mAnimLayer > |
| 1344 | highestTarget.mAnimLayer) { |
| 1345 | highestTarget = win; |
| 1346 | highestPos = pos; |
| 1347 | } |
| 1348 | } |
| 1349 | pos--; |
| 1350 | } |
| 1351 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1352 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1353 | if (highestTarget != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1354 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1355 | + mNextAppTransition + " " + highestTarget |
| 1356 | + " animating=" + highestTarget.isAnimating() |
| 1357 | + " layer=" + highestTarget.mAnimLayer |
| 1358 | + " new layer=" + w.mAnimLayer); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1359 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1360 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1361 | // If we are currently setting up for an animation, |
| 1362 | // hold everything until we can find out what will happen. |
| 1363 | mInputMethodTargetWaitingAnim = true; |
| 1364 | mInputMethodTarget = highestTarget; |
| 1365 | return highestPos + 1; |
| 1366 | } else if (highestTarget.isAnimating() && |
| 1367 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 1368 | // If the window we are currently targeting is involved |
| 1369 | // with an animation, and it is on top of the next target |
| 1370 | // we will be over, then hold off on moving until |
| 1371 | // that is done. |
| 1372 | mInputMethodTarget = highestTarget; |
| 1373 | return highestPos + 1; |
| 1374 | } |
| 1375 | } |
| 1376 | } |
| 1377 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1378 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1379 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1380 | if (w != null) { |
| 1381 | if (willMove) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1382 | if (DEBUG_INPUT_METHOD) { |
| 1383 | RuntimeException e = null; |
| 1384 | if (!HIDE_STACK_CRAWLS) { |
| 1385 | e = new RuntimeException(); |
| 1386 | e.fillInStackTrace(); |
| 1387 | } |
| 1388 | Slog.w(TAG, "Moving IM target from " |
| 1389 | + mInputMethodTarget + " to " + w, e); |
| 1390 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1391 | mInputMethodTarget = w; |
| 1392 | if (w.mAppToken != null) { |
| 1393 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 1394 | } else { |
| 1395 | setInputMethodAnimLayerAdjustment(0); |
| 1396 | } |
| 1397 | } |
| 1398 | return i+1; |
| 1399 | } |
| 1400 | if (willMove) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1401 | if (DEBUG_INPUT_METHOD) { |
| 1402 | RuntimeException e = null; |
| 1403 | if (!HIDE_STACK_CRAWLS) { |
| 1404 | e = new RuntimeException(); |
| 1405 | e.fillInStackTrace(); |
| 1406 | } |
| 1407 | Slog.w(TAG, "Moving IM target from " |
| 1408 | + mInputMethodTarget + " to null", e); |
| 1409 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1410 | mInputMethodTarget = null; |
| 1411 | setInputMethodAnimLayerAdjustment(0); |
| 1412 | } |
| 1413 | return -1; |
| 1414 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1415 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1416 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1417 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1418 | if (pos >= 0) { |
| 1419 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1420 | if (DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1421 | TAG, "Adding input method window " + win + " at " + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1422 | mWindows.add(pos, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1423 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1424 | moveInputMethodDialogsLocked(pos+1); |
| 1425 | return; |
| 1426 | } |
| 1427 | win.mTargetAppToken = null; |
| 1428 | addWindowToListInOrderLocked(win, true); |
| 1429 | moveInputMethodDialogsLocked(pos); |
| 1430 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1431 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1432 | void setInputMethodAnimLayerAdjustment(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1433 | 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] | 1434 | mInputMethodAnimLayerAdjustment = adj; |
| 1435 | WindowState imw = mInputMethodWindow; |
| 1436 | if (imw != null) { |
| 1437 | imw.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1438 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1439 | + " anim layer: " + imw.mAnimLayer); |
| 1440 | int wi = imw.mChildWindows.size(); |
| 1441 | while (wi > 0) { |
| 1442 | wi--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1443 | WindowState cw = imw.mChildWindows.get(wi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1444 | cw.mAnimLayer = cw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1445 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1446 | + " anim layer: " + cw.mAnimLayer); |
| 1447 | } |
| 1448 | } |
| 1449 | int di = mInputMethodDialogs.size(); |
| 1450 | while (di > 0) { |
| 1451 | di --; |
| 1452 | imw = mInputMethodDialogs.get(di); |
| 1453 | imw.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1454 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1455 | + " anim layer: " + imw.mAnimLayer); |
| 1456 | } |
| 1457 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1458 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1459 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1460 | int wpos = mWindows.indexOf(win); |
| 1461 | if (wpos >= 0) { |
| 1462 | if (wpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1463 | 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] | 1464 | mWindows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1465 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1466 | int NC = win.mChildWindows.size(); |
| 1467 | while (NC > 0) { |
| 1468 | NC--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1469 | WindowState cw = win.mChildWindows.get(NC); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1470 | int cpos = mWindows.indexOf(cw); |
| 1471 | if (cpos >= 0) { |
| 1472 | if (cpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1473 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1474 | + cpos + ": " + cw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1475 | mWindows.remove(cpos); |
| 1476 | } |
| 1477 | } |
| 1478 | } |
| 1479 | return interestingPos; |
| 1480 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1481 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1482 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1483 | addWindowToListInOrderLocked(win, false); |
| 1484 | // This is a hack to get all of the child windows added as well |
| 1485 | // at the right position. Child windows should be rare and |
| 1486 | // this case should be rare, so it shouldn't be that big a deal. |
| 1487 | int wpos = mWindows.indexOf(win); |
| 1488 | if (wpos >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1489 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1490 | + ": " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1491 | mWindows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1492 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1493 | reAddWindowLocked(wpos, win); |
| 1494 | } |
| 1495 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1496 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1497 | void logWindowList(String prefix) { |
| 1498 | int N = mWindows.size(); |
| 1499 | while (N > 0) { |
| 1500 | N--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1501 | Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1502 | } |
| 1503 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1504 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1505 | void moveInputMethodDialogsLocked(int pos) { |
| 1506 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1507 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1508 | final int N = dialogs.size(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1509 | 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] | 1510 | for (int i=0; i<N; i++) { |
| 1511 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1512 | } |
| 1513 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1514 | Slog.v(TAG, "Window list w/pos=" + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1515 | logWindowList(" "); |
| 1516 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1517 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1518 | if (pos >= 0) { |
| 1519 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1520 | if (pos < mWindows.size()) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1521 | WindowState wp = mWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1522 | if (wp == mInputMethodWindow) { |
| 1523 | pos++; |
| 1524 | } |
| 1525 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1526 | 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] | 1527 | for (int i=0; i<N; i++) { |
| 1528 | WindowState win = dialogs.get(i); |
| 1529 | win.mTargetAppToken = targetAppToken; |
| 1530 | pos = reAddWindowLocked(pos, win); |
| 1531 | } |
| 1532 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1533 | Slog.v(TAG, "Final window list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1534 | logWindowList(" "); |
| 1535 | } |
| 1536 | return; |
| 1537 | } |
| 1538 | for (int i=0; i<N; i++) { |
| 1539 | WindowState win = dialogs.get(i); |
| 1540 | win.mTargetAppToken = null; |
| 1541 | reAddWindowToListInOrderLocked(win); |
| 1542 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1543 | Slog.v(TAG, "No IM target, final list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1544 | logWindowList(" "); |
| 1545 | } |
| 1546 | } |
| 1547 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1548 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1549 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1550 | final WindowState imWin = mInputMethodWindow; |
| 1551 | final int DN = mInputMethodDialogs.size(); |
| 1552 | if (imWin == null && DN == 0) { |
| 1553 | return false; |
| 1554 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1555 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1556 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1557 | if (imPos >= 0) { |
| 1558 | // In this case, the input method windows are to be placed |
| 1559 | // immediately above the window they are targeting. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1560 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1561 | // First check to see if the input method windows are already |
| 1562 | // located here, and contiguous. |
| 1563 | final int N = mWindows.size(); |
| 1564 | WindowState firstImWin = imPos < N |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1565 | ? mWindows.get(imPos) : null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1566 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1567 | // Figure out the actual input method window that should be |
| 1568 | // at the bottom of their stack. |
| 1569 | WindowState baseImWin = imWin != null |
| 1570 | ? imWin : mInputMethodDialogs.get(0); |
| 1571 | if (baseImWin.mChildWindows.size() > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1572 | WindowState cw = baseImWin.mChildWindows.get(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1573 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 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 | if (firstImWin == baseImWin) { |
| 1577 | // The windows haven't moved... but are they still contiguous? |
| 1578 | // First find the top IM window. |
| 1579 | int pos = imPos+1; |
| 1580 | while (pos < N) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1581 | if (!(mWindows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1582 | break; |
| 1583 | } |
| 1584 | pos++; |
| 1585 | } |
| 1586 | pos++; |
| 1587 | // Now there should be no more input method windows above. |
| 1588 | while (pos < N) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1589 | if ((mWindows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1590 | break; |
| 1591 | } |
| 1592 | pos++; |
| 1593 | } |
| 1594 | if (pos >= N) { |
| 1595 | // All is good! |
| 1596 | return false; |
| 1597 | } |
| 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 | if (imWin != null) { |
| 1601 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1602 | Slog.v(TAG, "Moving IM from " + imPos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1603 | logWindowList(" "); |
| 1604 | } |
| 1605 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1606 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1607 | 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] | 1608 | logWindowList(" "); |
| 1609 | } |
| 1610 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1611 | reAddWindowLocked(imPos, imWin); |
| 1612 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1613 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1614 | logWindowList(" "); |
| 1615 | } |
| 1616 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1617 | } else { |
| 1618 | moveInputMethodDialogsLocked(imPos); |
| 1619 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1620 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1621 | } else { |
| 1622 | // In this case, the input method windows go in a fixed layer, |
| 1623 | // because they aren't currently associated with a focus window. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1624 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1625 | if (imWin != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1626 | 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] | 1627 | tmpRemoveWindowLocked(0, imWin); |
| 1628 | imWin.mTargetAppToken = null; |
| 1629 | reAddWindowToListInOrderLocked(imWin); |
| 1630 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1631 | Slog.v(TAG, "List with no IM target:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1632 | logWindowList(" "); |
| 1633 | } |
| 1634 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1635 | } else { |
| 1636 | moveInputMethodDialogsLocked(-1);; |
| 1637 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1638 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1639 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1640 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1641 | if (needAssignLayers) { |
| 1642 | assignLayersLocked(); |
| 1643 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1644 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1645 | return true; |
| 1646 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1647 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1648 | void adjustInputMethodDialogsLocked() { |
| 1649 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1650 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1651 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1652 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1653 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured=" |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1654 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1655 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1656 | ? wallpaperTarget.mAppToken.animation : null) |
| 1657 | + " upper=" + mUpperWallpaperTarget |
| 1658 | + " lower=" + mLowerWallpaperTarget); |
| 1659 | return (wallpaperTarget != null |
| 1660 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1661 | && wallpaperTarget.mAppToken.animation != null))) |
| 1662 | || mUpperWallpaperTarget != null |
| 1663 | || mLowerWallpaperTarget != null; |
| 1664 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1665 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1666 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1667 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1668 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1669 | int adjustWallpaperWindowsLocked() { |
| 1670 | int changed = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1671 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1672 | final int dw = mDisplay.getWidth(); |
| 1673 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1674 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1675 | // First find top-most window that has asked to be on top of the |
| 1676 | // wallpaper; all wallpapers go behind it. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1677 | final ArrayList<WindowState> localmWindows = mWindows; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1678 | int N = localmWindows.size(); |
| 1679 | WindowState w = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1680 | WindowState foundW = null; |
| 1681 | int foundI = 0; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1682 | WindowState topCurW = null; |
| 1683 | int topCurI = 0; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1684 | int i = N; |
| 1685 | while (i > 0) { |
| 1686 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1687 | w = localmWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1688 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1689 | if (topCurW == null) { |
| 1690 | topCurW = w; |
| 1691 | topCurI = i; |
| 1692 | } |
| 1693 | continue; |
| 1694 | } |
| 1695 | topCurW = null; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1696 | if (w.mAppToken != null) { |
| 1697 | // If this window's app token is hidden and not animating, |
| 1698 | // it is of no interest to us. |
| 1699 | if (w.mAppToken.hidden && w.mAppToken.animation == 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 | "Skipping hidden or animating token: " + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1702 | topCurW = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1703 | continue; |
| 1704 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1705 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1706 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay=" |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1707 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1708 | + " commitdrawpending=" + w.mCommitDrawPending); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1709 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1710 | && (mWallpaperTarget == w |
| 1711 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1712 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1713 | "Found wallpaper activity: #" + i + "=" + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1714 | foundW = w; |
| 1715 | foundI = i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1716 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1717 | && w.mAppToken.animation != null) |
| 1718 | || w.mAnimation != null)) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1719 | // The current wallpaper target is animating, so we'll |
| 1720 | // look behind it for another possible target and figure |
| 1721 | // out what is going on below. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1722 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1723 | + ": token animating, looking behind."); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1724 | continue; |
| 1725 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1726 | break; |
| 1727 | } |
| 1728 | } |
| 1729 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1730 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1731 | // If we are currently waiting for an app transition, and either |
| 1732 | // the current target or the next target are involved with it, |
| 1733 | // then hold off on doing anything with the wallpaper. |
| 1734 | // Note that we are checking here for just whether the target |
| 1735 | // is part of an app token... which is potentially overly aggressive |
| 1736 | // (the app token may not be involved in the transition), but good |
| 1737 | // enough (we'll just wait until whatever transition is pending |
| 1738 | // executes). |
| 1739 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1740 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1741 | "Wallpaper not changing: waiting for app anim in current target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1742 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1743 | } |
| 1744 | if (foundW != null && foundW.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1745 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1746 | "Wallpaper not changing: waiting for app anim in found target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1747 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1748 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1749 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1750 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1751 | if (mWallpaperTarget != foundW) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1752 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1753 | Slog.v(TAG, "New wallpaper target: " + foundW |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1754 | + " oldTarget: " + mWallpaperTarget); |
| 1755 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1756 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1757 | mLowerWallpaperTarget = null; |
| 1758 | mUpperWallpaperTarget = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1759 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1760 | WindowState oldW = mWallpaperTarget; |
| 1761 | mWallpaperTarget = foundW; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1762 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1763 | // Now what is happening... if the current and new targets are |
| 1764 | // animating, then we are in our super special mode! |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1765 | if (foundW != null && oldW != null) { |
| 1766 | boolean oldAnim = oldW.mAnimation != null |
| 1767 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1768 | boolean foundAnim = foundW.mAnimation != null |
| 1769 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1770 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1771 | Slog.v(TAG, "New animation: " + foundAnim |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1772 | + " old animation: " + oldAnim); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1773 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1774 | if (foundAnim && oldAnim) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1775 | int oldI = localmWindows.indexOf(oldW); |
| 1776 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1777 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1778 | } |
| 1779 | if (oldI >= 0) { |
| 1780 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1781 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1782 | + "=" + oldW + "; new#" + foundI |
| 1783 | + "=" + foundW); |
| 1784 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1785 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1786 | // Set the new target correctly. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1787 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1788 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1789 | Slog.v(TAG, "Old wallpaper still the target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1790 | } |
| 1791 | mWallpaperTarget = oldW; |
| 1792 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1793 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1794 | // Now set the upper and lower wallpaper targets |
| 1795 | // correctly, and make sure that we are positioning |
| 1796 | // the wallpaper below the lower. |
| 1797 | if (foundI > oldI) { |
| 1798 | // The new target is on top of the old one. |
| 1799 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1800 | Slog.v(TAG, "Found target above old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1801 | } |
| 1802 | mUpperWallpaperTarget = foundW; |
| 1803 | mLowerWallpaperTarget = oldW; |
| 1804 | foundW = oldW; |
| 1805 | foundI = oldI; |
| 1806 | } else { |
| 1807 | // The new target is below the old one. |
| 1808 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1809 | Slog.v(TAG, "Found target below old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1810 | } |
| 1811 | mUpperWallpaperTarget = oldW; |
| 1812 | mLowerWallpaperTarget = foundW; |
| 1813 | } |
| 1814 | } |
| 1815 | } |
| 1816 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1817 | |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1818 | } else if (mLowerWallpaperTarget != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1819 | // Is it time to stop animating? |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1820 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1821 | || (mLowerWallpaperTarget.mAppToken != null |
| 1822 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1823 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1824 | || (mUpperWallpaperTarget.mAppToken != null |
| 1825 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1826 | if (!lowerAnimating || !upperAnimating) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1827 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1828 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1829 | } |
| 1830 | mLowerWallpaperTarget = null; |
| 1831 | mUpperWallpaperTarget = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1832 | } |
| 1833 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1834 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1835 | boolean visible = foundW != null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1836 | if (visible) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1837 | // The window is visible to the compositor... but is it visible |
| 1838 | // to the user? That is what the wallpaper cares about. |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1839 | visible = isWallpaperVisible(foundW); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1840 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1841 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1842 | // If the wallpaper target is animating, we may need to copy |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1843 | // its layer adjustment. Only do this if we are not transfering |
| 1844 | // between two wallpaper targets. |
| 1845 | mWallpaperAnimLayerAdjustment = |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1846 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1847 | ? foundW.mAppToken.animLayerAdjustment : 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1848 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1849 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1850 | * TYPE_LAYER_MULTIPLIER |
| 1851 | + TYPE_LAYER_OFFSET; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1852 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1853 | // Now w is the window we are supposed to be behind... but we |
| 1854 | // 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] | 1855 | // AND any starting window associated with it, AND below the |
| 1856 | // maximum layer the policy allows for wallpapers. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1857 | while (foundI > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1858 | WindowState wb = localmWindows.get(foundI-1); |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1859 | if (wb.mBaseLayer < maxLayer && |
| 1860 | wb.mAttachedWindow != foundW && |
Pal Szasz | 73dc259 | 2010-09-03 11:46:26 +0200 | [diff] [blame] | 1861 | wb.mAttachedWindow != foundW.mAttachedWindow && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1862 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1863 | wb.mToken != foundW.mToken)) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1864 | // This window is not related to the previous one in any |
| 1865 | // interesting way, so stop here. |
| 1866 | break; |
| 1867 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1868 | foundW = wb; |
| 1869 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1870 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1871 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1872 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1873 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1874 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1875 | if (foundW == null && topCurW != null) { |
| 1876 | // There is no wallpaper target, so it goes at the bottom. |
| 1877 | // We will assume it is the same place as last time, if known. |
| 1878 | foundW = topCurW; |
| 1879 | foundI = topCurI+1; |
| 1880 | } else { |
| 1881 | // Okay i is the position immediately above the wallpaper. Look at |
| 1882 | // what is below it for later. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1883 | foundW = foundI > 0 ? localmWindows.get(foundI-1) : null; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1884 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1885 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1886 | if (visible) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1887 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1888 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1889 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1890 | } |
| 1891 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1892 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1893 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1894 | } |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1895 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1896 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1897 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1898 | // are correctly placed. |
| 1899 | int curTokenIndex = mWallpaperTokens.size(); |
| 1900 | while (curTokenIndex > 0) { |
| 1901 | curTokenIndex--; |
| 1902 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1903 | if (token.hidden == visible) { |
| 1904 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1905 | token.hidden = !visible; |
| 1906 | // Need to do a layout to ensure the wallpaper now has the |
| 1907 | // correct size. |
| 1908 | mLayoutNeeded = true; |
| 1909 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1910 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1911 | int curWallpaperIndex = token.windows.size(); |
| 1912 | while (curWallpaperIndex > 0) { |
| 1913 | curWallpaperIndex--; |
| 1914 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1915 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1916 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1917 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1918 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1919 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1920 | // First, make sure the client has the current visibility |
| 1921 | // state. |
| 1922 | if (wallpaper.mWallpaperVisible != visible) { |
| 1923 | wallpaper.mWallpaperVisible = visible; |
| 1924 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1925 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1926 | "Setting visibility of wallpaper " + wallpaper |
| 1927 | + ": " + visible); |
| 1928 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1929 | } catch (RemoteException e) { |
| 1930 | } |
| 1931 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1932 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1933 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1934 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1935 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1936 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1937 | // First, if this window is at the current index, then all |
| 1938 | // is well. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1939 | if (wallpaper == foundW) { |
| 1940 | foundI--; |
| 1941 | foundW = foundI > 0 |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1942 | ? localmWindows.get(foundI-1) : null; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1943 | continue; |
| 1944 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1945 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1946 | // The window didn't match... the current wallpaper window, |
| 1947 | // wherever it is, is in the wrong place, so make sure it is |
| 1948 | // not in the list. |
| 1949 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 1950 | if (oldIndex >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1951 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1952 | + oldIndex + ": " + wallpaper); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1953 | localmWindows.remove(oldIndex); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1954 | mWindowsChanged = true; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1955 | if (oldIndex < foundI) { |
| 1956 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1957 | } |
| 1958 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1959 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1960 | // Now stick it in. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1961 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1962 | "Moving wallpaper " + wallpaper |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1963 | + " from " + oldIndex + " to " + foundI); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1964 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1965 | localmWindows.add(foundI, wallpaper); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1966 | mWindowsChanged = true; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1967 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1968 | } |
| 1969 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1970 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1971 | return changed; |
| 1972 | } |
| 1973 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1974 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1975 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1976 | "Setting wallpaper layer adj to " + adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1977 | mWallpaperAnimLayerAdjustment = adj; |
| 1978 | int curTokenIndex = mWallpaperTokens.size(); |
| 1979 | while (curTokenIndex > 0) { |
| 1980 | curTokenIndex--; |
| 1981 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1982 | int curWallpaperIndex = token.windows.size(); |
| 1983 | while (curWallpaperIndex > 0) { |
| 1984 | curWallpaperIndex--; |
| 1985 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1986 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1987 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1988 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1989 | } |
| 1990 | } |
| 1991 | } |
| 1992 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1993 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 1994 | boolean sync) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1995 | boolean changed = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1996 | boolean rawChanged = false; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1997 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1998 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1999 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 2000 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 2001 | changed = wallpaperWin.mXOffset != offset; |
| 2002 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2003 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2004 | + wallpaperWin + " x: " + offset); |
| 2005 | wallpaperWin.mXOffset = offset; |
| 2006 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2007 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2008 | wallpaperWin.mWallpaperX = wpx; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2009 | wallpaperWin.mWallpaperXStep = wpxs; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2010 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2011 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2012 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2013 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2014 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2015 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 2016 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 2017 | if (wallpaperWin.mYOffset != offset) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2018 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2019 | + wallpaperWin + " y: " + offset); |
| 2020 | changed = true; |
| 2021 | wallpaperWin.mYOffset = offset; |
| 2022 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2023 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2024 | wallpaperWin.mWallpaperY = wpy; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2025 | wallpaperWin.mWallpaperYStep = wpys; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2026 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2027 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2028 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2029 | if (rawChanged) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2030 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2031 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2032 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 2033 | + " y=" + wallpaperWin.mWallpaperY); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2034 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2035 | mWaitingOnWallpaper = wallpaperWin; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2036 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2037 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2038 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 2039 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2040 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2041 | if (mWaitingOnWallpaper != null) { |
| 2042 | long start = SystemClock.uptimeMillis(); |
| 2043 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 2044 | < start) { |
| 2045 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2046 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2047 | "Waiting for offset complete..."); |
| 2048 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 2049 | } catch (InterruptedException e) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2050 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2051 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2052 | if ((start+WALLPAPER_TIMEOUT) |
| 2053 | < SystemClock.uptimeMillis()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2054 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2055 | + wallpaperWin); |
| 2056 | mLastWallpaperTimeoutTime = start; |
| 2057 | } |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2058 | } |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2059 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2060 | } |
| 2061 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2062 | } catch (RemoteException e) { |
| 2063 | } |
| 2064 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2065 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2066 | return changed; |
| 2067 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2068 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2069 | void wallpaperOffsetsComplete(IBinder window) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2070 | synchronized (mWindowMap) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2071 | if (mWaitingOnWallpaper != null && |
| 2072 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2073 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2074 | mWindowMap.notifyAll(); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2075 | } |
| 2076 | } |
| 2077 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2078 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2079 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2080 | final int dw = mDisplay.getWidth(); |
| 2081 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2082 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2083 | boolean changed = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2084 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2085 | WindowState target = mWallpaperTarget; |
| 2086 | if (target != null) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2087 | if (target.mWallpaperX >= 0) { |
| 2088 | mLastWallpaperX = target.mWallpaperX; |
| 2089 | } else if (changingTarget.mWallpaperX >= 0) { |
| 2090 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 2091 | } |
| 2092 | if (target.mWallpaperY >= 0) { |
| 2093 | mLastWallpaperY = target.mWallpaperY; |
| 2094 | } else if (changingTarget.mWallpaperY >= 0) { |
| 2095 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 2096 | } |
| 2097 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2098 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2099 | int curTokenIndex = mWallpaperTokens.size(); |
| 2100 | while (curTokenIndex > 0) { |
| 2101 | curTokenIndex--; |
| 2102 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2103 | int curWallpaperIndex = token.windows.size(); |
| 2104 | while (curWallpaperIndex > 0) { |
| 2105 | curWallpaperIndex--; |
| 2106 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2107 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 2108 | wallpaper.computeShownFrameLocked(); |
| 2109 | changed = true; |
| 2110 | // We only want to be synchronous with one wallpaper. |
| 2111 | sync = false; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2112 | } |
| 2113 | } |
| 2114 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2115 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2116 | return changed; |
| 2117 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2118 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2119 | void updateWallpaperVisibilityLocked() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2120 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2121 | final int dw = mDisplay.getWidth(); |
| 2122 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2123 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2124 | int curTokenIndex = mWallpaperTokens.size(); |
| 2125 | while (curTokenIndex > 0) { |
| 2126 | curTokenIndex--; |
| 2127 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2128 | if (token.hidden == visible) { |
| 2129 | token.hidden = !visible; |
| 2130 | // Need to do a layout to ensure the wallpaper now has the |
| 2131 | // correct size. |
| 2132 | mLayoutNeeded = true; |
| 2133 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2134 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2135 | int curWallpaperIndex = token.windows.size(); |
| 2136 | while (curWallpaperIndex > 0) { |
| 2137 | curWallpaperIndex--; |
| 2138 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2139 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2140 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2141 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2142 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2143 | if (wallpaper.mWallpaperVisible != visible) { |
| 2144 | wallpaper.mWallpaperVisible = visible; |
| 2145 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2146 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2147 | "Updating visibility of wallpaper " + wallpaper |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2148 | + ": " + visible); |
| 2149 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 2150 | } catch (RemoteException e) { |
| 2151 | } |
| 2152 | } |
| 2153 | } |
| 2154 | } |
| 2155 | } |
Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 2156 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2157 | public int addWindow(Session session, IWindow client, |
| 2158 | WindowManager.LayoutParams attrs, int viewVisibility, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2159 | Rect outContentInsets, InputChannel outInputChannel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2160 | int res = mPolicy.checkAddPermission(attrs); |
| 2161 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2162 | return res; |
| 2163 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2164 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2165 | boolean reportNewConfig = false; |
| 2166 | WindowState attachedWindow = null; |
| 2167 | WindowState win = null; |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2168 | long origId; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2169 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2170 | synchronized(mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2171 | if (mDisplay == null) { |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2172 | throw new IllegalStateException("Display has not been initialialized"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2173 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2174 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2175 | if (mWindowMap.containsKey(client.asBinder())) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2176 | Slog.w(TAG, "Window " + client + " is already added"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2177 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 2178 | } |
| 2179 | |
| 2180 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2181 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2182 | if (attachedWindow == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2183 | 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] | 2184 | + attrs.token + ". Aborting."); |
| 2185 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2186 | } |
| 2187 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 2188 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2189 | 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] | 2190 | + attrs.token + ". Aborting."); |
| 2191 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2192 | } |
| 2193 | } |
| 2194 | |
| 2195 | boolean addToken = false; |
| 2196 | WindowToken token = mTokenMap.get(attrs.token); |
| 2197 | if (token == null) { |
| 2198 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2199 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2200 | 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] | 2201 | + attrs.token + ". Aborting."); |
| 2202 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2203 | } |
| 2204 | if (attrs.type == TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2205 | 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] | 2206 | + attrs.token + ". Aborting."); |
| 2207 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2208 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2209 | if (attrs.type == TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2210 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2211 | + attrs.token + ". Aborting."); |
| 2212 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2213 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2214 | token = new WindowToken(attrs.token, -1, false); |
| 2215 | addToken = true; |
| 2216 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2217 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 2218 | AppWindowToken atoken = token.appWindowToken; |
| 2219 | if (atoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2220 | 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] | 2221 | + token + ". Aborting."); |
| 2222 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 2223 | } else if (atoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2224 | 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] | 2225 | + token + ". Aborting."); |
| 2226 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2227 | } |
| 2228 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 2229 | // No need for this guy! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2230 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2231 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 2232 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 2233 | } |
| 2234 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 2235 | if (token.windowType != TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2236 | Slog.w(TAG, "Attempted to add input method window with bad token " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2237 | + attrs.token + ". Aborting."); |
| 2238 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2239 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2240 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 2241 | if (token.windowType != TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2242 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2243 | + attrs.token + ". Aborting."); |
| 2244 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2245 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2246 | } |
| 2247 | |
| 2248 | win = new WindowState(session, client, token, |
| 2249 | attachedWindow, attrs, viewVisibility); |
| 2250 | if (win.mDeathRecipient == null) { |
| 2251 | // Client has apparently died, so there is no reason to |
| 2252 | // continue. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2253 | Slog.w(TAG, "Adding window client " + client.asBinder() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2254 | + " that is dead, aborting."); |
| 2255 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2256 | } |
| 2257 | |
| 2258 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2259 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2260 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 2261 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2262 | return res; |
| 2263 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2264 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2265 | if (outInputChannel != null) { |
| 2266 | String name = win.makeInputChannelName(); |
| 2267 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 2268 | win.mInputChannel = inputChannels[0]; |
| 2269 | inputChannels[1].transferToBinderOutParameter(outInputChannel); |
| 2270 | |
| 2271 | mInputManager.registerInputChannel(win.mInputChannel); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2272 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2273 | |
| 2274 | // From now on, no exceptions or errors allowed! |
| 2275 | |
| 2276 | res = WindowManagerImpl.ADD_OKAY; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2277 | |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2278 | origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2279 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2280 | if (addToken) { |
| 2281 | mTokenMap.put(attrs.token, token); |
| 2282 | mTokenList.add(token); |
| 2283 | } |
| 2284 | win.attach(); |
| 2285 | mWindowMap.put(client.asBinder(), win); |
| 2286 | |
| 2287 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 2288 | token.appWindowToken != null) { |
| 2289 | token.appWindowToken.startingWindow = win; |
| 2290 | } |
| 2291 | |
| 2292 | boolean imMayMove = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2293 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2294 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 2295 | mInputMethodWindow = win; |
| 2296 | addInputMethodWindowToListLocked(win); |
| 2297 | imMayMove = false; |
| 2298 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2299 | mInputMethodDialogs.add(win); |
| 2300 | addWindowToListInOrderLocked(win, true); |
| 2301 | adjustInputMethodDialogsLocked(); |
| 2302 | imMayMove = false; |
| 2303 | } else { |
| 2304 | addWindowToListInOrderLocked(win, true); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2305 | if (attrs.type == TYPE_WALLPAPER) { |
| 2306 | mLastWallpaperTimeoutTime = 0; |
| 2307 | adjustWallpaperWindowsLocked(); |
| 2308 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2309 | adjustWallpaperWindowsLocked(); |
| 2310 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2311 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2312 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2313 | win.mEnterAnimationPending = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2314 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2315 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2316 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2317 | if (mInTouchMode) { |
| 2318 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 2319 | } |
| 2320 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 2321 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 2322 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2323 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2324 | boolean focusChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2325 | if (win.canReceiveKeys()) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2326 | focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS); |
| 2327 | if (focusChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2328 | imMayMove = false; |
| 2329 | } |
| 2330 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2331 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2332 | if (imMayMove) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2333 | moveInputMethodWindowsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2334 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2335 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2336 | assignLayersLocked(); |
| 2337 | // Don't do layout here, the window must call |
| 2338 | // relayout to be displayed, so we'll do it there. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2339 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2340 | //dump(); |
| 2341 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2342 | if (focusChanged) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2343 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2344 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2345 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2346 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2347 | TAG, "New client " + client.asBinder() |
| 2348 | + ": window=" + win); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2349 | |
| 2350 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) { |
| 2351 | reportNewConfig = true; |
| 2352 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2353 | } |
| 2354 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2355 | if (reportNewConfig) { |
| 2356 | sendNewConfiguration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2357 | } |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2358 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2359 | Binder.restoreCallingIdentity(origId); |
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 | return res; |
| 2362 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2363 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2364 | public void removeWindow(Session session, IWindow client) { |
| 2365 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2366 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2367 | if (win == null) { |
| 2368 | return; |
| 2369 | } |
| 2370 | removeWindowLocked(session, win); |
| 2371 | } |
| 2372 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2373 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2374 | public void removeWindowLocked(Session session, WindowState win) { |
| 2375 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2376 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2377 | TAG, "Remove " + win + " client=" |
| 2378 | + Integer.toHexString(System.identityHashCode( |
| 2379 | win.mClient.asBinder())) |
| 2380 | + ", surface=" + win.mSurface); |
| 2381 | |
| 2382 | final long origId = Binder.clearCallingIdentity(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2383 | |
| 2384 | win.disposeInputChannel(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2385 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2386 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2387 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2388 | + " mExiting=" + win.mExiting |
| 2389 | + " isAnimating=" + win.isAnimating() |
| 2390 | + " app-animation=" |
| 2391 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2392 | + " inPendingTransaction=" |
| 2393 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2394 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2395 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2396 | boolean wasVisible = false; |
| 2397 | // First, see if we need to run an animation. If we do, we have |
| 2398 | // to hold off on removing the window until the animation is done. |
| 2399 | // If the display is frozen, just remove immediately, since the |
| 2400 | // animation wouldn't be seen. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2401 | if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2402 | // If we are not currently running the exit animation, we |
| 2403 | // need to see about starting one. |
| 2404 | if (wasVisible=win.isWinVisibleLw()) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2405 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2406 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2407 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2408 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2409 | } |
| 2410 | // Try starting an animation. |
| 2411 | if (applyAnimationLocked(win, transit, false)) { |
| 2412 | win.mExiting = true; |
| 2413 | } |
| 2414 | } |
| 2415 | if (win.mExiting || win.isAnimating()) { |
| 2416 | // The exit animation is running... wait for it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2417 | //Slog.i(TAG, "*** Running exit animation..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2418 | win.mExiting = true; |
| 2419 | win.mRemoveOnExit = true; |
| 2420 | mLayoutNeeded = true; |
| 2421 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 2422 | performLayoutAndPlaceSurfacesLocked(); |
| 2423 | if (win.mAppToken != null) { |
| 2424 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2425 | } |
| 2426 | //dump(); |
| 2427 | Binder.restoreCallingIdentity(origId); |
| 2428 | return; |
| 2429 | } |
| 2430 | } |
| 2431 | |
| 2432 | removeWindowInnerLocked(session, win); |
| 2433 | // Removing a visible window will effect the computed orientation |
| 2434 | // So just update orientation if needed. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2435 | if (wasVisible && computeForcedAppOrientationLocked() |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2436 | != mForcedAppOrientation |
| 2437 | && updateOrientationFromAppTokensLocked()) { |
| 2438 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2439 | } |
| 2440 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2441 | Binder.restoreCallingIdentity(origId); |
| 2442 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2443 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2444 | private void removeWindowInnerLocked(Session session, WindowState win) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2445 | win.mRemoved = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2446 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2447 | if (mInputMethodTarget == win) { |
| 2448 | moveInputMethodWindowsIfNeededLocked(false); |
| 2449 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2450 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2451 | if (false) { |
| 2452 | RuntimeException e = new RuntimeException("here"); |
| 2453 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2454 | Slog.w(TAG, "Removing window " + win, e); |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2455 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2456 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2457 | mPolicy.removeWindowLw(win); |
| 2458 | win.removeLocked(); |
| 2459 | |
| 2460 | mWindowMap.remove(win.mClient.asBinder()); |
| 2461 | mWindows.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2462 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2463 | 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] | 2464 | |
| 2465 | if (mInputMethodWindow == win) { |
| 2466 | mInputMethodWindow = null; |
| 2467 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2468 | mInputMethodDialogs.remove(win); |
| 2469 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2470 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2471 | final WindowToken token = win.mToken; |
| 2472 | final AppWindowToken atoken = win.mAppToken; |
| 2473 | token.windows.remove(win); |
| 2474 | if (atoken != null) { |
| 2475 | atoken.allAppWindows.remove(win); |
| 2476 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2477 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2478 | TAG, "**** Removing window " + win + ": count=" |
| 2479 | + token.windows.size()); |
| 2480 | if (token.windows.size() == 0) { |
| 2481 | if (!token.explicit) { |
| 2482 | mTokenMap.remove(token.token); |
| 2483 | mTokenList.remove(token); |
| 2484 | } else if (atoken != null) { |
| 2485 | atoken.firstWindowDrawn = false; |
| 2486 | } |
| 2487 | } |
| 2488 | |
| 2489 | if (atoken != null) { |
| 2490 | if (atoken.startingWindow == win) { |
| 2491 | atoken.startingWindow = null; |
| 2492 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2493 | // If this is the last window and we had requested a starting |
| 2494 | // transition window, well there is no point now. |
| 2495 | atoken.startingData = null; |
| 2496 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2497 | // If this is the last window except for a starting transition |
| 2498 | // window, we need to get rid of the starting transition. |
| 2499 | if (DEBUG_STARTING_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2500 | Slog.v(TAG, "Schedule remove starting " + token |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2501 | + ": no more real windows"); |
| 2502 | } |
| 2503 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2504 | mH.sendMessage(m); |
| 2505 | } |
| 2506 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2507 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2508 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2509 | mLastWallpaperTimeoutTime = 0; |
| 2510 | adjustWallpaperWindowsLocked(); |
| 2511 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2512 | adjustWallpaperWindowsLocked(); |
| 2513 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2514 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2515 | if (!mInLayout) { |
| 2516 | assignLayersLocked(); |
| 2517 | mLayoutNeeded = true; |
| 2518 | performLayoutAndPlaceSurfacesLocked(); |
| 2519 | if (win.mAppToken != null) { |
| 2520 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2521 | } |
| 2522 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2523 | |
| 2524 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2525 | } |
| 2526 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2527 | private static void logSurface(WindowState w, String msg, RuntimeException where) { |
| 2528 | String str = " SURFACE " + Integer.toHexString(w.hashCode()) |
| 2529 | + ": " + msg + " / " + w.mAttrs.getTitle(); |
| 2530 | if (where != null) { |
| 2531 | Slog.i(TAG, str, where); |
| 2532 | } else { |
| 2533 | Slog.i(TAG, str); |
| 2534 | } |
| 2535 | } |
| 2536 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2537 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 2538 | long origId = Binder.clearCallingIdentity(); |
| 2539 | try { |
| 2540 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2541 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2542 | if ((w != null) && (w.mSurface != null)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2543 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2544 | Surface.openTransaction(); |
| 2545 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2546 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 2547 | "transparentRegionHint=" + region, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2548 | w.mSurface.setTransparentRegionHint(region); |
| 2549 | } finally { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2550 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2551 | Surface.closeTransaction(); |
| 2552 | } |
| 2553 | } |
| 2554 | } |
| 2555 | } finally { |
| 2556 | Binder.restoreCallingIdentity(origId); |
| 2557 | } |
| 2558 | } |
| 2559 | |
| 2560 | void setInsetsWindow(Session session, IWindow client, |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2561 | int touchableInsets, Rect contentInsets, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2562 | Rect visibleInsets) { |
| 2563 | long origId = Binder.clearCallingIdentity(); |
| 2564 | try { |
| 2565 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2566 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2567 | if (w != null) { |
| 2568 | w.mGivenInsetsPending = false; |
| 2569 | w.mGivenContentInsets.set(contentInsets); |
| 2570 | w.mGivenVisibleInsets.set(visibleInsets); |
| 2571 | w.mTouchableInsets = touchableInsets; |
| 2572 | mLayoutNeeded = true; |
| 2573 | performLayoutAndPlaceSurfacesLocked(); |
| 2574 | } |
| 2575 | } |
| 2576 | } finally { |
| 2577 | Binder.restoreCallingIdentity(origId); |
| 2578 | } |
| 2579 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2580 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2581 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2582 | Rect outDisplayFrame) { |
| 2583 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2584 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2585 | if (win == null) { |
| 2586 | outDisplayFrame.setEmpty(); |
| 2587 | return; |
| 2588 | } |
| 2589 | outDisplayFrame.set(win.mDisplayFrame); |
| 2590 | } |
| 2591 | } |
| 2592 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2593 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2594 | float xStep, float yStep) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2595 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2596 | window.mWallpaperX = x; |
| 2597 | window.mWallpaperY = y; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2598 | window.mWallpaperXStep = xStep; |
| 2599 | window.mWallpaperYStep = yStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2600 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2601 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2602 | } |
| 2603 | } |
| 2604 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2605 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2606 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2607 | synchronized (mWindowMap) { |
| 2608 | if (mWaitingOnWallpaper != null && |
| 2609 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2610 | mWaitingOnWallpaper = null; |
| 2611 | mWindowMap.notifyAll(); |
| 2612 | } |
| 2613 | } |
| 2614 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2615 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2616 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2617 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2618 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2619 | || window == mUpperWallpaperTarget) { |
| 2620 | boolean doWait = sync; |
| 2621 | int curTokenIndex = mWallpaperTokens.size(); |
| 2622 | while (curTokenIndex > 0) { |
| 2623 | curTokenIndex--; |
| 2624 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2625 | int curWallpaperIndex = token.windows.size(); |
| 2626 | while (curWallpaperIndex > 0) { |
| 2627 | curWallpaperIndex--; |
| 2628 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2629 | try { |
| 2630 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2631 | x, y, z, extras, sync); |
| 2632 | // We only want to be synchronous with one wallpaper. |
| 2633 | sync = false; |
| 2634 | } catch (RemoteException e) { |
| 2635 | } |
| 2636 | } |
| 2637 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2638 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2639 | if (doWait) { |
| 2640 | // XXX Need to wait for result. |
| 2641 | } |
| 2642 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2643 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2644 | return null; |
| 2645 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2646 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2647 | public int relayoutWindow(Session session, IWindow client, |
| 2648 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2649 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2650 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2651 | Configuration outConfig, Surface outSurface) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2652 | boolean displayed = false; |
| 2653 | boolean inTouchMode; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2654 | boolean configChanged; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2655 | long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2656 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2657 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2658 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2659 | if (win == null) { |
| 2660 | return 0; |
| 2661 | } |
| 2662 | win.mRequestedWidth = requestedWidth; |
| 2663 | win.mRequestedHeight = requestedHeight; |
| 2664 | |
| 2665 | if (attrs != null) { |
| 2666 | mPolicy.adjustWindowParamsLw(attrs); |
| 2667 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2668 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2669 | int attrChanges = 0; |
| 2670 | int flagChanges = 0; |
| 2671 | if (attrs != null) { |
| 2672 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2673 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2674 | } |
| 2675 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2676 | 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] | 2677 | |
| 2678 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2679 | win.mAlpha = attrs.alpha; |
| 2680 | } |
| 2681 | |
| 2682 | final boolean scaledWindow = |
| 2683 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2684 | |
| 2685 | if (scaledWindow) { |
| 2686 | // requested{Width|Height} Surface's physical size |
| 2687 | // attrs.{width|height} Size on screen |
| 2688 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2689 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2690 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2691 | (attrs.height / (float)requestedHeight) : 1.0f; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2692 | } else { |
| 2693 | win.mHScale = win.mVScale = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2694 | } |
| 2695 | |
| 2696 | boolean imMayMove = (flagChanges&( |
| 2697 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2698 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2699 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2700 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2701 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2702 | || (!win.mRelayoutCalled); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2703 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2704 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2705 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2706 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2707 | win.mRelayoutCalled = true; |
| 2708 | final int oldVisibility = win.mViewVisibility; |
| 2709 | win.mViewVisibility = viewVisibility; |
| 2710 | if (viewVisibility == View.VISIBLE && |
| 2711 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2712 | displayed = !win.isVisibleLw(); |
| 2713 | if (win.mExiting) { |
| 2714 | win.mExiting = false; |
| 2715 | win.mAnimation = null; |
| 2716 | } |
| 2717 | if (win.mDestroying) { |
| 2718 | win.mDestroying = false; |
| 2719 | mDestroySurface.remove(win); |
| 2720 | } |
| 2721 | if (oldVisibility == View.GONE) { |
| 2722 | win.mEnterAnimationPending = true; |
| 2723 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2724 | if (displayed) { |
| 2725 | if (win.mSurface != null && !win.mDrawPending |
| 2726 | && !win.mCommitDrawPending && !mDisplayFrozen |
| 2727 | && mPolicy.isScreenOn()) { |
| 2728 | applyEnterAnimationLocked(win); |
| 2729 | } |
| 2730 | if ((win.mAttrs.flags |
| 2731 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2732 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2733 | "Relayout window turning screen on: " + win); |
| 2734 | win.mTurnOnScreen = true; |
| 2735 | } |
| 2736 | int diff = 0; |
| 2737 | if (win.mConfiguration != mCurConfiguration |
| 2738 | && (win.mConfiguration == null |
| 2739 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2740 | win.mConfiguration = mCurConfiguration; |
| 2741 | if (DEBUG_CONFIGURATION) { |
| 2742 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2743 | + win.mConfiguration + " / 0x" |
| 2744 | + Integer.toHexString(diff)); |
| 2745 | } |
| 2746 | outConfig.setTo(mCurConfiguration); |
| 2747 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2748 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2749 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2750 | // To change the format, we need to re-build the surface. |
| 2751 | win.destroySurfaceLocked(); |
| 2752 | displayed = true; |
| 2753 | } |
| 2754 | try { |
| 2755 | Surface surface = win.createSurfaceLocked(); |
| 2756 | if (surface != null) { |
| 2757 | outSurface.copyFrom(surface); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2758 | win.mReportDestroySurface = false; |
| 2759 | win.mSurfacePendingDestroy = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2760 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2761 | " OUT SURFACE " + outSurface + ": copied"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2762 | } else { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2763 | // For some reason there isn't a surface. Clear the |
| 2764 | // caller's object so they see the same state. |
| 2765 | outSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2766 | } |
| 2767 | } catch (Exception e) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2768 | mInputMonitor.updateInputWindowsLw(); |
| 2769 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2770 | Slog.w(TAG, "Exception thrown when creating surface for client " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2771 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2772 | e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2773 | Binder.restoreCallingIdentity(origId); |
| 2774 | return 0; |
| 2775 | } |
| 2776 | if (displayed) { |
| 2777 | focusMayChange = true; |
| 2778 | } |
| 2779 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2780 | && mInputMethodWindow == null) { |
| 2781 | mInputMethodWindow = win; |
| 2782 | imMayMove = true; |
| 2783 | } |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2784 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2785 | && win.mAppToken != null |
| 2786 | && win.mAppToken.startingWindow != null) { |
| 2787 | // Special handling of starting window over the base |
| 2788 | // window of the app: propagate lock screen flags to it, |
| 2789 | // to provide the correct semantics while starting. |
| 2790 | final int mask = |
| 2791 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2792 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2793 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2794 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2795 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2796 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2797 | } else { |
| 2798 | win.mEnterAnimationPending = false; |
| 2799 | if (win.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2800 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2801 | + ": mExiting=" + win.mExiting |
| 2802 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2803 | // If we are not currently running the exit animation, we |
| 2804 | // need to see about starting one. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2805 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2806 | // Try starting an animation; if there isn't one, we |
| 2807 | // can destroy the surface right away. |
| 2808 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2809 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2810 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2811 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2812 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2813 | applyAnimationLocked(win, transit, false)) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2814 | focusMayChange = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2815 | win.mExiting = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2816 | } else if (win.isAnimating()) { |
| 2817 | // Currently in a hide animation... turn this into |
| 2818 | // an exit. |
| 2819 | win.mExiting = true; |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2820 | } else if (win == mWallpaperTarget) { |
| 2821 | // If the wallpaper is currently behind this |
| 2822 | // window, we need to change both of them inside |
| 2823 | // of a transaction to avoid artifacts. |
| 2824 | win.mExiting = true; |
| 2825 | win.mAnimating = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2826 | } else { |
| 2827 | if (mInputMethodWindow == win) { |
| 2828 | mInputMethodWindow = null; |
| 2829 | } |
| 2830 | win.destroySurfaceLocked(); |
| 2831 | } |
| 2832 | } |
| 2833 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2834 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2835 | if (win.mSurface == null || (win.getAttrs().flags |
| 2836 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2837 | || win.mSurfacePendingDestroy) { |
| 2838 | // We are being called from a local process, which |
| 2839 | // means outSurface holds its current surface. Ensure the |
| 2840 | // surface object is cleared, but we don't want it actually |
| 2841 | // destroyed at this point. |
| 2842 | win.mSurfacePendingDestroy = false; |
| 2843 | outSurface.release(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2844 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2845 | } else if (win.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2846 | if (DEBUG_VISIBILITY) Slog.i(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2847 | "Keeping surface, will report destroy: " + win); |
| 2848 | win.mReportDestroySurface = true; |
| 2849 | outSurface.copyFrom(win.mSurface); |
| 2850 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2851 | } |
| 2852 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2853 | if (focusMayChange) { |
| 2854 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| 2855 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2856 | imMayMove = false; |
| 2857 | } |
| 2858 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2859 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2860 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2861 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2862 | // reassign them at this point if the IM window state gets shuffled |
| 2863 | boolean assignLayers = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2864 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2865 | if (imMayMove) { |
Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2866 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2867 | // Little hack here -- we -should- be able to rely on the |
| 2868 | // function to return true if the IME has moved and needs |
| 2869 | // its layer recomputed. However, if the IME was hidden |
| 2870 | // and isn't actually moved in the list, its layer may be |
| 2871 | // 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] | 2872 | assignLayers = true; |
| 2873 | } |
| 2874 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2875 | if (wallpaperMayMove) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2876 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2877 | assignLayers = true; |
| 2878 | } |
| 2879 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2880 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2881 | mLayoutNeeded = true; |
| 2882 | win.mGivenInsetsPending = insetsPending; |
| 2883 | if (assignLayers) { |
| 2884 | assignLayersLocked(); |
| 2885 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2886 | configChanged = updateOrientationFromAppTokensLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2887 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2888 | if (displayed && win.mIsWallpaper) { |
| 2889 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2890 | mDisplay.getHeight(), false); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2891 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2892 | if (win.mAppToken != null) { |
| 2893 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2894 | } |
| 2895 | outFrame.set(win.mFrame); |
| 2896 | outContentInsets.set(win.mContentInsets); |
| 2897 | outVisibleInsets.set(win.mVisibleInsets); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2898 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2899 | TAG, "Relayout given client " + client.asBinder() |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2900 | + ", requestedWidth=" + requestedWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2901 | + ", requestedHeight=" + requestedHeight |
| 2902 | + ", viewVisibility=" + viewVisibility |
| 2903 | + "\nRelayout returning frame=" + outFrame |
| 2904 | + ", surface=" + outSurface); |
| 2905 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2906 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2907 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2908 | |
| 2909 | inTouchMode = mInTouchMode; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2910 | |
| 2911 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2912 | } |
| 2913 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2914 | if (configChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2915 | sendNewConfiguration(); |
| 2916 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2917 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2918 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2919 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2920 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 2921 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 2922 | } |
| 2923 | |
| 2924 | public void finishDrawingWindow(Session session, IWindow client) { |
| 2925 | final long origId = Binder.clearCallingIdentity(); |
| 2926 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2927 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2928 | if (win != null && win.finishDrawingLocked()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2929 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 2930 | adjustWallpaperWindowsLocked(); |
| 2931 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2932 | mLayoutNeeded = true; |
| 2933 | performLayoutAndPlaceSurfacesLocked(); |
| 2934 | } |
| 2935 | } |
| 2936 | Binder.restoreCallingIdentity(origId); |
| 2937 | } |
| 2938 | |
| 2939 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2940 | 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] | 2941 | + (lp != null ? lp.packageName : null) |
| 2942 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 2943 | if (lp != null && lp.windowAnimations != 0) { |
| 2944 | // If this is a system resource, don't try to load it from the |
| 2945 | // application resources. It is nice to avoid loading application |
| 2946 | // resources if we can. |
| 2947 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 2948 | int resId = lp.windowAnimations; |
| 2949 | if ((resId&0xFF000000) == 0x01000000) { |
| 2950 | packageName = "android"; |
| 2951 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2952 | 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] | 2953 | + packageName); |
| 2954 | return AttributeCache.instance().get(packageName, resId, |
| 2955 | com.android.internal.R.styleable.WindowAnimation); |
| 2956 | } |
| 2957 | return null; |
| 2958 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2959 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2960 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2961 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2962 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 2963 | if (packageName != null) { |
| 2964 | if ((resId&0xFF000000) == 0x01000000) { |
| 2965 | packageName = "android"; |
| 2966 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2967 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2968 | + packageName); |
| 2969 | return AttributeCache.instance().get(packageName, resId, |
| 2970 | com.android.internal.R.styleable.WindowAnimation); |
| 2971 | } |
| 2972 | return null; |
| 2973 | } |
| 2974 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2975 | private void applyEnterAnimationLocked(WindowState win) { |
| 2976 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 2977 | if (win.mEnterAnimationPending) { |
| 2978 | win.mEnterAnimationPending = false; |
| 2979 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 2980 | } |
| 2981 | |
| 2982 | applyAnimationLocked(win, transit, true); |
| 2983 | } |
| 2984 | |
| 2985 | private boolean applyAnimationLocked(WindowState win, |
| 2986 | int transit, boolean isEntrance) { |
| 2987 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 2988 | // If we are trying to apply an animation, but already running |
| 2989 | // an animation of the same type, then just leave that one alone. |
| 2990 | return true; |
| 2991 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2992 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2993 | // Only apply an animation if the display isn't frozen. If it is |
| 2994 | // frozen, there is no reason to animate and it can cause strange |
| 2995 | // artifacts when we unfreeze the display if some different animation |
| 2996 | // is running. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2997 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2998 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 2999 | int attr = -1; |
| 3000 | Animation a = null; |
| 3001 | if (anim != 0) { |
| 3002 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 3003 | } else { |
| 3004 | switch (transit) { |
| 3005 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 3006 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 3007 | break; |
| 3008 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 3009 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 3010 | break; |
| 3011 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 3012 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 3013 | break; |
| 3014 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 3015 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 3016 | break; |
| 3017 | } |
| 3018 | if (attr >= 0) { |
| 3019 | a = loadAnimation(win.mAttrs, attr); |
| 3020 | } |
| 3021 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3022 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3023 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 3024 | + " mAnimation=" + win.mAnimation |
| 3025 | + " isEntrance=" + isEntrance); |
| 3026 | if (a != null) { |
| 3027 | if (DEBUG_ANIM) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3028 | RuntimeException e = null; |
| 3029 | if (!HIDE_STACK_CRAWLS) { |
| 3030 | e = new RuntimeException(); |
| 3031 | e.fillInStackTrace(); |
| 3032 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3033 | Slog.v(TAG, "Loaded animation " + a + " for " + win, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3034 | } |
| 3035 | win.setAnimation(a); |
| 3036 | win.mAnimationIsEntrance = isEntrance; |
| 3037 | } |
| 3038 | } else { |
| 3039 | win.clearAnimation(); |
| 3040 | } |
| 3041 | |
| 3042 | return win.mAnimation != null; |
| 3043 | } |
| 3044 | |
| 3045 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 3046 | int anim = 0; |
| 3047 | Context context = mContext; |
| 3048 | if (animAttr >= 0) { |
| 3049 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 3050 | if (ent != null) { |
| 3051 | context = ent.context; |
| 3052 | anim = ent.array.getResourceId(animAttr, 0); |
| 3053 | } |
| 3054 | } |
| 3055 | if (anim != 0) { |
| 3056 | return AnimationUtils.loadAnimation(context, anim); |
| 3057 | } |
| 3058 | return null; |
| 3059 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3060 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3061 | private Animation loadAnimation(String packageName, int resId) { |
| 3062 | int anim = 0; |
| 3063 | Context context = mContext; |
| 3064 | if (resId >= 0) { |
| 3065 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 3066 | if (ent != null) { |
| 3067 | context = ent.context; |
| 3068 | anim = resId; |
| 3069 | } |
| 3070 | } |
| 3071 | if (anim != 0) { |
| 3072 | return AnimationUtils.loadAnimation(context, anim); |
| 3073 | } |
| 3074 | return null; |
| 3075 | } |
| 3076 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3077 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 3078 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 3079 | // Only apply an animation if the display isn't frozen. If it is |
| 3080 | // frozen, there is no reason to animate and it can cause strange |
| 3081 | // artifacts when we unfreeze the display if some different animation |
| 3082 | // is running. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3083 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3084 | Animation a; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 3085 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3086 | a = new FadeInOutAnimation(enter); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3087 | if (DEBUG_ANIM) Slog.v(TAG, |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3088 | "applying FadeInOutAnimation for a window in compatibility mode"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3089 | } else if (mNextAppTransitionPackage != null) { |
| 3090 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 3091 | mNextAppTransitionEnter : mNextAppTransitionExit); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3092 | } else { |
| 3093 | int animAttr = 0; |
| 3094 | switch (transit) { |
| 3095 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 3096 | animAttr = enter |
| 3097 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 3098 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 3099 | break; |
| 3100 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 3101 | animAttr = enter |
| 3102 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 3103 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 3104 | break; |
| 3105 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 3106 | animAttr = enter |
| 3107 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 3108 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 3109 | break; |
| 3110 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 3111 | animAttr = enter |
| 3112 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 3113 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 3114 | break; |
| 3115 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 3116 | animAttr = enter |
| 3117 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 3118 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 3119 | break; |
| 3120 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 3121 | animAttr = enter |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 3122 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3123 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 3124 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3125 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3126 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3127 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 3128 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3129 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3130 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3131 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3132 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 3133 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 3134 | break; |
| 3135 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 3136 | animAttr = enter |
| 3137 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 3138 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 3139 | break; |
| 3140 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 3141 | animAttr = enter |
| 3142 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 3143 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3144 | break; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3145 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3146 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3147 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3148 | + " anim=" + a |
| 3149 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 3150 | + " transit=" + transit); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3151 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3152 | if (a != null) { |
| 3153 | if (DEBUG_ANIM) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3154 | RuntimeException e = null; |
| 3155 | if (!HIDE_STACK_CRAWLS) { |
| 3156 | e = new RuntimeException(); |
| 3157 | e.fillInStackTrace(); |
| 3158 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3159 | Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3160 | } |
| 3161 | wtoken.setAnimation(a); |
| 3162 | } |
| 3163 | } else { |
| 3164 | wtoken.clearAnimation(); |
| 3165 | } |
| 3166 | |
| 3167 | return wtoken.animation != null; |
| 3168 | } |
| 3169 | |
| 3170 | // ------------------------------------------------------------- |
| 3171 | // Application Window Tokens |
| 3172 | // ------------------------------------------------------------- |
| 3173 | |
| 3174 | public void validateAppTokens(List tokens) { |
| 3175 | int v = tokens.size()-1; |
| 3176 | int m = mAppTokens.size()-1; |
| 3177 | while (v >= 0 && m >= 0) { |
| 3178 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3179 | if (wtoken.removed) { |
| 3180 | m--; |
| 3181 | continue; |
| 3182 | } |
| 3183 | if (tokens.get(v) != wtoken.token) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3184 | 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] | 3185 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 3186 | } |
| 3187 | v--; |
| 3188 | m--; |
| 3189 | } |
| 3190 | while (v >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3191 | 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] | 3192 | v--; |
| 3193 | } |
| 3194 | while (m >= 0) { |
| 3195 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3196 | if (!wtoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3197 | Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3198 | } |
| 3199 | m--; |
| 3200 | } |
| 3201 | } |
| 3202 | |
| 3203 | boolean checkCallingPermission(String permission, String func) { |
| 3204 | // Quick check: if the calling permission is me, it's all okay. |
| 3205 | if (Binder.getCallingPid() == Process.myPid()) { |
| 3206 | return true; |
| 3207 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3208 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3209 | if (mContext.checkCallingPermission(permission) |
| 3210 | == PackageManager.PERMISSION_GRANTED) { |
| 3211 | return true; |
| 3212 | } |
| 3213 | String msg = "Permission Denial: " + func + " from pid=" |
| 3214 | + Binder.getCallingPid() |
| 3215 | + ", uid=" + Binder.getCallingUid() |
| 3216 | + " requires " + permission; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3217 | Slog.w(TAG, msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3218 | return false; |
| 3219 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3220 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3221 | AppWindowToken findAppWindowToken(IBinder token) { |
| 3222 | WindowToken wtoken = mTokenMap.get(token); |
| 3223 | if (wtoken == null) { |
| 3224 | return null; |
| 3225 | } |
| 3226 | return wtoken.appWindowToken; |
| 3227 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3228 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3229 | public void addWindowToken(IBinder token, int type) { |
| 3230 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3231 | "addWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3232 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3233 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3234 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3235 | synchronized(mWindowMap) { |
| 3236 | WindowToken wtoken = mTokenMap.get(token); |
| 3237 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3238 | 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] | 3239 | return; |
| 3240 | } |
| 3241 | wtoken = new WindowToken(token, type, true); |
| 3242 | mTokenMap.put(token, wtoken); |
| 3243 | mTokenList.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3244 | if (type == TYPE_WALLPAPER) { |
| 3245 | mWallpaperTokens.add(wtoken); |
| 3246 | } |
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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3250 | public void removeWindowToken(IBinder token) { |
| 3251 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3252 | "removeWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3253 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3254 | } |
| 3255 | |
| 3256 | final long origId = Binder.clearCallingIdentity(); |
| 3257 | synchronized(mWindowMap) { |
| 3258 | WindowToken wtoken = mTokenMap.remove(token); |
| 3259 | mTokenList.remove(wtoken); |
| 3260 | if (wtoken != null) { |
| 3261 | boolean delayed = false; |
| 3262 | if (!wtoken.hidden) { |
| 3263 | wtoken.hidden = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3264 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3265 | final int N = wtoken.windows.size(); |
| 3266 | boolean changed = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3267 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3268 | for (int i=0; i<N; i++) { |
| 3269 | WindowState win = wtoken.windows.get(i); |
| 3270 | |
| 3271 | if (win.isAnimating()) { |
| 3272 | delayed = true; |
| 3273 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3274 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3275 | if (win.isVisibleNow()) { |
| 3276 | applyAnimationLocked(win, |
| 3277 | WindowManagerPolicy.TRANSIT_EXIT, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3278 | changed = true; |
| 3279 | } |
| 3280 | } |
| 3281 | |
| 3282 | if (changed) { |
| 3283 | mLayoutNeeded = true; |
| 3284 | performLayoutAndPlaceSurfacesLocked(); |
| 3285 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3286 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3287 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3288 | if (delayed) { |
| 3289 | mExitingTokens.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3290 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 3291 | mWallpaperTokens.remove(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3292 | } |
| 3293 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3294 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3295 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3296 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3297 | 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] | 3298 | } |
| 3299 | } |
| 3300 | Binder.restoreCallingIdentity(origId); |
| 3301 | } |
| 3302 | |
| 3303 | public void addAppToken(int addPos, IApplicationToken token, |
| 3304 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 3305 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3306 | "addAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3307 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3308 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3309 | |
| 3310 | // Get the dispatching timeout here while we are not holding any locks so that it |
| 3311 | // can be cached by the AppWindowToken. The timeout value is used later by the |
| 3312 | // input dispatcher in code that does hold locks. If we did not cache the value |
| 3313 | // here we would run the chance of introducing a deadlock between the window manager |
| 3314 | // (which holds locks while updating the input dispatcher state) and the activity manager |
| 3315 | // (which holds locks while querying the application token). |
| 3316 | long inputDispatchingTimeoutNanos; |
| 3317 | try { |
| 3318 | inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L; |
| 3319 | } catch (RemoteException ex) { |
| 3320 | Slog.w(TAG, "Could not get dispatching timeout.", ex); |
| 3321 | inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 3322 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3323 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3324 | synchronized(mWindowMap) { |
| 3325 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3326 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3327 | 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] | 3328 | return; |
| 3329 | } |
| 3330 | wtoken = new AppWindowToken(token); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3331 | wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3332 | wtoken.groupId = groupId; |
| 3333 | wtoken.appFullscreen = fullscreen; |
| 3334 | wtoken.requestedOrientation = requestedOrientation; |
| 3335 | mAppTokens.add(addPos, wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3336 | 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] | 3337 | mTokenMap.put(token.asBinder(), wtoken); |
| 3338 | mTokenList.add(wtoken); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3339 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3340 | // Application tokens start out hidden. |
| 3341 | wtoken.hidden = true; |
| 3342 | wtoken.hiddenRequested = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3343 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3344 | //dump(); |
| 3345 | } |
| 3346 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3347 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3348 | public void setAppGroupId(IBinder token, int groupId) { |
| 3349 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3350 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3351 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3352 | } |
| 3353 | |
| 3354 | synchronized(mWindowMap) { |
| 3355 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3356 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3357 | 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] | 3358 | return; |
| 3359 | } |
| 3360 | wtoken.groupId = groupId; |
| 3361 | } |
| 3362 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3363 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3364 | public int getOrientationFromWindowsLocked() { |
| 3365 | int pos = mWindows.size() - 1; |
| 3366 | while (pos >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3367 | WindowState wtoken = mWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3368 | pos--; |
| 3369 | if (wtoken.mAppToken != null) { |
| 3370 | // We hit an application window. so the orientation will be determined by the |
| 3371 | // app window. No point in continuing further. |
| 3372 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3373 | } |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3374 | if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3375 | continue; |
| 3376 | } |
| 3377 | int req = wtoken.mAttrs.screenOrientation; |
| 3378 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 3379 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 3380 | continue; |
| 3381 | } else { |
| 3382 | return req; |
| 3383 | } |
| 3384 | } |
| 3385 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3386 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3387 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3388 | public int getOrientationFromAppTokensLocked() { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3389 | int pos = mAppTokens.size() - 1; |
| 3390 | int curGroup = 0; |
| 3391 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3392 | boolean findingBehind = false; |
| 3393 | boolean haveGroup = false; |
| 3394 | boolean lastFullscreen = false; |
| 3395 | while (pos >= 0) { |
| 3396 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 3397 | pos--; |
| 3398 | // if we're about to tear down this window and not seek for |
| 3399 | // the behind activity, don't use it for orientation |
| 3400 | if (!findingBehind |
| 3401 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| 3402 | continue; |
| 3403 | } |
| 3404 | |
| 3405 | if (!haveGroup) { |
| 3406 | // We ignore any hidden applications on the top. |
| 3407 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3408 | continue; |
| 3409 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3410 | haveGroup = true; |
| 3411 | curGroup = wtoken.groupId; |
| 3412 | lastOrientation = wtoken.requestedOrientation; |
| 3413 | } else if (curGroup != wtoken.groupId) { |
| 3414 | // If we have hit a new application group, and the bottom |
| 3415 | // of the previous group didn't explicitly say to use |
| 3416 | // the orientation behind it, and the last app was |
| 3417 | // full screen, then we'll stick with the |
| 3418 | // user's orientation. |
| 3419 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3420 | && lastFullscreen) { |
| 3421 | return lastOrientation; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3422 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3423 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3424 | int or = wtoken.requestedOrientation; |
| 3425 | // If this application is fullscreen, and didn't explicitly say |
| 3426 | // to use the orientation behind it, then just take whatever |
| 3427 | // orientation it has and ignores whatever is under it. |
| 3428 | lastFullscreen = wtoken.appFullscreen; |
| 3429 | if (lastFullscreen |
| 3430 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| 3431 | return or; |
| 3432 | } |
| 3433 | // If this application has requested an explicit orientation, |
| 3434 | // then use it. |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 3435 | if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 3436 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3437 | return or; |
| 3438 | } |
| 3439 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| 3440 | } |
| 3441 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3442 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3443 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3444 | public Configuration updateOrientationFromAppTokens( |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3445 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3446 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3447 | "updateOrientationFromAppTokens()")) { |
| 3448 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3449 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3450 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3451 | Configuration config = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3452 | long ident = Binder.clearCallingIdentity(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3453 | |
| 3454 | synchronized(mWindowMap) { |
| 3455 | if (updateOrientationFromAppTokensLocked()) { |
| 3456 | if (freezeThisOneIfNeeded != null) { |
| 3457 | AppWindowToken wtoken = findAppWindowToken( |
| 3458 | freezeThisOneIfNeeded); |
| 3459 | if (wtoken != null) { |
| 3460 | startAppFreezingScreenLocked(wtoken, |
| 3461 | ActivityInfo.CONFIG_ORIENTATION); |
| 3462 | } |
| 3463 | } |
| 3464 | config = computeNewConfigurationLocked(); |
| 3465 | |
| 3466 | } else if (currentConfig != null) { |
| 3467 | // No obvious action we need to take, but if our current |
Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3468 | // state mismatches the activity manager's, update it, |
| 3469 | // disregarding font scale, which should remain set to |
| 3470 | // the value of the previous configuration. |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3471 | mTempConfiguration.setToDefaults(); |
Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3472 | mTempConfiguration.fontScale = currentConfig.fontScale; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3473 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3474 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3475 | mWaitingForConfig = true; |
| 3476 | mLayoutNeeded = true; |
| 3477 | startFreezingDisplayLocked(); |
| 3478 | config = new Configuration(mTempConfiguration); |
| 3479 | } |
| 3480 | } |
| 3481 | } |
| 3482 | } |
| 3483 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3484 | Binder.restoreCallingIdentity(ident); |
| 3485 | return config; |
| 3486 | } |
| 3487 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3488 | /* |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3489 | * Determine the new desired orientation of the display, returning |
| 3490 | * a non-null new Configuration if it has changed from the current |
| 3491 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3492 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3493 | * SCREEN. This will typically be done for you if you call |
| 3494 | * sendNewConfiguration(). |
| 3495 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3496 | * The orientation is computed from non-application windows first. If none of |
| 3497 | * the non-application windows specify orientation, the orientation is computed from |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3498 | * application tokens. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3499 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3500 | * android.os.IBinder) |
| 3501 | */ |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3502 | boolean updateOrientationFromAppTokensLocked() { |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3503 | if (mDisplayFrozen) { |
| 3504 | // If the display is frozen, some activities may be in the middle |
| 3505 | // of restarting, and thus have removed their old window. If the |
| 3506 | // window has the flag to hide the lock screen, then the lock screen |
| 3507 | // can re-appear and inflict its own orientation on us. Keep the |
| 3508 | // orientation stable until this all settles down. |
| 3509 | return false; |
| 3510 | } |
| 3511 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3512 | boolean changed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3513 | long ident = Binder.clearCallingIdentity(); |
| 3514 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3515 | int req = computeForcedAppOrientationLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3516 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3517 | if (req != mForcedAppOrientation) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3518 | mForcedAppOrientation = req; |
| 3519 | //send a message to Policy indicating orientation change to take |
| 3520 | //action like disabling/enabling sensors etc., |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3521 | mPolicy.setCurrentOrientationLw(req); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3522 | if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION, |
| 3523 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) { |
| 3524 | changed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3525 | } |
| 3526 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3527 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3528 | return changed; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3529 | } finally { |
| 3530 | Binder.restoreCallingIdentity(ident); |
| 3531 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3532 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3533 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3534 | int computeForcedAppOrientationLocked() { |
| 3535 | int req = getOrientationFromWindowsLocked(); |
| 3536 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3537 | req = getOrientationFromAppTokensLocked(); |
| 3538 | } |
| 3539 | return req; |
| 3540 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3541 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3542 | public void setNewConfiguration(Configuration config) { |
| 3543 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3544 | "setNewConfiguration()")) { |
| 3545 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3546 | } |
| 3547 | |
| 3548 | synchronized(mWindowMap) { |
| 3549 | mCurConfiguration = new Configuration(config); |
| 3550 | mWaitingForConfig = false; |
| 3551 | performLayoutAndPlaceSurfacesLocked(); |
| 3552 | } |
| 3553 | } |
| 3554 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3555 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3556 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3557 | "setAppOrientation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3558 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3559 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3560 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3561 | synchronized(mWindowMap) { |
| 3562 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3563 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3564 | 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] | 3565 | return; |
| 3566 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3567 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3568 | wtoken.requestedOrientation = requestedOrientation; |
| 3569 | } |
| 3570 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3571 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3572 | public int getAppOrientation(IApplicationToken token) { |
| 3573 | synchronized(mWindowMap) { |
| 3574 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3575 | if (wtoken == null) { |
| 3576 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3577 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3578 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3579 | return wtoken.requestedOrientation; |
| 3580 | } |
| 3581 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3582 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3583 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3584 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3585 | "setFocusedApp()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3586 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3587 | } |
| 3588 | |
| 3589 | synchronized(mWindowMap) { |
| 3590 | boolean changed = false; |
| 3591 | if (token == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3592 | 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] | 3593 | changed = mFocusedApp != null; |
| 3594 | mFocusedApp = null; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3595 | if (changed) { |
| 3596 | mInputMonitor.setFocusedAppLw(null); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3597 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3598 | } else { |
| 3599 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3600 | if (newFocus == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3601 | 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] | 3602 | return; |
| 3603 | } |
| 3604 | changed = mFocusedApp != newFocus; |
| 3605 | mFocusedApp = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3606 | if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3607 | if (changed) { |
| 3608 | mInputMonitor.setFocusedAppLw(newFocus); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3609 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3610 | } |
| 3611 | |
| 3612 | if (moveFocusNow && changed) { |
| 3613 | final long origId = Binder.clearCallingIdentity(); |
| 3614 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3615 | Binder.restoreCallingIdentity(origId); |
| 3616 | } |
| 3617 | } |
| 3618 | } |
| 3619 | |
| 3620 | public void prepareAppTransition(int transit) { |
| 3621 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3622 | "prepareAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3623 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3624 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3625 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3626 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3627 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3628 | TAG, "Prepare app transition: transit=" + transit |
| 3629 | + " mNextAppTransition=" + mNextAppTransition); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3630 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3631 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3632 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3633 | mNextAppTransition = transit; |
Dianne Hackborn | d7cd29d | 2009-07-01 11:22:45 -0700 | [diff] [blame] | 3634 | } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3635 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3636 | // Opening a new task always supersedes a close for the anim. |
| 3637 | mNextAppTransition = transit; |
| 3638 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3639 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3640 | // Opening a new activity always supersedes a close for the anim. |
| 3641 | mNextAppTransition = transit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3642 | } |
| 3643 | mAppTransitionReady = false; |
| 3644 | mAppTransitionTimeout = false; |
| 3645 | mStartingIconInTransition = false; |
| 3646 | mSkipAppTransitionAnimation = false; |
| 3647 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3648 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3649 | 5000); |
| 3650 | } |
| 3651 | } |
| 3652 | } |
| 3653 | |
| 3654 | public int getPendingAppTransition() { |
| 3655 | return mNextAppTransition; |
| 3656 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3657 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3658 | public void overridePendingAppTransition(String packageName, |
| 3659 | int enterAnim, int exitAnim) { |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3660 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3661 | mNextAppTransitionPackage = packageName; |
| 3662 | mNextAppTransitionEnter = enterAnim; |
| 3663 | mNextAppTransitionExit = exitAnim; |
| 3664 | } |
| 3665 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3666 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3667 | public void executeAppTransition() { |
| 3668 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3669 | "executeAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3670 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3671 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3672 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3673 | synchronized(mWindowMap) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3674 | if (DEBUG_APP_TRANSITIONS) { |
| 3675 | RuntimeException e = new RuntimeException("here"); |
| 3676 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3677 | Slog.w(TAG, "Execute app transition: mNextAppTransition=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3678 | + mNextAppTransition, e); |
| 3679 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3680 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3681 | mAppTransitionReady = true; |
| 3682 | final long origId = Binder.clearCallingIdentity(); |
| 3683 | performLayoutAndPlaceSurfacesLocked(); |
| 3684 | Binder.restoreCallingIdentity(origId); |
| 3685 | } |
| 3686 | } |
| 3687 | } |
| 3688 | |
| 3689 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3690 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
| 3691 | IBinder transferFrom, boolean createIfNeeded) { |
| 3692 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3693 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3694 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3695 | } |
| 3696 | |
| 3697 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3698 | if (DEBUG_STARTING_WINDOW) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3699 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3700 | + " transferFrom=" + transferFrom); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3701 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3702 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3703 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3704 | 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] | 3705 | return; |
| 3706 | } |
| 3707 | |
| 3708 | // If the display is frozen, we won't do anything until the |
| 3709 | // actual window is displayed so there is no reason to put in |
| 3710 | // the starting window. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3711 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3712 | return; |
| 3713 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3714 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3715 | if (wtoken.startingData != null) { |
| 3716 | return; |
| 3717 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3718 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3719 | if (transferFrom != null) { |
| 3720 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3721 | if (ttoken != null) { |
| 3722 | WindowState startingWindow = ttoken.startingWindow; |
| 3723 | if (startingWindow != null) { |
| 3724 | if (mStartingIconInTransition) { |
| 3725 | // In this case, the starting icon has already |
| 3726 | // been displayed, so start letting windows get |
| 3727 | // shown immediately without any more transitions. |
| 3728 | mSkipAppTransitionAnimation = true; |
| 3729 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3730 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3731 | "Moving existing starting from " + ttoken |
| 3732 | + " to " + wtoken); |
| 3733 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3734 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3735 | // Transfer the starting window over to the new |
| 3736 | // token. |
| 3737 | wtoken.startingData = ttoken.startingData; |
| 3738 | wtoken.startingView = ttoken.startingView; |
| 3739 | wtoken.startingWindow = startingWindow; |
| 3740 | ttoken.startingData = null; |
| 3741 | ttoken.startingView = null; |
| 3742 | ttoken.startingWindow = null; |
| 3743 | ttoken.startingMoved = true; |
| 3744 | startingWindow.mToken = wtoken; |
Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3745 | startingWindow.mRootToken = wtoken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3746 | startingWindow.mAppToken = wtoken; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3747 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3748 | "Removing starting window: " + startingWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3749 | mWindows.remove(startingWindow); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3750 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3751 | ttoken.windows.remove(startingWindow); |
| 3752 | ttoken.allAppWindows.remove(startingWindow); |
| 3753 | addWindowToListInOrderLocked(startingWindow, true); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3754 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3755 | // Propagate other interesting state between the |
| 3756 | // tokens. If the old token is displayed, we should |
| 3757 | // immediately force the new one to be displayed. If |
| 3758 | // it is animating, we need to move that animation to |
| 3759 | // the new one. |
| 3760 | if (ttoken.allDrawn) { |
| 3761 | wtoken.allDrawn = true; |
| 3762 | } |
| 3763 | if (ttoken.firstWindowDrawn) { |
| 3764 | wtoken.firstWindowDrawn = true; |
| 3765 | } |
| 3766 | if (!ttoken.hidden) { |
| 3767 | wtoken.hidden = false; |
| 3768 | wtoken.hiddenRequested = false; |
| 3769 | wtoken.willBeHidden = false; |
| 3770 | } |
| 3771 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3772 | wtoken.clientHidden = ttoken.clientHidden; |
| 3773 | wtoken.sendAppVisibilityToClients(); |
| 3774 | } |
| 3775 | if (ttoken.animation != null) { |
| 3776 | wtoken.animation = ttoken.animation; |
| 3777 | wtoken.animating = ttoken.animating; |
| 3778 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3779 | ttoken.animation = null; |
| 3780 | ttoken.animLayerAdjustment = 0; |
| 3781 | wtoken.updateLayers(); |
| 3782 | ttoken.updateLayers(); |
| 3783 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3784 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3785 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3786 | mLayoutNeeded = true; |
| 3787 | performLayoutAndPlaceSurfacesLocked(); |
| 3788 | Binder.restoreCallingIdentity(origId); |
| 3789 | return; |
| 3790 | } else if (ttoken.startingData != null) { |
| 3791 | // The previous app was getting ready to show a |
| 3792 | // starting window, but hasn't yet done so. Steal it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3793 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3794 | "Moving pending starting from " + ttoken |
| 3795 | + " to " + wtoken); |
| 3796 | wtoken.startingData = ttoken.startingData; |
| 3797 | ttoken.startingData = null; |
| 3798 | ttoken.startingMoved = true; |
| 3799 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3800 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3801 | // want to process the message ASAP, before any other queued |
| 3802 | // messages. |
| 3803 | mH.sendMessageAtFrontOfQueue(m); |
| 3804 | return; |
| 3805 | } |
| 3806 | } |
| 3807 | } |
| 3808 | |
| 3809 | // There is no existing starting window, and the caller doesn't |
| 3810 | // want us to create one, so that's it! |
| 3811 | if (!createIfNeeded) { |
| 3812 | return; |
| 3813 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3814 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3815 | // If this is a translucent or wallpaper window, then don't |
| 3816 | // show a starting window -- the current effect (a full-screen |
| 3817 | // opaque starting window that fades away to the real contents |
| 3818 | // when it is ready) does not work for this. |
| 3819 | if (theme != 0) { |
| 3820 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3821 | com.android.internal.R.styleable.Window); |
| 3822 | if (ent.array.getBoolean( |
| 3823 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3824 | return; |
| 3825 | } |
| 3826 | if (ent.array.getBoolean( |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3827 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3828 | return; |
| 3829 | } |
| 3830 | if (ent.array.getBoolean( |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3831 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3832 | return; |
| 3833 | } |
| 3834 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3835 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3836 | mStartingIconInTransition = true; |
| 3837 | wtoken.startingData = new StartingData( |
| 3838 | pkg, theme, nonLocalizedLabel, |
| 3839 | labelRes, icon); |
| 3840 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3841 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3842 | // want to process the message ASAP, before any other queued |
| 3843 | // messages. |
| 3844 | mH.sendMessageAtFrontOfQueue(m); |
| 3845 | } |
| 3846 | } |
| 3847 | |
| 3848 | public void setAppWillBeHidden(IBinder token) { |
| 3849 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3850 | "setAppWillBeHidden()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3851 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3852 | } |
| 3853 | |
| 3854 | AppWindowToken wtoken; |
| 3855 | |
| 3856 | synchronized(mWindowMap) { |
| 3857 | wtoken = findAppWindowToken(token); |
| 3858 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3859 | 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] | 3860 | return; |
| 3861 | } |
| 3862 | wtoken.willBeHidden = true; |
| 3863 | } |
| 3864 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3865 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3866 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3867 | boolean visible, int transit, boolean performLayout) { |
| 3868 | boolean delayed = false; |
| 3869 | |
| 3870 | if (wtoken.clientHidden == visible) { |
| 3871 | wtoken.clientHidden = !visible; |
| 3872 | wtoken.sendAppVisibilityToClients(); |
| 3873 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3874 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3875 | wtoken.willBeHidden = false; |
| 3876 | if (wtoken.hidden == visible) { |
| 3877 | final int N = wtoken.allAppWindows.size(); |
| 3878 | boolean changed = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3879 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3880 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3881 | + " performLayout=" + performLayout); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3882 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3883 | boolean runningAppAnimation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3884 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3885 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3886 | if (wtoken.animation == sDummyAnimation) { |
| 3887 | wtoken.animation = null; |
| 3888 | } |
| 3889 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 3890 | changed = true; |
| 3891 | if (wtoken.animation != null) { |
| 3892 | delayed = runningAppAnimation = true; |
| 3893 | } |
| 3894 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3895 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3896 | for (int i=0; i<N; i++) { |
| 3897 | WindowState win = wtoken.allAppWindows.get(i); |
| 3898 | if (win == wtoken.startingWindow) { |
| 3899 | continue; |
| 3900 | } |
| 3901 | |
| 3902 | if (win.isAnimating()) { |
| 3903 | delayed = true; |
| 3904 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3905 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3906 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3907 | //win.dump(" "); |
| 3908 | if (visible) { |
| 3909 | if (!win.isVisibleNow()) { |
| 3910 | if (!runningAppAnimation) { |
| 3911 | applyAnimationLocked(win, |
| 3912 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 3913 | } |
| 3914 | changed = true; |
| 3915 | } |
| 3916 | } else if (win.isVisibleNow()) { |
| 3917 | if (!runningAppAnimation) { |
| 3918 | applyAnimationLocked(win, |
| 3919 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 3920 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3921 | changed = true; |
| 3922 | } |
| 3923 | } |
| 3924 | |
| 3925 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 3926 | if (!visible) { |
| 3927 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3928 | } else { |
| 3929 | // If we are being set visible, and the starting window is |
| 3930 | // not yet displayed, then make sure it doesn't get displayed. |
| 3931 | WindowState swin = wtoken.startingWindow; |
| 3932 | if (swin != null && (swin.mDrawPending |
| 3933 | || swin.mCommitDrawPending)) { |
| 3934 | swin.mPolicyVisibility = false; |
| 3935 | swin.mPolicyVisibilityAfterAnim = false; |
| 3936 | } |
| 3937 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3938 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3939 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3940 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 3941 | + wtoken.hiddenRequested); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3942 | |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3943 | if (changed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3944 | mLayoutNeeded = true; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3945 | if (performLayout) { |
| 3946 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 3947 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3948 | } else { |
| 3949 | mInputMonitor.updateInputWindowsLw(); |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3950 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3951 | } |
| 3952 | } |
| 3953 | |
| 3954 | if (wtoken.animation != null) { |
| 3955 | delayed = true; |
| 3956 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3957 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3958 | return delayed; |
| 3959 | } |
| 3960 | |
| 3961 | public void setAppVisibility(IBinder token, boolean visible) { |
| 3962 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3963 | "setAppVisibility()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3964 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3965 | } |
| 3966 | |
| 3967 | AppWindowToken wtoken; |
| 3968 | |
| 3969 | synchronized(mWindowMap) { |
| 3970 | wtoken = findAppWindowToken(token); |
| 3971 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3972 | 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] | 3973 | return; |
| 3974 | } |
| 3975 | |
| 3976 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3977 | RuntimeException e = null; |
| 3978 | if (!HIDE_STACK_CRAWLS) { |
| 3979 | e = new RuntimeException(); |
| 3980 | e.fillInStackTrace(); |
| 3981 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3982 | Slog.v(TAG, "setAppVisibility(" + token + ", " + visible |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3983 | + "): mNextAppTransition=" + mNextAppTransition |
| 3984 | + " hidden=" + wtoken.hidden |
| 3985 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 3986 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3987 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3988 | // If we are preparing an app transition, then delay changing |
| 3989 | // the visibility of this token until we execute that transition. |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3990 | if (!mDisplayFrozen && mPolicy.isScreenOn() |
| 3991 | && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3992 | // Already in requested state, don't do anything more. |
| 3993 | if (wtoken.hiddenRequested != visible) { |
| 3994 | return; |
| 3995 | } |
| 3996 | wtoken.hiddenRequested = !visible; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3997 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3998 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3999 | TAG, "Setting dummy animation on: " + wtoken); |
| 4000 | wtoken.setDummyAnimation(); |
| 4001 | mOpeningApps.remove(wtoken); |
| 4002 | mClosingApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4003 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4004 | wtoken.inPendingTransaction = true; |
| 4005 | if (visible) { |
| 4006 | mOpeningApps.add(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4007 | wtoken.startingDisplayed = false; |
| 4008 | wtoken.startingMoved = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4009 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4010 | // If the token is currently hidden (should be the |
| 4011 | // common case), then we need to set up to wait for |
| 4012 | // its windows to be ready. |
| 4013 | if (wtoken.hidden) { |
| 4014 | wtoken.allDrawn = false; |
| 4015 | wtoken.waitingToShow = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4016 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4017 | if (wtoken.clientHidden) { |
| 4018 | // In the case where we are making an app visible |
| 4019 | // but holding off for a transition, we still need |
| 4020 | // to tell the client to make its windows visible so |
| 4021 | // they get drawn. Otherwise, we will wait on |
| 4022 | // performing the transition until all windows have |
| 4023 | // been drawn, they never will be, and we are sad. |
| 4024 | wtoken.clientHidden = false; |
| 4025 | wtoken.sendAppVisibilityToClients(); |
| 4026 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4027 | } |
| 4028 | } else { |
| 4029 | mClosingApps.add(wtoken); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4030 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4031 | // If the token is currently visible (should be the |
| 4032 | // common case), then set up to wait for it to be hidden. |
| 4033 | if (!wtoken.hidden) { |
| 4034 | wtoken.waitingToHide = true; |
| 4035 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4036 | } |
| 4037 | return; |
| 4038 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4039 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4040 | final long origId = Binder.clearCallingIdentity(); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4041 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4042 | wtoken.updateReportedVisibilityLocked(); |
| 4043 | Binder.restoreCallingIdentity(origId); |
| 4044 | } |
| 4045 | } |
| 4046 | |
| 4047 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4048 | boolean unfreezeSurfaceNow, boolean force) { |
| 4049 | if (wtoken.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4050 | 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] | 4051 | + " force=" + force); |
| 4052 | final int N = wtoken.allAppWindows.size(); |
| 4053 | boolean unfrozeWindows = false; |
| 4054 | for (int i=0; i<N; i++) { |
| 4055 | WindowState w = wtoken.allAppWindows.get(i); |
| 4056 | if (w.mAppFreezing) { |
| 4057 | w.mAppFreezing = false; |
| 4058 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 4059 | w.mOrientationChanging = true; |
| 4060 | } |
| 4061 | unfrozeWindows = true; |
| 4062 | } |
| 4063 | } |
| 4064 | if (force || unfrozeWindows) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4065 | 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] | 4066 | wtoken.freezingScreen = false; |
| 4067 | mAppsFreezingScreen--; |
| 4068 | } |
| 4069 | if (unfreezeSurfaceNow) { |
| 4070 | if (unfrozeWindows) { |
| 4071 | mLayoutNeeded = true; |
| 4072 | performLayoutAndPlaceSurfacesLocked(); |
| 4073 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4074 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4075 | } |
| 4076 | } |
| 4077 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4078 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4079 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4080 | int configChanges) { |
| 4081 | if (DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 4082 | RuntimeException e = null; |
| 4083 | if (!HIDE_STACK_CRAWLS) { |
| 4084 | e = new RuntimeException(); |
| 4085 | e.fillInStackTrace(); |
| 4086 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4087 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4088 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 4089 | + wtoken.freezingScreen, e); |
| 4090 | } |
| 4091 | if (!wtoken.hiddenRequested) { |
| 4092 | if (!wtoken.freezingScreen) { |
| 4093 | wtoken.freezingScreen = true; |
| 4094 | mAppsFreezingScreen++; |
| 4095 | if (mAppsFreezingScreen == 1) { |
| 4096 | startFreezingDisplayLocked(); |
| 4097 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 4098 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 4099 | 5000); |
| 4100 | } |
| 4101 | } |
| 4102 | final int N = wtoken.allAppWindows.size(); |
| 4103 | for (int i=0; i<N; i++) { |
| 4104 | WindowState w = wtoken.allAppWindows.get(i); |
| 4105 | w.mAppFreezing = true; |
| 4106 | } |
| 4107 | } |
| 4108 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4109 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4110 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 4111 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4112 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4113 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4114 | } |
| 4115 | |
| 4116 | synchronized(mWindowMap) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 4117 | if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4118 | 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] | 4119 | return; |
| 4120 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4121 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4122 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4123 | if (wtoken == null || wtoken.appToken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4124 | 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] | 4125 | return; |
| 4126 | } |
| 4127 | final long origId = Binder.clearCallingIdentity(); |
| 4128 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 4129 | Binder.restoreCallingIdentity(origId); |
| 4130 | } |
| 4131 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4132 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4133 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 4134 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4135 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4136 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4137 | } |
| 4138 | |
| 4139 | synchronized(mWindowMap) { |
| 4140 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4141 | if (wtoken == null || wtoken.appToken == null) { |
| 4142 | return; |
| 4143 | } |
| 4144 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4145 | 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] | 4146 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 4147 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 4148 | Binder.restoreCallingIdentity(origId); |
| 4149 | } |
| 4150 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4151 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4152 | public void removeAppToken(IBinder token) { |
| 4153 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4154 | "removeAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4155 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4156 | } |
| 4157 | |
| 4158 | AppWindowToken wtoken = null; |
| 4159 | AppWindowToken startingToken = null; |
| 4160 | boolean delayed = false; |
| 4161 | |
| 4162 | final long origId = Binder.clearCallingIdentity(); |
| 4163 | synchronized(mWindowMap) { |
| 4164 | WindowToken basewtoken = mTokenMap.remove(token); |
| 4165 | mTokenList.remove(basewtoken); |
| 4166 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4167 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4168 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4169 | wtoken.inPendingTransaction = false; |
| 4170 | mOpeningApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4171 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4172 | if (mClosingApps.contains(wtoken)) { |
| 4173 | delayed = true; |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4174 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4175 | mClosingApps.add(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4176 | wtoken.waitingToHide = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4177 | delayed = true; |
| 4178 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4179 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4180 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 4181 | + " animation=" + wtoken.animation |
| 4182 | + " animating=" + wtoken.animating); |
| 4183 | if (delayed) { |
| 4184 | // set the token aside because it has an active animation to be finished |
| 4185 | mExitingAppTokens.add(wtoken); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 4186 | } else { |
| 4187 | // Make sure there is no animation running on this token, |
| 4188 | // so any windows associated with it will be removed as |
| 4189 | // soon as their animations are complete |
| 4190 | wtoken.animation = null; |
| 4191 | wtoken.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4192 | } |
| 4193 | mAppTokens.remove(wtoken); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 4194 | if (mLastEnterAnimToken == wtoken) { |
| 4195 | mLastEnterAnimToken = null; |
| 4196 | mLastEnterAnimParams = null; |
| 4197 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4198 | wtoken.removed = true; |
| 4199 | if (wtoken.startingData != null) { |
| 4200 | startingToken = wtoken; |
| 4201 | } |
| 4202 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 4203 | if (mFocusedApp == wtoken) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4204 | 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] | 4205 | mFocusedApp = null; |
| 4206 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4207 | mInputMonitor.setFocusedAppLw(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4208 | } |
| 4209 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4210 | 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] | 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 | if (!delayed && wtoken != null) { |
| 4214 | wtoken.updateReportedVisibilityLocked(); |
| 4215 | } |
| 4216 | } |
| 4217 | Binder.restoreCallingIdentity(origId); |
| 4218 | |
| 4219 | if (startingToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4220 | 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] | 4221 | + startingToken + ": app token removed"); |
| 4222 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 4223 | mH.sendMessage(m); |
| 4224 | } |
| 4225 | } |
| 4226 | |
| 4227 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 4228 | final int NW = token.windows.size(); |
| 4229 | for (int i=0; i<NW; i++) { |
| 4230 | WindowState win = token.windows.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4231 | 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] | 4232 | mWindows.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4233 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4234 | int j = win.mChildWindows.size(); |
| 4235 | while (j > 0) { |
| 4236 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4237 | WindowState cwin = win.mChildWindows.get(j); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4238 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4239 | "Tmp removing child window " + cwin); |
| 4240 | mWindows.remove(cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4241 | } |
| 4242 | } |
| 4243 | return NW > 0; |
| 4244 | } |
| 4245 | |
| 4246 | void dumpAppTokensLocked() { |
| 4247 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4248 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4249 | } |
| 4250 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4251 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4252 | void dumpWindowsLocked() { |
| 4253 | for (int i=mWindows.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4254 | Slog.v(TAG, " #" + i + ": " + mWindows.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4255 | } |
| 4256 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4257 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4258 | private int findWindowOffsetLocked(int tokenPos) { |
| 4259 | final int NW = mWindows.size(); |
| 4260 | |
| 4261 | if (tokenPos >= mAppTokens.size()) { |
| 4262 | int i = NW; |
| 4263 | while (i > 0) { |
| 4264 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4265 | WindowState win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4266 | if (win.getAppToken() != null) { |
| 4267 | return i+1; |
| 4268 | } |
| 4269 | } |
| 4270 | } |
| 4271 | |
| 4272 | while (tokenPos > 0) { |
| 4273 | // Find the first app token below the new position that has |
| 4274 | // a window displayed. |
| 4275 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4276 | 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] | 4277 | + tokenPos + " -- " + wtoken.token); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4278 | if (wtoken.sendingToBottom) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4279 | if (DEBUG_REORDER) Slog.v(TAG, |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4280 | "Skipping token -- currently sending to bottom"); |
| 4281 | tokenPos--; |
| 4282 | continue; |
| 4283 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4284 | int i = wtoken.windows.size(); |
| 4285 | while (i > 0) { |
| 4286 | i--; |
| 4287 | WindowState win = wtoken.windows.get(i); |
| 4288 | int j = win.mChildWindows.size(); |
| 4289 | while (j > 0) { |
| 4290 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4291 | WindowState cwin = win.mChildWindows.get(j); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4292 | if (cwin.mSubLayer >= 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4293 | for (int pos=NW-1; pos>=0; pos--) { |
| 4294 | if (mWindows.get(pos) == cwin) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4295 | if (DEBUG_REORDER) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4296 | "Found child win @" + (pos+1)); |
| 4297 | return pos+1; |
| 4298 | } |
| 4299 | } |
| 4300 | } |
| 4301 | } |
| 4302 | for (int pos=NW-1; pos>=0; pos--) { |
| 4303 | if (mWindows.get(pos) == win) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4304 | 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] | 4305 | return pos+1; |
| 4306 | } |
| 4307 | } |
| 4308 | } |
| 4309 | tokenPos--; |
| 4310 | } |
| 4311 | |
| 4312 | return 0; |
| 4313 | } |
| 4314 | |
| 4315 | private final int reAddWindowLocked(int index, WindowState win) { |
| 4316 | final int NCW = win.mChildWindows.size(); |
| 4317 | boolean added = false; |
| 4318 | for (int j=0; j<NCW; j++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4319 | WindowState cwin = win.mChildWindows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4320 | if (!added && cwin.mSubLayer >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4321 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4322 | + index + ": " + cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4323 | mWindows.add(index, win); |
| 4324 | index++; |
| 4325 | added = true; |
| 4326 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4327 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4328 | + index + ": " + cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4329 | mWindows.add(index, cwin); |
| 4330 | index++; |
| 4331 | } |
| 4332 | if (!added) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4333 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4334 | + index + ": " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4335 | mWindows.add(index, win); |
| 4336 | index++; |
| 4337 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4338 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4339 | return index; |
| 4340 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4341 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4342 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 4343 | final int NW = token.windows.size(); |
| 4344 | for (int i=0; i<NW; i++) { |
| 4345 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 4346 | } |
| 4347 | return index; |
| 4348 | } |
| 4349 | |
| 4350 | public void moveAppToken(int index, IBinder token) { |
| 4351 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4352 | "moveAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4353 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4354 | } |
| 4355 | |
| 4356 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4357 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4358 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 4359 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4360 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4361 | 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] | 4362 | + token + " (" + wtoken + ")"); |
| 4363 | return; |
| 4364 | } |
| 4365 | mAppTokens.add(index, wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4366 | 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] | 4367 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4368 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4369 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4370 | 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] | 4371 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4372 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4373 | 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] | 4374 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4375 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4376 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4377 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4378 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4379 | mLayoutNeeded = true; |
| 4380 | performLayoutAndPlaceSurfacesLocked(); |
| 4381 | } |
| 4382 | Binder.restoreCallingIdentity(origId); |
| 4383 | } |
| 4384 | } |
| 4385 | |
| 4386 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 4387 | // XXX This should be done more efficiently! |
| 4388 | // (take advantage of the fact that both lists should be |
| 4389 | // ordered in the same way.) |
| 4390 | int N = tokens.size(); |
| 4391 | for (int i=0; i<N; i++) { |
| 4392 | IBinder token = tokens.get(i); |
| 4393 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4394 | if (!mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4395 | 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] | 4396 | + token + " (" + wtoken + ")"); |
| 4397 | i--; |
| 4398 | N--; |
| 4399 | } |
| 4400 | } |
| 4401 | } |
| 4402 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4403 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 4404 | boolean updateFocusAndLayout) { |
| 4405 | // First remove all of the windows from the list. |
| 4406 | tmpRemoveAppWindowsLocked(wtoken); |
| 4407 | |
| 4408 | // Where to start adding? |
| 4409 | int pos = findWindowOffsetLocked(tokenPos); |
| 4410 | |
| 4411 | // And now add them back at the correct place. |
| 4412 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 4413 | |
| 4414 | if (updateFocusAndLayout) { |
| 4415 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4416 | assignLayersLocked(); |
| 4417 | } |
| 4418 | mLayoutNeeded = true; |
| 4419 | performLayoutAndPlaceSurfacesLocked(); |
| 4420 | } |
| 4421 | } |
| 4422 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4423 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 4424 | // First remove all of the windows from the list. |
| 4425 | final int N = tokens.size(); |
| 4426 | int i; |
| 4427 | for (i=0; i<N; i++) { |
| 4428 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4429 | if (token != null) { |
| 4430 | tmpRemoveAppWindowsLocked(token); |
| 4431 | } |
| 4432 | } |
| 4433 | |
| 4434 | // Where to start adding? |
| 4435 | int pos = findWindowOffsetLocked(tokenPos); |
| 4436 | |
| 4437 | // And now add them back at the correct place. |
| 4438 | for (i=0; i<N; i++) { |
| 4439 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4440 | if (token != null) { |
| 4441 | pos = reAddAppWindowsLocked(pos, token); |
| 4442 | } |
| 4443 | } |
| 4444 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4445 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4446 | assignLayersLocked(); |
| 4447 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4448 | mLayoutNeeded = true; |
| 4449 | performLayoutAndPlaceSurfacesLocked(); |
| 4450 | |
| 4451 | //dump(); |
| 4452 | } |
| 4453 | |
| 4454 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4455 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4456 | "moveAppTokensToTop()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4457 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4458 | } |
| 4459 | |
| 4460 | final long origId = Binder.clearCallingIdentity(); |
| 4461 | synchronized(mWindowMap) { |
| 4462 | removeAppTokensLocked(tokens); |
| 4463 | final int N = tokens.size(); |
| 4464 | for (int i=0; i<N; i++) { |
| 4465 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4466 | if (wt != null) { |
| 4467 | mAppTokens.add(wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4468 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4469 | mToTopApps.remove(wt); |
| 4470 | mToBottomApps.remove(wt); |
| 4471 | mToTopApps.add(wt); |
| 4472 | wt.sendingToBottom = false; |
| 4473 | wt.sendingToTop = true; |
| 4474 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4475 | } |
| 4476 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4477 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4478 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4479 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4480 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4481 | } |
| 4482 | Binder.restoreCallingIdentity(origId); |
| 4483 | } |
| 4484 | |
| 4485 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4486 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4487 | "moveAppTokensToBottom()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4488 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4489 | } |
| 4490 | |
| 4491 | final long origId = Binder.clearCallingIdentity(); |
| 4492 | synchronized(mWindowMap) { |
| 4493 | removeAppTokensLocked(tokens); |
| 4494 | final int N = tokens.size(); |
| 4495 | int pos = 0; |
| 4496 | for (int i=0; i<N; i++) { |
| 4497 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4498 | if (wt != null) { |
| 4499 | mAppTokens.add(pos, wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4500 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4501 | mToTopApps.remove(wt); |
| 4502 | mToBottomApps.remove(wt); |
| 4503 | mToBottomApps.add(i, wt); |
| 4504 | wt.sendingToTop = false; |
| 4505 | wt.sendingToBottom = true; |
| 4506 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4507 | pos++; |
| 4508 | } |
| 4509 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4510 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4511 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4512 | moveAppWindowsLocked(tokens, 0); |
| 4513 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4514 | } |
| 4515 | Binder.restoreCallingIdentity(origId); |
| 4516 | } |
| 4517 | |
| 4518 | // ------------------------------------------------------------- |
| 4519 | // Misc IWindowSession methods |
| 4520 | // ------------------------------------------------------------- |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4521 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4522 | private boolean shouldAllowDisableKeyguard() |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4523 | { |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4524 | // We fail safe and prevent disabling keyguard in the unlikely event this gets |
| 4525 | // called before DevicePolicyManagerService has started. |
| 4526 | if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { |
| 4527 | DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( |
| 4528 | Context.DEVICE_POLICY_SERVICE); |
| 4529 | if (dpm != null) { |
| 4530 | mAllowDisableKeyguard = dpm.getPasswordQuality(null) |
| 4531 | == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? |
| 4532 | ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; |
| 4533 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4534 | } |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4535 | return mAllowDisableKeyguard == ALLOW_DISABLE_YES; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4536 | } |
| 4537 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4538 | public void disableKeyguard(IBinder token, String tag) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4539 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4540 | != PackageManager.PERMISSION_GRANTED) { |
| 4541 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4542 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4543 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4544 | synchronized (mKeyguardTokenWatcher) { |
| 4545 | mKeyguardTokenWatcher.acquire(token, tag); |
Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4546 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4547 | } |
| 4548 | |
| 4549 | public void reenableKeyguard(IBinder token) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4550 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4551 | != PackageManager.PERMISSION_GRANTED) { |
| 4552 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4553 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4554 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4555 | synchronized (mKeyguardTokenWatcher) { |
| 4556 | mKeyguardTokenWatcher.release(token); |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4557 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4558 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4559 | // If we are the last one to reenable the keyguard wait until |
| 4560 | // we have actually finished reenabling until returning. |
| 4561 | // It is possible that reenableKeyguard() can be called before |
| 4562 | // the previous disableKeyguard() is handled, in which case |
| 4563 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4564 | // be called. In that case mKeyguardDisabled will be false here |
| 4565 | // and we have nothing to wait for. |
| 4566 | while (mKeyguardDisabled) { |
| 4567 | try { |
| 4568 | mKeyguardTokenWatcher.wait(); |
| 4569 | } catch (InterruptedException e) { |
| 4570 | Thread.currentThread().interrupt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4571 | } |
| 4572 | } |
| 4573 | } |
| 4574 | } |
| 4575 | } |
| 4576 | |
| 4577 | /** |
| 4578 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4579 | */ |
| 4580 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4581 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4582 | != PackageManager.PERMISSION_GRANTED) { |
| 4583 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4584 | } |
| 4585 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4586 | public void onKeyguardExitResult(boolean success) { |
| 4587 | try { |
| 4588 | callback.onKeyguardExitResult(success); |
| 4589 | } catch (RemoteException e) { |
| 4590 | // Client has died, we don't care. |
| 4591 | } |
| 4592 | } |
| 4593 | }); |
| 4594 | } |
| 4595 | |
| 4596 | public boolean inKeyguardRestrictedInputMode() { |
| 4597 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4598 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4599 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4600 | public void closeSystemDialogs(String reason) { |
| 4601 | synchronized(mWindowMap) { |
| 4602 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4603 | WindowState w = mWindows.get(i); |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4604 | if (w.mSurface != null) { |
| 4605 | try { |
| 4606 | w.mClient.closeSystemDialogs(reason); |
| 4607 | } catch (RemoteException e) { |
| 4608 | } |
| 4609 | } |
| 4610 | } |
| 4611 | } |
| 4612 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4613 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4614 | static float fixScale(float scale) { |
| 4615 | if (scale < 0) scale = 0; |
| 4616 | else if (scale > 20) scale = 20; |
| 4617 | return Math.abs(scale); |
| 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 void setAnimationScale(int which, float scale) { |
| 4621 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4622 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4623 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4624 | } |
| 4625 | |
| 4626 | if (scale < 0) scale = 0; |
| 4627 | else if (scale > 20) scale = 20; |
| 4628 | scale = Math.abs(scale); |
| 4629 | switch (which) { |
| 4630 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4631 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4632 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4633 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4634 | // Persist setting |
| 4635 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4636 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4637 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4638 | public void setAnimationScales(float[] scales) { |
| 4639 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4640 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4641 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4642 | } |
| 4643 | |
| 4644 | if (scales != null) { |
| 4645 | if (scales.length >= 1) { |
| 4646 | mWindowAnimationScale = fixScale(scales[0]); |
| 4647 | } |
| 4648 | if (scales.length >= 2) { |
| 4649 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4650 | } |
| 4651 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4652 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4653 | // Persist setting |
| 4654 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4655 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4656 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4657 | public float getAnimationScale(int which) { |
| 4658 | switch (which) { |
| 4659 | case 0: return mWindowAnimationScale; |
| 4660 | case 1: return mTransitionAnimationScale; |
| 4661 | } |
| 4662 | return 0; |
| 4663 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4664 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4665 | public float[] getAnimationScales() { |
| 4666 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4667 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4668 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4669 | public int getSwitchState(int sw) { |
| 4670 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4671 | "getSwitchState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4672 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4673 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4674 | return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4675 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4676 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4677 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4678 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4679 | "getSwitchStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4680 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4681 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4682 | return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4683 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4684 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4685 | public int getScancodeState(int sw) { |
| 4686 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4687 | "getScancodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4688 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4689 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4690 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4691 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4692 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4693 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4694 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4695 | "getScancodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4696 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4697 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4698 | return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4699 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4700 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4701 | public int getTrackballScancodeState(int sw) { |
| 4702 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4703 | "getTrackballScancodeState()")) { |
| 4704 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4705 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4706 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4707 | } |
| 4708 | |
| 4709 | public int getDPadScancodeState(int sw) { |
| 4710 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4711 | "getDPadScancodeState()")) { |
| 4712 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4713 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4714 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4715 | } |
| 4716 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4717 | public int getKeycodeState(int sw) { |
| 4718 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4719 | "getKeycodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4720 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4721 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4722 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4723 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4724 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4725 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4726 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4727 | "getKeycodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4728 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4729 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4730 | return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4731 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4732 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4733 | public int getTrackballKeycodeState(int sw) { |
| 4734 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4735 | "getTrackballKeycodeState()")) { |
| 4736 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4737 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4738 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4739 | } |
| 4740 | |
| 4741 | public int getDPadKeycodeState(int sw) { |
| 4742 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4743 | "getDPadKeycodeState()")) { |
| 4744 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4745 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4746 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4747 | } |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4748 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4749 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4750 | return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4751 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4752 | |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4753 | public InputChannel monitorInput(String inputChannelName) { |
| 4754 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4755 | "monitorInput()")) { |
| 4756 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4757 | } |
| 4758 | return mInputManager.monitorInput(inputChannelName); |
| 4759 | } |
| 4760 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 4761 | public InputDevice getInputDevice(int deviceId) { |
| 4762 | return mInputManager.getInputDevice(deviceId); |
| 4763 | } |
| 4764 | |
| 4765 | public int[] getInputDeviceIds() { |
| 4766 | return mInputManager.getInputDeviceIds(); |
| 4767 | } |
| 4768 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4769 | public void enableScreenAfterBoot() { |
| 4770 | synchronized(mWindowMap) { |
| 4771 | if (mSystemBooted) { |
| 4772 | return; |
| 4773 | } |
| 4774 | mSystemBooted = true; |
| 4775 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4776 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4777 | performEnableScreen(); |
| 4778 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4779 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4780 | public void enableScreenIfNeededLocked() { |
| 4781 | if (mDisplayEnabled) { |
| 4782 | return; |
| 4783 | } |
| 4784 | if (!mSystemBooted) { |
| 4785 | return; |
| 4786 | } |
| 4787 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4788 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4789 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4790 | public void performEnableScreen() { |
| 4791 | synchronized(mWindowMap) { |
| 4792 | if (mDisplayEnabled) { |
| 4793 | return; |
| 4794 | } |
| 4795 | if (!mSystemBooted) { |
| 4796 | return; |
| 4797 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4798 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4799 | // Don't enable the screen until all existing windows |
| 4800 | // have been drawn. |
| 4801 | final int N = mWindows.size(); |
| 4802 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4803 | WindowState w = mWindows.get(i); |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 4804 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4805 | return; |
| 4806 | } |
| 4807 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4808 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4809 | mDisplayEnabled = true; |
| 4810 | if (false) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4811 | Slog.i(TAG, "ENABLING SCREEN!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4812 | StringWriter sw = new StringWriter(); |
| 4813 | PrintWriter pw = new PrintWriter(sw); |
| 4814 | this.dump(null, pw, null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4815 | Slog.i(TAG, sw.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4816 | } |
| 4817 | try { |
| 4818 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4819 | if (surfaceFlinger != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4820 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4821 | Parcel data = Parcel.obtain(); |
| 4822 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4823 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4824 | data, null, 0); |
| 4825 | data.recycle(); |
| 4826 | } |
| 4827 | } catch (RemoteException ex) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4828 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4829 | } |
| 4830 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4831 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4832 | mPolicy.enableScreenAfterBoot(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4833 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4834 | // Make sure the last requested orientation has been applied. |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4835 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4836 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4837 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4838 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4839 | public void setInTouchMode(boolean mode) { |
| 4840 | synchronized(mWindowMap) { |
| 4841 | mInTouchMode = mode; |
| 4842 | } |
| 4843 | } |
| 4844 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame^] | 4845 | public void freezeRotation() { |
| 4846 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| 4847 | "setRotation()")) { |
| 4848 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 4849 | } |
| 4850 | |
| 4851 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation); |
| 4852 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0); |
| 4853 | } |
| 4854 | |
| 4855 | public void thawRotation() { |
| 4856 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| 4857 | "setRotation()")) { |
| 4858 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 4859 | } |
| 4860 | |
| 4861 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0); |
| 4862 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0); |
| 4863 | } |
| 4864 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4865 | public void setRotation(int rotation, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4866 | boolean alwaysSendConfiguration, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4867 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4868 | "setRotation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4869 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4870 | } |
| 4871 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4872 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4873 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4874 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4875 | public void setRotationUnchecked(int rotation, |
| 4876 | boolean alwaysSendConfiguration, int animFlags) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4877 | if(DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4878 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4879 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4880 | long origId = Binder.clearCallingIdentity(); |
| 4881 | boolean changed; |
| 4882 | synchronized(mWindowMap) { |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4883 | changed = setRotationUncheckedLocked(rotation, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4884 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4885 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4886 | if (changed || alwaysSendConfiguration) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4887 | sendNewConfiguration(); |
| 4888 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4889 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4890 | Binder.restoreCallingIdentity(origId); |
| 4891 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4892 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4893 | /** |
| 4894 | * Apply a new rotation to the screen, respecting the requests of |
| 4895 | * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply |
| 4896 | * re-evaluate the desired rotation. |
| 4897 | * |
| 4898 | * Returns null if the rotation has been changed. In this case YOU |
| 4899 | * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN. |
| 4900 | */ |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4901 | public boolean setRotationUncheckedLocked(int rotation, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4902 | boolean changed; |
| 4903 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| 4904 | rotation = mRequestedRotation; |
| 4905 | } else { |
| 4906 | mRequestedRotation = rotation; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4907 | mLastRotationFlags = animFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4908 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4909 | 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] | 4910 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4911 | mRotation, mDisplayEnabled); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4912 | 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] | 4913 | changed = mDisplayEnabled && mRotation != rotation; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4914 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4915 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4916 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4917 | "Rotation changed to " + rotation |
| 4918 | + " from " + mRotation |
| 4919 | + " (forceApp=" + mForcedAppOrientation |
| 4920 | + ", req=" + mRequestedRotation + ")"); |
| 4921 | mRotation = rotation; |
| 4922 | mWindowsFreezingScreen = true; |
| 4923 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 4924 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 4925 | 2000); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4926 | mWaitingForConfig = true; |
| 4927 | mLayoutNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4928 | startFreezingDisplayLocked(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4929 | Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4930 | mInputManager.setDisplayOrientation(0, rotation); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4931 | if (mDisplayEnabled) { |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4932 | Surface.setOrientation(0, rotation, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4933 | } |
| 4934 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4935 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4936 | if (w.mSurface != null) { |
| 4937 | w.mOrientationChanging = true; |
| 4938 | } |
| 4939 | } |
| 4940 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 4941 | try { |
| 4942 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 4943 | } catch (RemoteException e) { |
| 4944 | } |
| 4945 | } |
| 4946 | } //end if changed |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4947 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4948 | return changed; |
| 4949 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4950 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4951 | public int getRotation() { |
| 4952 | return mRotation; |
| 4953 | } |
| 4954 | |
| 4955 | public int watchRotation(IRotationWatcher watcher) { |
| 4956 | final IBinder watcherBinder = watcher.asBinder(); |
| 4957 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 4958 | public void binderDied() { |
| 4959 | synchronized (mWindowMap) { |
| 4960 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 4961 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 4962 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 4963 | if (removed != null) { |
| 4964 | removed.asBinder().unlinkToDeath(this, 0); |
| 4965 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4966 | i--; |
| 4967 | } |
| 4968 | } |
| 4969 | } |
| 4970 | } |
| 4971 | }; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4972 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4973 | synchronized (mWindowMap) { |
| 4974 | try { |
| 4975 | watcher.asBinder().linkToDeath(dr, 0); |
| 4976 | mRotationWatchers.add(watcher); |
| 4977 | } catch (RemoteException e) { |
| 4978 | // Client died, no cleanup needed. |
| 4979 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4980 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4981 | return mRotation; |
| 4982 | } |
| 4983 | } |
| 4984 | |
| 4985 | /** |
| 4986 | * Starts the view server on the specified port. |
| 4987 | * |
| 4988 | * @param port The port to listener to. |
| 4989 | * |
| 4990 | * @return True if the server was successfully started, false otherwise. |
| 4991 | * |
| 4992 | * @see com.android.server.ViewServer |
| 4993 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 4994 | */ |
| 4995 | public boolean startViewServer(int port) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4996 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4997 | return false; |
| 4998 | } |
| 4999 | |
| 5000 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 5001 | return false; |
| 5002 | } |
| 5003 | |
| 5004 | if (port < 1024) { |
| 5005 | return false; |
| 5006 | } |
| 5007 | |
| 5008 | if (mViewServer != null) { |
| 5009 | if (!mViewServer.isRunning()) { |
| 5010 | try { |
| 5011 | return mViewServer.start(); |
| 5012 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5013 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5014 | } |
| 5015 | } |
| 5016 | return false; |
| 5017 | } |
| 5018 | |
| 5019 | try { |
| 5020 | mViewServer = new ViewServer(this, port); |
| 5021 | return mViewServer.start(); |
| 5022 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5023 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5024 | } |
| 5025 | return false; |
| 5026 | } |
| 5027 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5028 | private boolean isSystemSecure() { |
| 5029 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 5030 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 5031 | } |
| 5032 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5033 | /** |
| 5034 | * Stops the view server if it exists. |
| 5035 | * |
| 5036 | * @return True if the server stopped, false if it wasn't started or |
| 5037 | * couldn't be stopped. |
| 5038 | * |
| 5039 | * @see com.android.server.ViewServer |
| 5040 | */ |
| 5041 | public boolean stopViewServer() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5042 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5043 | return false; |
| 5044 | } |
| 5045 | |
| 5046 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 5047 | return false; |
| 5048 | } |
| 5049 | |
| 5050 | if (mViewServer != null) { |
| 5051 | return mViewServer.stop(); |
| 5052 | } |
| 5053 | return false; |
| 5054 | } |
| 5055 | |
| 5056 | /** |
| 5057 | * Indicates whether the view server is running. |
| 5058 | * |
| 5059 | * @return True if the server is running, false otherwise. |
| 5060 | * |
| 5061 | * @see com.android.server.ViewServer |
| 5062 | */ |
| 5063 | public boolean isViewServerRunning() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5064 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5065 | return false; |
| 5066 | } |
| 5067 | |
| 5068 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 5069 | return false; |
| 5070 | } |
| 5071 | |
| 5072 | return mViewServer != null && mViewServer.isRunning(); |
| 5073 | } |
| 5074 | |
| 5075 | /** |
| 5076 | * Lists all availble windows in the system. The listing is written in the |
| 5077 | * specified Socket's output stream with the following syntax: |
| 5078 | * windowHashCodeInHexadecimal windowName |
| 5079 | * Each line of the ouput represents a different window. |
| 5080 | * |
| 5081 | * @param client The remote client to send the listing to. |
| 5082 | * @return False if an error occured, true otherwise. |
| 5083 | */ |
| 5084 | boolean viewServerListWindows(Socket client) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5085 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5086 | return false; |
| 5087 | } |
| 5088 | |
| 5089 | boolean result = true; |
| 5090 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5091 | WindowState[] windows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5092 | synchronized (mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5093 | //noinspection unchecked |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5094 | windows = mWindows.toArray(new WindowState[mWindows.size()]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5095 | } |
| 5096 | |
| 5097 | BufferedWriter out = null; |
| 5098 | |
| 5099 | // Any uncaught exception will crash the system process |
| 5100 | try { |
| 5101 | OutputStream clientStream = client.getOutputStream(); |
| 5102 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5103 | |
| 5104 | final int count = windows.length; |
| 5105 | for (int i = 0; i < count; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5106 | final WindowState w = windows[i]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5107 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 5108 | out.write(' '); |
| 5109 | out.append(w.mAttrs.getTitle()); |
| 5110 | out.write('\n'); |
| 5111 | } |
| 5112 | |
| 5113 | out.write("DONE.\n"); |
| 5114 | out.flush(); |
| 5115 | } catch (Exception e) { |
| 5116 | result = false; |
| 5117 | } finally { |
| 5118 | if (out != null) { |
| 5119 | try { |
| 5120 | out.close(); |
| 5121 | } catch (IOException e) { |
| 5122 | result = false; |
| 5123 | } |
| 5124 | } |
| 5125 | } |
| 5126 | |
| 5127 | return result; |
| 5128 | } |
| 5129 | |
| 5130 | /** |
Konstantin Lopyrev | f962476 | 2010-07-14 17:02:37 -0700 | [diff] [blame] | 5131 | * Returns the focused window in the following format: |
| 5132 | * windowHashCodeInHexadecimal windowName |
| 5133 | * |
| 5134 | * @param client The remote client to send the listing to. |
| 5135 | * @return False if an error occurred, true otherwise. |
| 5136 | */ |
| 5137 | boolean viewServerGetFocusedWindow(Socket client) { |
| 5138 | if (isSystemSecure()) { |
| 5139 | return false; |
| 5140 | } |
| 5141 | |
| 5142 | boolean result = true; |
| 5143 | |
| 5144 | WindowState focusedWindow = getFocusedWindow(); |
| 5145 | |
| 5146 | BufferedWriter out = null; |
| 5147 | |
| 5148 | // Any uncaught exception will crash the system process |
| 5149 | try { |
| 5150 | OutputStream clientStream = client.getOutputStream(); |
| 5151 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5152 | |
| 5153 | if(focusedWindow != null) { |
| 5154 | out.write(Integer.toHexString(System.identityHashCode(focusedWindow))); |
| 5155 | out.write(' '); |
| 5156 | out.append(focusedWindow.mAttrs.getTitle()); |
| 5157 | } |
| 5158 | out.write('\n'); |
| 5159 | out.flush(); |
| 5160 | } catch (Exception e) { |
| 5161 | result = false; |
| 5162 | } finally { |
| 5163 | if (out != null) { |
| 5164 | try { |
| 5165 | out.close(); |
| 5166 | } catch (IOException e) { |
| 5167 | result = false; |
| 5168 | } |
| 5169 | } |
| 5170 | } |
| 5171 | |
| 5172 | return result; |
| 5173 | } |
| 5174 | |
| 5175 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5176 | * Sends a command to a target window. The result of the command, if any, will be |
| 5177 | * written in the output stream of the specified socket. |
| 5178 | * |
| 5179 | * The parameters must follow this syntax: |
| 5180 | * windowHashcode extra |
| 5181 | * |
| 5182 | * Where XX is the length in characeters of the windowTitle. |
| 5183 | * |
| 5184 | * The first parameter is the target window. The window with the specified hashcode |
| 5185 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 5186 | * will be delivered to the target window and as parameters to the command itself. |
| 5187 | * |
| 5188 | * @param client The remote client to sent the result, if any, to. |
| 5189 | * @param command The command to execute. |
| 5190 | * @param parameters The command parameters. |
| 5191 | * |
| 5192 | * @return True if the command was successfully delivered, false otherwise. This does |
| 5193 | * not indicate whether the command itself was successful. |
| 5194 | */ |
| 5195 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5196 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5197 | return false; |
| 5198 | } |
| 5199 | |
| 5200 | boolean success = true; |
| 5201 | Parcel data = null; |
| 5202 | Parcel reply = null; |
| 5203 | |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5204 | BufferedWriter out = null; |
| 5205 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5206 | // Any uncaught exception will crash the system process |
| 5207 | try { |
| 5208 | // Find the hashcode of the window |
| 5209 | int index = parameters.indexOf(' '); |
| 5210 | if (index == -1) { |
| 5211 | index = parameters.length(); |
| 5212 | } |
| 5213 | final String code = parameters.substring(0, index); |
Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 5214 | int hashCode = (int) Long.parseLong(code, 16); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5215 | |
| 5216 | // Extract the command's parameter after the window description |
| 5217 | if (index < parameters.length()) { |
| 5218 | parameters = parameters.substring(index + 1); |
| 5219 | } else { |
| 5220 | parameters = ""; |
| 5221 | } |
| 5222 | |
| 5223 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 5224 | if (window == null) { |
| 5225 | return false; |
| 5226 | } |
| 5227 | |
| 5228 | data = Parcel.obtain(); |
| 5229 | data.writeInterfaceToken("android.view.IWindow"); |
| 5230 | data.writeString(command); |
| 5231 | data.writeString(parameters); |
| 5232 | data.writeInt(1); |
| 5233 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 5234 | |
| 5235 | reply = Parcel.obtain(); |
| 5236 | |
| 5237 | final IBinder binder = window.mClient.asBinder(); |
| 5238 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 5239 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 5240 | |
| 5241 | reply.readException(); |
| 5242 | |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5243 | if (!client.isOutputShutdown()) { |
| 5244 | out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream())); |
| 5245 | out.write("DONE\n"); |
| 5246 | out.flush(); |
| 5247 | } |
| 5248 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5249 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5250 | 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] | 5251 | success = false; |
| 5252 | } finally { |
| 5253 | if (data != null) { |
| 5254 | data.recycle(); |
| 5255 | } |
| 5256 | if (reply != null) { |
| 5257 | reply.recycle(); |
| 5258 | } |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5259 | if (out != null) { |
| 5260 | try { |
| 5261 | out.close(); |
| 5262 | } catch (IOException e) { |
| 5263 | |
| 5264 | } |
| 5265 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5266 | } |
| 5267 | |
| 5268 | return success; |
| 5269 | } |
| 5270 | |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 5271 | public void addWindowChangeListener(WindowChangeListener listener) { |
| 5272 | synchronized(mWindowMap) { |
| 5273 | mWindowChangeListeners.add(listener); |
| 5274 | } |
| 5275 | } |
| 5276 | |
| 5277 | public void removeWindowChangeListener(WindowChangeListener listener) { |
| 5278 | synchronized(mWindowMap) { |
| 5279 | mWindowChangeListeners.remove(listener); |
| 5280 | } |
| 5281 | } |
| 5282 | |
| 5283 | private void notifyWindowsChanged() { |
| 5284 | WindowChangeListener[] windowChangeListeners; |
| 5285 | synchronized(mWindowMap) { |
| 5286 | if(mWindowChangeListeners.isEmpty()) { |
| 5287 | return; |
| 5288 | } |
| 5289 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5290 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5291 | } |
| 5292 | int N = windowChangeListeners.length; |
| 5293 | for(int i = 0; i < N; i++) { |
| 5294 | windowChangeListeners[i].windowsChanged(); |
| 5295 | } |
| 5296 | } |
| 5297 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 5298 | private void notifyFocusChanged() { |
| 5299 | WindowChangeListener[] windowChangeListeners; |
| 5300 | synchronized(mWindowMap) { |
| 5301 | if(mWindowChangeListeners.isEmpty()) { |
| 5302 | return; |
| 5303 | } |
| 5304 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5305 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5306 | } |
| 5307 | int N = windowChangeListeners.length; |
| 5308 | for(int i = 0; i < N; i++) { |
| 5309 | windowChangeListeners[i].focusChanged(); |
| 5310 | } |
| 5311 | } |
| 5312 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5313 | private WindowState findWindow(int hashCode) { |
| 5314 | if (hashCode == -1) { |
| 5315 | return getFocusedWindow(); |
| 5316 | } |
| 5317 | |
| 5318 | synchronized (mWindowMap) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5319 | final ArrayList<WindowState> windows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5320 | final int count = windows.size(); |
| 5321 | |
| 5322 | for (int i = 0; i < count; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5323 | WindowState w = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5324 | if (System.identityHashCode(w) == hashCode) { |
| 5325 | return w; |
| 5326 | } |
| 5327 | } |
| 5328 | } |
| 5329 | |
| 5330 | return null; |
| 5331 | } |
| 5332 | |
| 5333 | /* |
| 5334 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 5335 | * that to config-changed listeners if appropriate. |
| 5336 | */ |
| 5337 | void sendNewConfiguration() { |
| 5338 | try { |
| 5339 | mActivityManager.updateConfiguration(null); |
| 5340 | } catch (RemoteException e) { |
| 5341 | } |
| 5342 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5343 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5344 | public Configuration computeNewConfiguration() { |
| 5345 | synchronized (mWindowMap) { |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5346 | return computeNewConfigurationLocked(); |
| 5347 | } |
| 5348 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5349 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5350 | Configuration computeNewConfigurationLocked() { |
| 5351 | Configuration config = new Configuration(); |
| 5352 | if (!computeNewConfigurationLocked(config)) { |
| 5353 | return null; |
| 5354 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5355 | return config; |
| 5356 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5357 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5358 | boolean computeNewConfigurationLocked(Configuration config) { |
| 5359 | if (mDisplay == null) { |
| 5360 | return false; |
| 5361 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5362 | |
| 5363 | mInputManager.getInputConfiguration(config); |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 5364 | |
| 5365 | // Use the effective "visual" dimensions based on current rotation |
| 5366 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 5367 | || mRotation == Surface.ROTATION_270); |
| 5368 | final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; |
| 5369 | final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; |
| 5370 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5371 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 5372 | if (dw < dh) { |
| 5373 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 5374 | } else if (dw > dh) { |
| 5375 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 5376 | } |
| 5377 | config.orientation = orientation; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5378 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5379 | DisplayMetrics dm = new DisplayMetrics(); |
| 5380 | mDisplay.getMetrics(dm); |
| 5381 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 5382 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5383 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5384 | // Note we only do this once because at this point we don't |
| 5385 | // expect the screen to change in this way at runtime, and want |
| 5386 | // to avoid all of this computation for every config change. |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5387 | int longSize = dw; |
| 5388 | int shortSize = dh; |
| 5389 | if (longSize < shortSize) { |
| 5390 | int tmp = longSize; |
| 5391 | longSize = shortSize; |
| 5392 | shortSize = tmp; |
| 5393 | } |
| 5394 | longSize = (int)(longSize/dm.density); |
| 5395 | shortSize = (int)(shortSize/dm.density); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5396 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5397 | // These semi-magic numbers define our compatibility modes for |
| 5398 | // applications with different screens. Don't change unless you |
| 5399 | // make sure to test lots and lots of apps! |
| 5400 | if (longSize < 470) { |
| 5401 | // This is shorter than an HVGA normal density screen (which |
| 5402 | // is 480 pixels on its long side). |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5403 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 5404 | | Configuration.SCREENLAYOUT_LONG_NO; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5405 | } else { |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 5406 | // What size is this screen screen? |
| 5407 | if (longSize >= 800 && shortSize >= 600) { |
| 5408 | // SVGA or larger screens at medium density are the point |
| 5409 | // at which we consider it to be an extra large screen. |
| 5410 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE; |
Dianne Hackborn | b51dc0f | 2010-10-21 15:34:47 -0700 | [diff] [blame] | 5411 | } else if (longSize >= 530 && shortSize >= 400) { |
| 5412 | // SVGA or larger screens at high density are the point |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5413 | // at which we consider it to be a large screen. |
| 5414 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 5415 | } else { |
| 5416 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5417 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5418 | // If this screen is wider than normal HVGA, or taller |
| 5419 | // than FWVGA, then for old apps we want to run in size |
| 5420 | // compatibility mode. |
| 5421 | if (shortSize > 321 || longSize > 570) { |
| 5422 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 5423 | } |
| 5424 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5425 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5426 | // Is this a long screen? |
| 5427 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 5428 | // Anything wider than WVGA (5:3) is considering to be long. |
| 5429 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 5430 | } else { |
| 5431 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 5432 | } |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5433 | } |
| 5434 | } |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5435 | config.screenLayout = mScreenLayout; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5436 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5437 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 5438 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 5439 | mPolicy.adjustConfigurationLw(config); |
| 5440 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5441 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5442 | |
| 5443 | // ------------------------------------------------------------- |
| 5444 | // Drag and drop |
| 5445 | // ------------------------------------------------------------- |
| 5446 | |
| 5447 | IBinder prepareDragSurface(IWindow window, SurfaceSession session, |
| 5448 | boolean localOnly, int width, int height, Surface outSurface) { |
| 5449 | if (DEBUG_DRAG) { |
| 5450 | Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height |
| 5451 | + " local=" + localOnly + " win=" + window |
| 5452 | + " asbinder=" + window.asBinder()); |
| 5453 | } |
| 5454 | |
| 5455 | final int callerPid = Binder.getCallingPid(); |
| 5456 | final long origId = Binder.clearCallingIdentity(); |
| 5457 | IBinder token = null; |
| 5458 | |
| 5459 | try { |
| 5460 | synchronized (mWindowMap) { |
| 5461 | try { |
| 5462 | // !!! TODO: fail if the given window does not currently have touch focus? |
| 5463 | |
| 5464 | if (mDragState == null) { |
| 5465 | Surface surface = new Surface(session, callerPid, "drag surface", 0, |
| 5466 | width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN); |
| 5467 | outSurface.copyFrom(surface); |
| 5468 | token = new Binder(); |
| 5469 | mDragState = new DragState(token, surface, localOnly); |
| 5470 | mDragState.mSurface = surface; |
| 5471 | mDragState.mLocalOnly = localOnly; |
| 5472 | token = mDragState.mToken = new Binder(); |
| 5473 | |
| 5474 | // 5 second timeout for this window to actually begin the drag |
| 5475 | mH.removeMessages(H.DRAG_START_TIMEOUT, window); |
| 5476 | Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, window.asBinder()); |
| 5477 | mH.sendMessageDelayed(msg, 5000); |
| 5478 | } else { |
| 5479 | Slog.w(TAG, "Drag already in progress"); |
| 5480 | } |
| 5481 | } catch (Surface.OutOfResourcesException e) { |
| 5482 | Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e); |
| 5483 | if (mDragState != null) { |
| 5484 | mDragState.reset(); |
| 5485 | mDragState = null; |
| 5486 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5487 | } |
| 5488 | } |
| 5489 | } finally { |
| 5490 | Binder.restoreCallingIdentity(origId); |
| 5491 | } |
| 5492 | |
| 5493 | return token; |
| 5494 | } |
| 5495 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5496 | // ------------------------------------------------------------- |
| 5497 | // Input Events and Focus Management |
| 5498 | // ------------------------------------------------------------- |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5499 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5500 | InputMonitor mInputMonitor = new InputMonitor(); |
| 5501 | |
| 5502 | /* Tracks the progress of input dispatch and ensures that input dispatch state |
| 5503 | * is kept in sync with changes in window focus, visibility, registration, and |
| 5504 | * other relevant Window Manager state transitions. */ |
| 5505 | final class InputMonitor { |
| 5506 | // Current window with input focus for keys and other non-touch events. May be null. |
| 5507 | private WindowState mInputFocus; |
| 5508 | |
| 5509 | // When true, prevents input dispatch from proceeding until set to false again. |
| 5510 | private boolean mInputDispatchFrozen; |
| 5511 | |
| 5512 | // When true, input dispatch proceeds normally. Otherwise all events are dropped. |
| 5513 | private boolean mInputDispatchEnabled = true; |
| 5514 | |
| 5515 | // Temporary list of windows information to provide to the input dispatcher. |
| 5516 | private InputWindowList mTempInputWindows = new InputWindowList(); |
| 5517 | |
| 5518 | // Temporary input application object to provide to the input dispatcher. |
| 5519 | private InputApplication mTempInputApplication = new InputApplication(); |
| 5520 | |
| 5521 | /* Notifies the window manager about a broken input channel. |
| 5522 | * |
| 5523 | * Called by the InputManager. |
| 5524 | */ |
| 5525 | public void notifyInputChannelBroken(InputChannel inputChannel) { |
| 5526 | synchronized (mWindowMap) { |
| 5527 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5528 | if (windowState == null) { |
| 5529 | return; // irrelevant |
| 5530 | } |
| 5531 | |
| 5532 | Slog.i(TAG, "WINDOW DIED " + windowState); |
| 5533 | removeWindowLocked(windowState.mSession, windowState); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5534 | } |
| 5535 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5536 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5537 | /* Notifies the window manager about an application that is not responding. |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5538 | * 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] | 5539 | * |
| 5540 | * Called by the InputManager. |
| 5541 | */ |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5542 | public long notifyANR(Object token, InputChannel inputChannel) { |
| 5543 | AppWindowToken appWindowToken = null; |
| 5544 | if (inputChannel != null) { |
| 5545 | synchronized (mWindowMap) { |
| 5546 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5547 | if (windowState != null) { |
| 5548 | Slog.i(TAG, "Input event dispatching timed out sending to " |
| 5549 | + windowState.mAttrs.getTitle()); |
| 5550 | appWindowToken = windowState.mAppToken; |
| 5551 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5552 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5553 | } |
| 5554 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5555 | if (appWindowToken == null && token != null) { |
| 5556 | appWindowToken = (AppWindowToken) token; |
| 5557 | Slog.i(TAG, "Input event dispatching timed out sending to application " |
| 5558 | + appWindowToken.stringName); |
| 5559 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5560 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5561 | if (appWindowToken != null && appWindowToken.appToken != null) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5562 | try { |
| 5563 | // Notify the activity manager about the timeout and let it decide whether |
| 5564 | // to abort dispatching or keep waiting. |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5565 | boolean abort = appWindowToken.appToken.keyDispatchingTimedOut(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5566 | if (! abort) { |
| 5567 | // The activity manager declined to abort dispatching. |
| 5568 | // Wait a bit longer and timeout again later. |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5569 | return appWindowToken.inputDispatchingTimeoutNanos; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5570 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5571 | } catch (RemoteException ex) { |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5572 | } |
| 5573 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5574 | return 0; // abort dispatching |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5575 | } |
| 5576 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5577 | private WindowState getWindowStateForInputChannel(InputChannel inputChannel) { |
| 5578 | synchronized (mWindowMap) { |
| 5579 | return getWindowStateForInputChannelLocked(inputChannel); |
| 5580 | } |
| 5581 | } |
| 5582 | |
| 5583 | private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) { |
| 5584 | int windowCount = mWindows.size(); |
| 5585 | for (int i = 0; i < windowCount; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5586 | WindowState windowState = mWindows.get(i); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5587 | if (windowState.mInputChannel == inputChannel) { |
| 5588 | return windowState; |
| 5589 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5590 | } |
| 5591 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5592 | return null; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5593 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5594 | |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 5595 | private void addDragInputWindowLw(InputWindowList windowList) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5596 | final InputWindow inputWindow = windowList.add(); |
| 5597 | inputWindow.inputChannel = mDragState.mServerChannel; |
| 5598 | inputWindow.name = "drag"; |
| 5599 | inputWindow.layoutParamsFlags = 0; |
| 5600 | inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG; |
| 5601 | inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 5602 | inputWindow.visible = true; |
| 5603 | inputWindow.canReceiveKeys = false; |
| 5604 | inputWindow.hasFocus = true; |
| 5605 | inputWindow.hasWallpaper = false; |
| 5606 | inputWindow.paused = false; |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 5607 | inputWindow.layer = mDragState.getDragLayerLw(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5608 | inputWindow.ownerPid = Process.myPid(); |
| 5609 | inputWindow.ownerUid = Process.myUid(); |
| 5610 | |
| 5611 | // The drag window covers the entire display |
| 5612 | inputWindow.frameLeft = 0; |
| 5613 | inputWindow.frameTop = 0; |
| 5614 | inputWindow.frameRight = mDisplay.getWidth(); |
| 5615 | inputWindow.frameBottom = mDisplay.getHeight(); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 5616 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5617 | inputWindow.visibleFrameLeft = inputWindow.frameLeft; |
| 5618 | inputWindow.visibleFrameTop = inputWindow.frameTop; |
| 5619 | inputWindow.visibleFrameRight = inputWindow.frameRight; |
| 5620 | inputWindow.visibleFrameBottom = inputWindow.frameBottom; |
| 5621 | |
| 5622 | inputWindow.touchableAreaLeft = inputWindow.frameLeft; |
| 5623 | inputWindow.touchableAreaTop = inputWindow.frameTop; |
| 5624 | inputWindow.touchableAreaRight = inputWindow.frameRight; |
| 5625 | inputWindow.touchableAreaBottom = inputWindow.frameBottom; |
| 5626 | } |
| 5627 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5628 | /* Updates the cached window information provided to the input dispatcher. */ |
| 5629 | public void updateInputWindowsLw() { |
| 5630 | // Populate the input window list with information about all of the windows that |
| 5631 | // could potentially receive input. |
| 5632 | // As an optimization, we could try to prune the list of windows but this turns |
| 5633 | // out to be difficult because only the native code knows for sure which window |
| 5634 | // currently has touch focus. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5635 | final ArrayList<WindowState> windows = mWindows; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5636 | |
| 5637 | // If there's a drag in flight, provide a pseudowindow to catch drag input |
| 5638 | final boolean inDrag = (mDragState != null); |
| 5639 | if (inDrag) { |
| 5640 | if (DEBUG_DRAG) { |
| 5641 | Log.d(TAG, "Inserting drag window"); |
| 5642 | } |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 5643 | addDragInputWindowLw(mTempInputWindows); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5644 | } |
| 5645 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5646 | final int N = windows.size(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5647 | for (int i = N - 1; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5648 | final WindowState child = windows.get(i); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5649 | if (child.mInputChannel == null || child.mRemoved) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5650 | // Skip this window because it cannot possibly receive input. |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5651 | continue; |
| 5652 | } |
| 5653 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5654 | final int flags = child.mAttrs.flags; |
| 5655 | final int type = child.mAttrs.type; |
| 5656 | |
| 5657 | final boolean hasFocus = (child == mInputFocus); |
| 5658 | final boolean isVisible = child.isVisibleLw(); |
| 5659 | final boolean hasWallpaper = (child == mWallpaperTarget) |
| 5660 | && (type != WindowManager.LayoutParams.TYPE_KEYGUARD); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5661 | |
| 5662 | // If there's a drag in progress and 'child' is a potential drop target, |
| 5663 | // make sure it's been told about the drag |
| 5664 | if (inDrag && isVisible) { |
| 5665 | mDragState.sendDragStartedIfNeededLw(child); |
| 5666 | } |
| 5667 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5668 | // Add a window to our list of input windows. |
| 5669 | final InputWindow inputWindow = mTempInputWindows.add(); |
| 5670 | inputWindow.inputChannel = child.mInputChannel; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5671 | inputWindow.name = child.toString(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5672 | inputWindow.layoutParamsFlags = flags; |
| 5673 | inputWindow.layoutParamsType = type; |
| 5674 | inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos(); |
| 5675 | inputWindow.visible = isVisible; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5676 | inputWindow.canReceiveKeys = child.canReceiveKeys(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5677 | inputWindow.hasFocus = hasFocus; |
| 5678 | inputWindow.hasWallpaper = hasWallpaper; |
| 5679 | inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5680 | inputWindow.layer = child.mLayer; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5681 | inputWindow.ownerPid = child.mSession.mPid; |
| 5682 | inputWindow.ownerUid = child.mSession.mUid; |
| 5683 | |
| 5684 | final Rect frame = child.mFrame; |
| 5685 | inputWindow.frameLeft = frame.left; |
| 5686 | inputWindow.frameTop = frame.top; |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5687 | inputWindow.frameRight = frame.right; |
| 5688 | inputWindow.frameBottom = frame.bottom; |
| 5689 | |
| 5690 | final Rect visibleFrame = child.mVisibleFrame; |
| 5691 | inputWindow.visibleFrameLeft = visibleFrame.left; |
| 5692 | inputWindow.visibleFrameTop = visibleFrame.top; |
| 5693 | inputWindow.visibleFrameRight = visibleFrame.right; |
| 5694 | inputWindow.visibleFrameBottom = visibleFrame.bottom; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5695 | |
| 5696 | switch (child.mTouchableInsets) { |
| 5697 | default: |
| 5698 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME: |
| 5699 | inputWindow.touchableAreaLeft = frame.left; |
| 5700 | inputWindow.touchableAreaTop = frame.top; |
| 5701 | inputWindow.touchableAreaRight = frame.right; |
| 5702 | inputWindow.touchableAreaBottom = frame.bottom; |
| 5703 | break; |
| 5704 | |
| 5705 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: { |
| 5706 | Rect inset = child.mGivenContentInsets; |
| 5707 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5708 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5709 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5710 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
| 5711 | break; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5712 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5713 | |
| 5714 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: { |
| 5715 | Rect inset = child.mGivenVisibleInsets; |
| 5716 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5717 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5718 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5719 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5720 | break; |
| 5721 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5722 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5723 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5724 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5725 | // Send windows to native code. |
| 5726 | mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray()); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5727 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5728 | // Clear the list in preparation for the next round. |
| 5729 | // Also avoids keeping InputChannel objects referenced unnecessarily. |
| 5730 | mTempInputWindows.clear(); |
| 5731 | } |
| 5732 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5733 | /* Notifies that the lid switch changed state. */ |
| 5734 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 5735 | mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen); |
| 5736 | } |
| 5737 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5738 | /* Provides an opportunity for the window manager policy to intercept early key |
| 5739 | * processing as soon as the key has been read from the device. */ |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5740 | public int interceptKeyBeforeQueueing(long whenNanos, int action, int flags, |
| 5741 | int keyCode, int scanCode, int policyFlags, boolean isScreenOn) { |
| 5742 | return mPolicy.interceptKeyBeforeQueueing(whenNanos, action, flags, |
| 5743 | keyCode, scanCode, policyFlags, isScreenOn); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5744 | } |
| 5745 | |
| 5746 | /* Provides an opportunity for the window manager policy to process a key before |
| 5747 | * ordinary dispatch. */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5748 | public boolean interceptKeyBeforeDispatching(InputChannel focus, |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5749 | int action, int flags, int keyCode, int scanCode, int metaState, int repeatCount, |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5750 | int policyFlags) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5751 | WindowState windowState = getWindowStateForInputChannel(focus); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5752 | return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags, |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5753 | keyCode, scanCode, metaState, repeatCount, policyFlags); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5754 | } |
| 5755 | |
| 5756 | /* Called when the current input focus changes. |
| 5757 | * Layer assignment is assumed to be complete by the time this is called. |
| 5758 | */ |
| 5759 | public void setInputFocusLw(WindowState newWindow) { |
| 5760 | if (DEBUG_INPUT) { |
| 5761 | Slog.d(TAG, "Input focus has changed to " + newWindow); |
| 5762 | } |
| 5763 | |
| 5764 | if (newWindow != mInputFocus) { |
| 5765 | if (newWindow != null && newWindow.canReceiveKeys()) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5766 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 5767 | // This is to protect against bugs if someone pauses dispatching but |
| 5768 | // forgets to resume. |
| 5769 | newWindow.mToken.paused = false; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5770 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5771 | |
| 5772 | mInputFocus = newWindow; |
| 5773 | updateInputWindowsLw(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5774 | } |
| 5775 | } |
| 5776 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5777 | public void setFocusedAppLw(AppWindowToken newApp) { |
| 5778 | // Focused app has changed. |
| 5779 | if (newApp == null) { |
| 5780 | mInputManager.setFocusedApplication(null); |
| 5781 | } else { |
| 5782 | mTempInputApplication.name = newApp.toString(); |
| 5783 | mTempInputApplication.dispatchingTimeoutNanos = |
| 5784 | newApp.inputDispatchingTimeoutNanos; |
| 5785 | mTempInputApplication.token = newApp; |
| 5786 | |
| 5787 | mInputManager.setFocusedApplication(mTempInputApplication); |
| 5788 | } |
| 5789 | } |
| 5790 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5791 | public void pauseDispatchingLw(WindowToken window) { |
| 5792 | if (! window.paused) { |
| 5793 | if (DEBUG_INPUT) { |
| 5794 | Slog.v(TAG, "Pausing WindowToken " + window); |
| 5795 | } |
| 5796 | |
| 5797 | window.paused = true; |
| 5798 | updateInputWindowsLw(); |
| 5799 | } |
| 5800 | } |
| 5801 | |
| 5802 | public void resumeDispatchingLw(WindowToken window) { |
| 5803 | if (window.paused) { |
| 5804 | if (DEBUG_INPUT) { |
| 5805 | Slog.v(TAG, "Resuming WindowToken " + window); |
| 5806 | } |
| 5807 | |
| 5808 | window.paused = false; |
| 5809 | updateInputWindowsLw(); |
| 5810 | } |
| 5811 | } |
| 5812 | |
| 5813 | public void freezeInputDispatchingLw() { |
| 5814 | if (! mInputDispatchFrozen) { |
| 5815 | if (DEBUG_INPUT) { |
| 5816 | Slog.v(TAG, "Freezing input dispatching"); |
| 5817 | } |
| 5818 | |
| 5819 | mInputDispatchFrozen = true; |
| 5820 | updateInputDispatchModeLw(); |
| 5821 | } |
| 5822 | } |
| 5823 | |
| 5824 | public void thawInputDispatchingLw() { |
| 5825 | if (mInputDispatchFrozen) { |
| 5826 | if (DEBUG_INPUT) { |
| 5827 | Slog.v(TAG, "Thawing input dispatching"); |
| 5828 | } |
| 5829 | |
| 5830 | mInputDispatchFrozen = false; |
| 5831 | updateInputDispatchModeLw(); |
| 5832 | } |
| 5833 | } |
| 5834 | |
| 5835 | public void setEventDispatchingLw(boolean enabled) { |
| 5836 | if (mInputDispatchEnabled != enabled) { |
| 5837 | if (DEBUG_INPUT) { |
| 5838 | Slog.v(TAG, "Setting event dispatching to " + enabled); |
| 5839 | } |
| 5840 | |
| 5841 | mInputDispatchEnabled = enabled; |
| 5842 | updateInputDispatchModeLw(); |
| 5843 | } |
| 5844 | } |
| 5845 | |
| 5846 | private void updateInputDispatchModeLw() { |
| 5847 | mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen); |
| 5848 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5849 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5850 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5851 | public void pauseKeyDispatching(IBinder _token) { |
| 5852 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5853 | "pauseKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5854 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5855 | } |
| 5856 | |
| 5857 | synchronized (mWindowMap) { |
| 5858 | WindowToken token = mTokenMap.get(_token); |
| 5859 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5860 | mInputMonitor.pauseDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5861 | } |
| 5862 | } |
| 5863 | } |
| 5864 | |
| 5865 | public void resumeKeyDispatching(IBinder _token) { |
| 5866 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5867 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5868 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5869 | } |
| 5870 | |
| 5871 | synchronized (mWindowMap) { |
| 5872 | WindowToken token = mTokenMap.get(_token); |
| 5873 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5874 | mInputMonitor.resumeDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5875 | } |
| 5876 | } |
| 5877 | } |
| 5878 | |
| 5879 | public void setEventDispatching(boolean enabled) { |
| 5880 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5881 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5882 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5883 | } |
| 5884 | |
| 5885 | synchronized (mWindowMap) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5886 | mInputMonitor.setEventDispatchingLw(enabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5887 | } |
| 5888 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5889 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5890 | /** |
| 5891 | * Injects a keystroke event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5892 | * Even when sync is false, this method may block while waiting for current |
| 5893 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5894 | * |
| 5895 | * @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] | 5896 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5897 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5898 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5899 | */ |
| 5900 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 5901 | long downTime = ev.getDownTime(); |
| 5902 | long eventTime = ev.getEventTime(); |
| 5903 | |
| 5904 | int action = ev.getAction(); |
| 5905 | int code = ev.getKeyCode(); |
| 5906 | int repeatCount = ev.getRepeatCount(); |
| 5907 | int metaState = ev.getMetaState(); |
| 5908 | int deviceId = ev.getDeviceId(); |
| 5909 | int scancode = ev.getScanCode(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5910 | int source = ev.getSource(); |
| 5911 | |
| 5912 | if (source == InputDevice.SOURCE_UNKNOWN) { |
| 5913 | source = InputDevice.SOURCE_KEYBOARD; |
| 5914 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5915 | |
| 5916 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 5917 | if (downTime == 0) downTime = eventTime; |
| 5918 | |
| 5919 | KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5920 | deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5921 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5922 | final int pid = Binder.getCallingPid(); |
| 5923 | final int uid = Binder.getCallingUid(); |
| 5924 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5925 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5926 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5927 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5928 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5929 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5930 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5931 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5932 | return reportInjectionResult(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5933 | } |
| 5934 | |
| 5935 | /** |
| 5936 | * Inject a pointer (touch) event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5937 | * Even when sync is false, this method may block while waiting for current |
| 5938 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5939 | * |
| 5940 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 5941 | * {@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] | 5942 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5943 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5944 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5945 | */ |
| 5946 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5947 | final int pid = Binder.getCallingPid(); |
| 5948 | final int uid = Binder.getCallingUid(); |
| 5949 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5950 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5951 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5952 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) { |
| 5953 | newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 5954 | } |
| 5955 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5956 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5957 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5958 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5959 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5960 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5961 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5962 | return reportInjectionResult(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5963 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5964 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5965 | /** |
| 5966 | * Inject a trackball (navigation device) event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5967 | * Even when sync is false, this method may block while waiting for current |
| 5968 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5969 | * |
| 5970 | * @param ev A motion event describing the trackball action. (As noted in |
| 5971 | * {@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] | 5972 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5973 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5974 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5975 | */ |
| 5976 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5977 | final int pid = Binder.getCallingPid(); |
| 5978 | final int uid = Binder.getCallingUid(); |
| 5979 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5980 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5981 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5982 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) { |
| 5983 | newEvent.setSource(InputDevice.SOURCE_TRACKBALL); |
| 5984 | } |
| 5985 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5986 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5987 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5988 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5989 | INJECTION_TIMEOUT_MILLIS); |
| 5990 | |
| 5991 | Binder.restoreCallingIdentity(ident); |
| 5992 | return reportInjectionResult(result); |
| 5993 | } |
| 5994 | |
| 5995 | /** |
| 5996 | * Inject an input event into the UI without waiting for dispatch to commence. |
| 5997 | * This variant is useful for fire-and-forget input event injection. It does not |
| 5998 | * block any longer than it takes to enqueue the input event. |
| 5999 | * |
| 6000 | * @param ev An input event. (Be sure to set the input source correctly.) |
| 6001 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6002 | */ |
| 6003 | public boolean injectInputEventNoWait(InputEvent ev) { |
| 6004 | final int pid = Binder.getCallingPid(); |
| 6005 | final int uid = Binder.getCallingUid(); |
| 6006 | final long ident = Binder.clearCallingIdentity(); |
| 6007 | |
| 6008 | final int result = mInputManager.injectInputEvent(ev, pid, uid, |
| 6009 | InputManager.INPUT_EVENT_INJECTION_SYNC_NONE, |
| 6010 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6011 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6012 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6013 | return reportInjectionResult(result); |
| 6014 | } |
| 6015 | |
| 6016 | private boolean reportInjectionResult(int result) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6017 | switch (result) { |
| 6018 | case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED: |
| 6019 | Slog.w(TAG, "Input event injection permission denied."); |
| 6020 | throw new SecurityException( |
| 6021 | "Injecting to another application requires INJECT_EVENTS permission"); |
| 6022 | case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED: |
Christopher Tate | 09e85dc | 2010-08-02 11:54:41 -0700 | [diff] [blame] | 6023 | //Slog.v(TAG, "Input event injection succeeded."); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6024 | return true; |
| 6025 | case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT: |
| 6026 | Slog.w(TAG, "Input event injection timed out."); |
| 6027 | return false; |
| 6028 | case InputManager.INPUT_EVENT_INJECTION_FAILED: |
| 6029 | default: |
| 6030 | Slog.w(TAG, "Input event injection failed."); |
| 6031 | return false; |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6032 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6033 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6034 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6035 | private WindowState getFocusedWindow() { |
| 6036 | synchronized (mWindowMap) { |
| 6037 | return getFocusedWindowLocked(); |
| 6038 | } |
| 6039 | } |
| 6040 | |
| 6041 | private WindowState getFocusedWindowLocked() { |
| 6042 | return mCurrentFocus; |
| 6043 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6044 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6045 | public boolean detectSafeMode() { |
| 6046 | mSafeMode = mPolicy.detectSafeMode(); |
| 6047 | return mSafeMode; |
| 6048 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6049 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6050 | public void systemReady() { |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6051 | synchronized(mWindowMap) { |
| 6052 | if (mDisplay != null) { |
| 6053 | throw new IllegalStateException("Display already initialized"); |
| 6054 | } |
| 6055 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 6056 | mDisplay = wm.getDefaultDisplay(); |
| 6057 | mInitialDisplayWidth = mDisplay.getWidth(); |
| 6058 | mInitialDisplayHeight = mDisplay.getHeight(); |
| 6059 | mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight); |
| 6060 | } |
| 6061 | |
| 6062 | try { |
| 6063 | mActivityManager.updateConfiguration(null); |
| 6064 | } catch (RemoteException e) { |
| 6065 | } |
Dianne Hackborn | 154db5f | 2010-07-29 19:15:19 -0700 | [diff] [blame] | 6066 | |
| 6067 | mPolicy.systemReady(); |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6068 | } |
| 6069 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6070 | // ------------------------------------------------------------- |
| 6071 | // Client Session State |
| 6072 | // ------------------------------------------------------------- |
| 6073 | |
| 6074 | private final class Session extends IWindowSession.Stub |
| 6075 | implements IBinder.DeathRecipient { |
| 6076 | final IInputMethodClient mClient; |
| 6077 | final IInputContext mInputContext; |
| 6078 | final int mUid; |
| 6079 | final int mPid; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6080 | final String mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6081 | SurfaceSession mSurfaceSession; |
| 6082 | int mNumWindow = 0; |
| 6083 | boolean mClientDead = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6084 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6085 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 6086 | mClient = client; |
| 6087 | mInputContext = inputContext; |
| 6088 | mUid = Binder.getCallingUid(); |
| 6089 | mPid = Binder.getCallingPid(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6090 | StringBuilder sb = new StringBuilder(); |
| 6091 | sb.append("Session{"); |
| 6092 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 6093 | sb.append(" uid "); |
| 6094 | sb.append(mUid); |
| 6095 | sb.append("}"); |
| 6096 | mStringName = sb.toString(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6097 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6098 | synchronized (mWindowMap) { |
| 6099 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 6100 | IBinder b = ServiceManager.getService( |
| 6101 | Context.INPUT_METHOD_SERVICE); |
| 6102 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 6103 | } |
| 6104 | } |
| 6105 | long ident = Binder.clearCallingIdentity(); |
| 6106 | try { |
| 6107 | // Note: it is safe to call in to the input method manager |
| 6108 | // here because we are not holding our lock. |
| 6109 | if (mInputMethodManager != null) { |
| 6110 | mInputMethodManager.addClient(client, inputContext, |
| 6111 | mUid, mPid); |
| 6112 | } else { |
| 6113 | client.setUsingInputMethod(false); |
| 6114 | } |
| 6115 | client.asBinder().linkToDeath(this, 0); |
| 6116 | } catch (RemoteException e) { |
| 6117 | // The caller has died, so we can just forget about this. |
| 6118 | try { |
| 6119 | if (mInputMethodManager != null) { |
| 6120 | mInputMethodManager.removeClient(client); |
| 6121 | } |
| 6122 | } catch (RemoteException ee) { |
| 6123 | } |
| 6124 | } finally { |
| 6125 | Binder.restoreCallingIdentity(ident); |
| 6126 | } |
| 6127 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6128 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6129 | @Override |
| 6130 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 6131 | throws RemoteException { |
| 6132 | try { |
| 6133 | return super.onTransact(code, data, reply, flags); |
| 6134 | } catch (RuntimeException e) { |
| 6135 | // Log all 'real' exceptions thrown to the caller |
| 6136 | if (!(e instanceof SecurityException)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6137 | Slog.e(TAG, "Window Session Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6138 | } |
| 6139 | throw e; |
| 6140 | } |
| 6141 | } |
| 6142 | |
| 6143 | public void binderDied() { |
| 6144 | // Note: it is safe to call in to the input method manager |
| 6145 | // here because we are not holding our lock. |
| 6146 | try { |
| 6147 | if (mInputMethodManager != null) { |
| 6148 | mInputMethodManager.removeClient(mClient); |
| 6149 | } |
| 6150 | } catch (RemoteException e) { |
| 6151 | } |
| 6152 | synchronized(mWindowMap) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 6153 | mClient.asBinder().unlinkToDeath(this, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6154 | mClientDead = true; |
| 6155 | killSessionLocked(); |
| 6156 | } |
| 6157 | } |
| 6158 | |
| 6159 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6160 | int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) { |
| 6161 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, |
| 6162 | outInputChannel); |
| 6163 | } |
| 6164 | |
| 6165 | public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6166 | int viewVisibility, Rect outContentInsets) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6167 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6168 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6169 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6170 | public void remove(IWindow window) { |
| 6171 | removeWindow(this, window); |
| 6172 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6173 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6174 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 6175 | int requestedWidth, int requestedHeight, int viewFlags, |
| 6176 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6177 | Rect outVisibleInsets, Configuration outConfig, Surface outSurface) { |
Dianne Hackborn | f123e49 | 2010-09-24 11:16:23 -0700 | [diff] [blame] | 6178 | //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid()); |
| 6179 | int res = relayoutWindow(this, window, attrs, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6180 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6181 | outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface); |
Dianne Hackborn | f123e49 | 2010-09-24 11:16:23 -0700 | [diff] [blame] | 6182 | //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid()); |
| 6183 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6184 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6185 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6186 | public void setTransparentRegion(IWindow window, Region region) { |
| 6187 | setTransparentRegionWindow(this, window, region); |
| 6188 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6189 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6190 | public void setInsets(IWindow window, int touchableInsets, |
| 6191 | Rect contentInsets, Rect visibleInsets) { |
| 6192 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 6193 | visibleInsets); |
| 6194 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6195 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6196 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 6197 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 6198 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6199 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6200 | public void finishDrawing(IWindow window) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6201 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6202 | TAG, "IWindow finishDrawing called for " + window); |
| 6203 | finishDrawingWindow(this, window); |
| 6204 | } |
| 6205 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6206 | public void setInTouchMode(boolean mode) { |
| 6207 | synchronized(mWindowMap) { |
| 6208 | mInTouchMode = mode; |
| 6209 | } |
| 6210 | } |
| 6211 | |
| 6212 | public boolean getInTouchMode() { |
| 6213 | synchronized(mWindowMap) { |
| 6214 | return mInTouchMode; |
| 6215 | } |
| 6216 | } |
| 6217 | |
| 6218 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 6219 | boolean always) { |
| 6220 | synchronized(mWindowMap) { |
| 6221 | long ident = Binder.clearCallingIdentity(); |
| 6222 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6223 | return mPolicy.performHapticFeedbackLw( |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6224 | windowForClientLocked(this, window, true), |
| 6225 | effectId, always); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6226 | } finally { |
| 6227 | Binder.restoreCallingIdentity(ident); |
| 6228 | } |
| 6229 | } |
| 6230 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6231 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6232 | /* Drag/drop */ |
| 6233 | public IBinder prepareDrag(IWindow window, boolean localOnly, |
| 6234 | int width, int height, Surface outSurface) { |
| 6235 | return prepareDragSurface(window, mSurfaceSession, localOnly, |
| 6236 | width, height, outSurface); |
| 6237 | } |
| 6238 | |
| 6239 | public boolean performDrag(IWindow window, IBinder dragToken, |
| 6240 | float touchX, float touchY, float thumbCenterX, float thumbCenterY, |
| 6241 | ClipData data) { |
| 6242 | if (DEBUG_DRAG) { |
| 6243 | Slog.d(TAG, "perform drag: win=" + window + " data=" + data); |
| 6244 | } |
| 6245 | |
| 6246 | synchronized (mWindowMap) { |
| 6247 | if (mDragState == null) { |
| 6248 | Slog.w(TAG, "No drag prepared"); |
| 6249 | throw new IllegalStateException("performDrag() without prepareDrag()"); |
| 6250 | } |
| 6251 | |
| 6252 | if (dragToken != mDragState.mToken) { |
| 6253 | Slog.w(TAG, "Performing mismatched drag"); |
| 6254 | throw new IllegalStateException("performDrag() does not match prepareDrag()"); |
| 6255 | } |
| 6256 | |
| 6257 | WindowState callingWin = windowForClientLocked(null, window, false); |
| 6258 | if (callingWin == null) { |
| 6259 | Slog.w(TAG, "Bad requesting window " + window); |
| 6260 | return false; // !!! TODO: throw here? |
| 6261 | } |
| 6262 | |
| 6263 | // !!! TODO: if input is not still focused on the initiating window, fail |
| 6264 | // the drag initiation (e.g. an alarm window popped up just as the application |
| 6265 | // called performDrag() |
| 6266 | |
| 6267 | mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder()); |
| 6268 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 6269 | // !!! TODO: extract the current touch (x, y) in screen coordinates. That |
| 6270 | // will let us eliminate the (touchX,touchY) parameters from the API. |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6271 | |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6272 | // !!! FIXME: put all this heavy stuff onto the mH looper, as well as |
| 6273 | // the actual drag event dispatch stuff in the dragstate |
| 6274 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6275 | mDragState.register(); |
| 6276 | mInputMonitor.updateInputWindowsLw(); |
Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 6277 | if (!mInputManager.transferTouchFocus(callingWin.mInputChannel, |
| 6278 | mDragState.mServerChannel)) { |
| 6279 | Slog.e(TAG, "Unable to transfer touch focus"); |
| 6280 | mDragState.unregister(); |
| 6281 | mDragState = null; |
| 6282 | mInputMonitor.updateInputWindowsLw(); |
| 6283 | return false; |
| 6284 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6285 | |
| 6286 | mDragState.mData = data; |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6287 | mDragState.mCurrentX = touchX; |
| 6288 | mDragState.mCurrentY = touchY; |
Chris Tate | b8203e9 | 2010-10-12 14:23:21 -0700 | [diff] [blame] | 6289 | mDragState.broadcastDragStartedLw(touchX, touchY); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6290 | |
| 6291 | // remember the thumb offsets for later |
| 6292 | mDragState.mThumbOffsetX = thumbCenterX; |
| 6293 | mDragState.mThumbOffsetY = thumbCenterY; |
| 6294 | |
| 6295 | // Make the surface visible at the proper location |
| 6296 | final Surface surface = mDragState.mSurface; |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6297 | Surface.openTransaction(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6298 | try { |
| 6299 | surface.setPosition((int)(touchX - thumbCenterX), |
| 6300 | (int)(touchY - thumbCenterY)); |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6301 | surface.setAlpha(.7071f); |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 6302 | surface.setLayer(mDragState.getDragLayerLw()); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6303 | surface.show(); |
| 6304 | } finally { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6305 | Surface.closeTransaction(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6306 | } |
| 6307 | } |
| 6308 | |
| 6309 | return true; // success! |
| 6310 | } |
| 6311 | |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6312 | public void reportDropResult(IWindow window, boolean consumed) { |
| 6313 | IBinder token = window.asBinder(); |
| 6314 | if (DEBUG_DRAG) { |
| 6315 | Slog.d(TAG, "Drop result=" + consumed + " reported by " + token); |
| 6316 | } |
| 6317 | |
| 6318 | synchronized (mWindowMap) { |
| 6319 | if (mDragState.mToken != token) { |
| 6320 | Slog.w(TAG, "Invalid drop-result claim by " + window); |
| 6321 | throw new IllegalStateException("reportDropResult() by non-recipient"); |
| 6322 | } |
| 6323 | |
| 6324 | // The right window has responded, even if it's no longer around, |
| 6325 | // so be sure to halt the timeout even if the later WindowState |
| 6326 | // lookup fails. |
| 6327 | mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder()); |
| 6328 | |
| 6329 | WindowState callingWin = windowForClientLocked(null, window, false); |
| 6330 | if (callingWin == null) { |
| 6331 | Slog.w(TAG, "Bad result-reporting window " + window); |
| 6332 | return; // !!! TODO: throw here? |
| 6333 | } |
| 6334 | |
| 6335 | mDragState.mDragResult = consumed; |
| 6336 | mDragState.endDragLw(); |
| 6337 | } |
| 6338 | } |
| 6339 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6340 | public void dragRecipientEntered(IWindow window) { |
| 6341 | if (DEBUG_DRAG) { |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6342 | Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder()); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6343 | } |
| 6344 | } |
| 6345 | |
| 6346 | public void dragRecipientExited(IWindow window) { |
| 6347 | if (DEBUG_DRAG) { |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6348 | Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder()); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6349 | } |
| 6350 | } |
| 6351 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6352 | 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] | 6353 | synchronized(mWindowMap) { |
| 6354 | long ident = Binder.clearCallingIdentity(); |
| 6355 | try { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6356 | setWindowWallpaperPositionLocked( |
| 6357 | windowForClientLocked(this, window, true), |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6358 | x, y, xStep, yStep); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6359 | } finally { |
| 6360 | Binder.restoreCallingIdentity(ident); |
| 6361 | } |
| 6362 | } |
| 6363 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6364 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6365 | public void wallpaperOffsetsComplete(IBinder window) { |
| 6366 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 6367 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6368 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6369 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 6370 | int z, Bundle extras, boolean sync) { |
| 6371 | synchronized(mWindowMap) { |
| 6372 | long ident = Binder.clearCallingIdentity(); |
| 6373 | try { |
| 6374 | return sendWindowWallpaperCommandLocked( |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6375 | windowForClientLocked(this, window, true), |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6376 | action, x, y, z, extras, sync); |
| 6377 | } finally { |
| 6378 | Binder.restoreCallingIdentity(ident); |
| 6379 | } |
| 6380 | } |
| 6381 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6382 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6383 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 6384 | WindowManagerService.this.wallpaperCommandComplete(window, result); |
| 6385 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6386 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6387 | void windowAddedLocked() { |
| 6388 | if (mSurfaceSession == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6389 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6390 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 6391 | mSurfaceSession = new SurfaceSession(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6392 | if (SHOW_TRANSACTIONS) Slog.i( |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6393 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6394 | mSessions.add(this); |
| 6395 | } |
| 6396 | mNumWindow++; |
| 6397 | } |
| 6398 | |
| 6399 | void windowRemovedLocked() { |
| 6400 | mNumWindow--; |
| 6401 | killSessionLocked(); |
| 6402 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6403 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6404 | void killSessionLocked() { |
| 6405 | if (mNumWindow <= 0 && mClientDead) { |
| 6406 | mSessions.remove(this); |
| 6407 | if (mSurfaceSession != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6408 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6409 | TAG, "Last window removed from " + this |
| 6410 | + ", destroying " + mSurfaceSession); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6411 | if (SHOW_TRANSACTIONS) Slog.i( |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6412 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6413 | try { |
| 6414 | mSurfaceSession.kill(); |
| 6415 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6416 | Slog.w(TAG, "Exception thrown when killing surface session " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6417 | + mSurfaceSession + " in session " + this |
| 6418 | + ": " + e.toString()); |
| 6419 | } |
| 6420 | mSurfaceSession = null; |
| 6421 | } |
| 6422 | } |
| 6423 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6424 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6425 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6426 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 6427 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 6428 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6429 | } |
| 6430 | |
| 6431 | @Override |
| 6432 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6433 | return mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6434 | } |
| 6435 | } |
| 6436 | |
| 6437 | // ------------------------------------------------------------- |
| 6438 | // Client Window State |
| 6439 | // ------------------------------------------------------------- |
| 6440 | |
| 6441 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 6442 | final Session mSession; |
| 6443 | final IWindow mClient; |
| 6444 | WindowToken mToken; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6445 | WindowToken mRootToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6446 | AppWindowToken mAppToken; |
| 6447 | AppWindowToken mTargetAppToken; |
| 6448 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 6449 | final DeathRecipient mDeathRecipient; |
| 6450 | final WindowState mAttachedWindow; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6451 | final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6452 | final int mBaseLayer; |
| 6453 | final int mSubLayer; |
| 6454 | final boolean mLayoutAttached; |
| 6455 | final boolean mIsImWindow; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6456 | final boolean mIsWallpaper; |
| 6457 | final boolean mIsFloatingLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6458 | int mViewVisibility; |
| 6459 | boolean mPolicyVisibility = true; |
| 6460 | boolean mPolicyVisibilityAfterAnim = true; |
| 6461 | boolean mAppFreezing; |
| 6462 | Surface mSurface; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6463 | boolean mReportDestroySurface; |
| 6464 | boolean mSurfacePendingDestroy; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6465 | boolean mAttachedHidden; // is our parent window hidden? |
| 6466 | boolean mLastHidden; // was this window last hidden? |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6467 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6468 | int mRequestedWidth; |
| 6469 | int mRequestedHeight; |
| 6470 | int mLastRequestedWidth; |
| 6471 | int mLastRequestedHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6472 | int mLayer; |
| 6473 | int mAnimLayer; |
| 6474 | int mLastLayer; |
| 6475 | boolean mHaveFrame; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6476 | boolean mObscured; |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 6477 | boolean mTurnOnScreen; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6478 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6479 | int mLayoutSeq = -1; |
| 6480 | |
| 6481 | Configuration mConfiguration = null; |
| 6482 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6483 | // Actual frame shown on-screen (may be modified by animation) |
| 6484 | final Rect mShownFrame = new Rect(); |
| 6485 | final Rect mLastShownFrame = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6486 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6487 | /** |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 6488 | * Set when we have changed the size of the surface, to know that |
| 6489 | * we must tell them application to resize (and thus redraw itself). |
| 6490 | */ |
| 6491 | boolean mSurfaceResized; |
| 6492 | |
| 6493 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6494 | * Insets that determine the actually visible area |
| 6495 | */ |
| 6496 | final Rect mVisibleInsets = new Rect(); |
| 6497 | final Rect mLastVisibleInsets = new Rect(); |
| 6498 | boolean mVisibleInsetsChanged; |
| 6499 | |
| 6500 | /** |
| 6501 | * Insets that are covered by system windows |
| 6502 | */ |
| 6503 | final Rect mContentInsets = new Rect(); |
| 6504 | final Rect mLastContentInsets = new Rect(); |
| 6505 | boolean mContentInsetsChanged; |
| 6506 | |
| 6507 | /** |
| 6508 | * Set to true if we are waiting for this window to receive its |
| 6509 | * given internal insets before laying out other windows based on it. |
| 6510 | */ |
| 6511 | boolean mGivenInsetsPending; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6512 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6513 | /** |
| 6514 | * These are the content insets that were given during layout for |
| 6515 | * this window, to be applied to windows behind it. |
| 6516 | */ |
| 6517 | final Rect mGivenContentInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6518 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6519 | /** |
| 6520 | * These are the visible insets that were given during layout for |
| 6521 | * this window, to be applied to windows behind it. |
| 6522 | */ |
| 6523 | final Rect mGivenVisibleInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6524 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6525 | /** |
| 6526 | * Flag indicating whether the touchable region should be adjusted by |
| 6527 | * the visible insets; if false the area outside the visible insets is |
| 6528 | * NOT touchable, so we must use those to adjust the frame during hit |
| 6529 | * tests. |
| 6530 | */ |
| 6531 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6532 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6533 | // Current transformation being applied. |
| 6534 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 6535 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 6536 | float mHScale=1, mVScale=1; |
| 6537 | float mLastHScale=1, mLastVScale=1; |
| 6538 | final Matrix mTmpMatrix = new Matrix(); |
| 6539 | |
| 6540 | // "Real" frame that the application sees. |
| 6541 | final Rect mFrame = new Rect(); |
| 6542 | final Rect mLastFrame = new Rect(); |
| 6543 | |
| 6544 | final Rect mContainingFrame = new Rect(); |
| 6545 | final Rect mDisplayFrame = new Rect(); |
| 6546 | final Rect mContentFrame = new Rect(); |
| 6547 | final Rect mVisibleFrame = new Rect(); |
| 6548 | |
| 6549 | float mShownAlpha = 1; |
| 6550 | float mAlpha = 1; |
| 6551 | float mLastAlpha = 1; |
| 6552 | |
| 6553 | // Set to true if, when the window gets displayed, it should perform |
| 6554 | // an enter animation. |
| 6555 | boolean mEnterAnimationPending; |
| 6556 | |
| 6557 | // Currently running animation. |
| 6558 | boolean mAnimating; |
| 6559 | boolean mLocalAnimating; |
| 6560 | Animation mAnimation; |
| 6561 | boolean mAnimationIsEntrance; |
| 6562 | boolean mHasTransformation; |
| 6563 | boolean mHasLocalTransformation; |
| 6564 | final Transformation mTransformation = new Transformation(); |
| 6565 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6566 | // If a window showing a wallpaper: the requested offset for the |
| 6567 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 6568 | float mWallpaperX = -1; |
| 6569 | float mWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6570 | |
| 6571 | // If a window showing a wallpaper: what fraction of the offset |
| 6572 | // range corresponds to a full virtual screen. |
| 6573 | float mWallpaperXStep = -1; |
| 6574 | float mWallpaperYStep = -1; |
| 6575 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6576 | // Wallpaper windows: pixels offset based on above variables. |
| 6577 | int mXOffset; |
| 6578 | int mYOffset; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6579 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6580 | // This is set after IWindowSession.relayout() has been called at |
| 6581 | // least once for the window. It allows us to detect the situation |
| 6582 | // where we don't yet have a surface, but should have one soon, so |
| 6583 | // we can give the window focus before waiting for the relayout. |
| 6584 | boolean mRelayoutCalled; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6585 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6586 | // This is set after the Surface has been created but before the |
| 6587 | // window has been drawn. During this time the surface is hidden. |
| 6588 | boolean mDrawPending; |
| 6589 | |
| 6590 | // This is set after the window has finished drawing for the first |
| 6591 | // time but before its surface is shown. The surface will be |
| 6592 | // displayed when the next layout is run. |
| 6593 | boolean mCommitDrawPending; |
| 6594 | |
| 6595 | // This is set during the time after the window's drawing has been |
| 6596 | // committed, and before its surface is actually shown. It is used |
| 6597 | // to delay showing the surface until all windows in a token are ready |
| 6598 | // to be shown. |
| 6599 | boolean mReadyToShow; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6600 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6601 | // Set when the window has been shown in the screen the first time. |
| 6602 | boolean mHasDrawn; |
| 6603 | |
| 6604 | // Currently running an exit animation? |
| 6605 | boolean mExiting; |
| 6606 | |
| 6607 | // Currently on the mDestroySurface list? |
| 6608 | boolean mDestroying; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6609 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6610 | // Completely remove from window manager after exit animation? |
| 6611 | boolean mRemoveOnExit; |
| 6612 | |
| 6613 | // Set when the orientation is changing and this window has not yet |
| 6614 | // been updated for the new orientation. |
| 6615 | boolean mOrientationChanging; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6616 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6617 | // Is this window now (or just being) removed? |
| 6618 | boolean mRemoved; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6619 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6620 | // For debugging, this is the last information given to the surface flinger. |
| 6621 | boolean mSurfaceShown; |
| 6622 | int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH; |
| 6623 | int mSurfaceLayer; |
| 6624 | float mSurfaceAlpha; |
| 6625 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6626 | // Input channel |
| 6627 | InputChannel mInputChannel; |
| 6628 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6629 | WindowState(Session s, IWindow c, WindowToken token, |
| 6630 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 6631 | int viewVisibility) { |
| 6632 | mSession = s; |
| 6633 | mClient = c; |
| 6634 | mToken = token; |
| 6635 | mAttrs.copyFrom(a); |
| 6636 | mViewVisibility = viewVisibility; |
| 6637 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 6638 | mAlpha = a.alpha; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6639 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6640 | TAG, "Window " + this + " client=" + c.asBinder() |
| 6641 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 6642 | try { |
| 6643 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 6644 | } catch (RemoteException e) { |
| 6645 | mDeathRecipient = null; |
| 6646 | mAttachedWindow = null; |
| 6647 | mLayoutAttached = false; |
| 6648 | mIsImWindow = false; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6649 | mIsWallpaper = false; |
| 6650 | mIsFloatingLayer = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6651 | mBaseLayer = 0; |
| 6652 | mSubLayer = 0; |
| 6653 | return; |
| 6654 | } |
| 6655 | mDeathRecipient = deathRecipient; |
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 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 6658 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 6659 | // The multiplier here is to reserve space for multiple |
| 6660 | // windows in the same type layer. |
| 6661 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 6662 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 6663 | + TYPE_LAYER_OFFSET; |
| 6664 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 6665 | mAttachedWindow = attachedWindow; |
| 6666 | mAttachedWindow.mChildWindows.add(this); |
| 6667 | mLayoutAttached = mAttrs.type != |
| 6668 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 6669 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 6670 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6671 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 6672 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6673 | } else { |
| 6674 | // The multiplier here is to reserve space for multiple |
| 6675 | // windows in the same type layer. |
| 6676 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 6677 | * TYPE_LAYER_MULTIPLIER |
| 6678 | + TYPE_LAYER_OFFSET; |
| 6679 | mSubLayer = 0; |
| 6680 | mAttachedWindow = null; |
| 6681 | mLayoutAttached = false; |
| 6682 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 6683 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6684 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 6685 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6686 | } |
| 6687 | |
| 6688 | WindowState appWin = this; |
| 6689 | while (appWin.mAttachedWindow != null) { |
| 6690 | appWin = mAttachedWindow; |
| 6691 | } |
| 6692 | WindowToken appToken = appWin.mToken; |
| 6693 | while (appToken.appWindowToken == null) { |
| 6694 | WindowToken parent = mTokenMap.get(appToken.token); |
| 6695 | if (parent == null || appToken == parent) { |
| 6696 | break; |
| 6697 | } |
| 6698 | appToken = parent; |
| 6699 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6700 | mRootToken = appToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6701 | mAppToken = appToken.appWindowToken; |
| 6702 | |
| 6703 | mSurface = null; |
| 6704 | mRequestedWidth = 0; |
| 6705 | mRequestedHeight = 0; |
| 6706 | mLastRequestedWidth = 0; |
| 6707 | mLastRequestedHeight = 0; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6708 | mXOffset = 0; |
| 6709 | mYOffset = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6710 | mLayer = 0; |
| 6711 | mAnimLayer = 0; |
| 6712 | mLastLayer = 0; |
| 6713 | } |
| 6714 | |
| 6715 | void attach() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6716 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6717 | TAG, "Attaching " + this + " token=" + mToken |
| 6718 | + ", list=" + mToken.windows); |
| 6719 | mSession.windowAddedLocked(); |
| 6720 | } |
| 6721 | |
| 6722 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 6723 | mHaveFrame = true; |
| 6724 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6725 | final Rect container = mContainingFrame; |
| 6726 | container.set(pf); |
| 6727 | |
| 6728 | final Rect display = mDisplayFrame; |
| 6729 | display.set(df); |
| 6730 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 6731 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6732 | container.intersect(mCompatibleScreenFrame); |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6733 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 6734 | display.intersect(mCompatibleScreenFrame); |
| 6735 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6736 | } |
| 6737 | |
| 6738 | final int pw = container.right - container.left; |
| 6739 | final int ph = container.bottom - container.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6740 | |
| 6741 | int w,h; |
| 6742 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 6743 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 6744 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 6745 | } else { |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 6746 | w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth; |
| 6747 | h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6748 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6749 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6750 | final Rect content = mContentFrame; |
| 6751 | content.set(cf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6752 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6753 | final Rect visible = mVisibleFrame; |
| 6754 | visible.set(vf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6755 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6756 | final Rect frame = mFrame; |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6757 | final int fw = frame.width(); |
| 6758 | final int fh = frame.height(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6759 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6760 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 6761 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 6762 | |
| 6763 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 6764 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 6765 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 6766 | |
| 6767 | //System.out.println("Out: " + mFrame); |
| 6768 | |
| 6769 | // Now make sure the window fits in the overall display. |
| 6770 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6771 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6772 | // Make sure the content and visible frames are inside of the |
| 6773 | // final window frame. |
| 6774 | if (content.left < frame.left) content.left = frame.left; |
| 6775 | if (content.top < frame.top) content.top = frame.top; |
| 6776 | if (content.right > frame.right) content.right = frame.right; |
| 6777 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 6778 | if (visible.left < frame.left) visible.left = frame.left; |
| 6779 | if (visible.top < frame.top) visible.top = frame.top; |
| 6780 | if (visible.right > frame.right) visible.right = frame.right; |
| 6781 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6782 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6783 | final Rect contentInsets = mContentInsets; |
| 6784 | contentInsets.left = content.left-frame.left; |
| 6785 | contentInsets.top = content.top-frame.top; |
| 6786 | contentInsets.right = frame.right-content.right; |
| 6787 | contentInsets.bottom = frame.bottom-content.bottom; |
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 | final Rect visibleInsets = mVisibleInsets; |
| 6790 | visibleInsets.left = visible.left-frame.left; |
| 6791 | visibleInsets.top = visible.top-frame.top; |
| 6792 | visibleInsets.right = frame.right-visible.right; |
| 6793 | visibleInsets.bottom = frame.bottom-visible.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6794 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 6795 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 6796 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6797 | mDisplay.getHeight(), false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6798 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6799 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6800 | if (localLOGV) { |
| 6801 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 6802 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6803 | Slog.v(TAG, "Resolving (mRequestedWidth=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6804 | + mRequestedWidth + ", mRequestedheight=" |
| 6805 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 6806 | + "): frame=" + mFrame.toShortString() |
| 6807 | + " ci=" + contentInsets.toShortString() |
| 6808 | + " vi=" + visibleInsets.toShortString()); |
| 6809 | //} |
| 6810 | } |
| 6811 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6812 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6813 | public Rect getFrameLw() { |
| 6814 | return mFrame; |
| 6815 | } |
| 6816 | |
| 6817 | public Rect getShownFrameLw() { |
| 6818 | return mShownFrame; |
| 6819 | } |
| 6820 | |
| 6821 | public Rect getDisplayFrameLw() { |
| 6822 | return mDisplayFrame; |
| 6823 | } |
| 6824 | |
| 6825 | public Rect getContentFrameLw() { |
| 6826 | return mContentFrame; |
| 6827 | } |
| 6828 | |
| 6829 | public Rect getVisibleFrameLw() { |
| 6830 | return mVisibleFrame; |
| 6831 | } |
| 6832 | |
| 6833 | public boolean getGivenInsetsPendingLw() { |
| 6834 | return mGivenInsetsPending; |
| 6835 | } |
| 6836 | |
| 6837 | public Rect getGivenContentInsetsLw() { |
| 6838 | return mGivenContentInsets; |
| 6839 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6840 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6841 | public Rect getGivenVisibleInsetsLw() { |
| 6842 | return mGivenVisibleInsets; |
| 6843 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6844 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6845 | public WindowManager.LayoutParams getAttrs() { |
| 6846 | return mAttrs; |
| 6847 | } |
| 6848 | |
| 6849 | public int getSurfaceLayer() { |
| 6850 | return mLayer; |
| 6851 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6852 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6853 | public IApplicationToken getAppToken() { |
| 6854 | return mAppToken != null ? mAppToken.appToken : null; |
| 6855 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6856 | |
| 6857 | public long getInputDispatchingTimeoutNanos() { |
| 6858 | return mAppToken != null |
| 6859 | ? mAppToken.inputDispatchingTimeoutNanos |
| 6860 | : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 6861 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6862 | |
| 6863 | public boolean hasAppShownWindows() { |
| 6864 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 6865 | } |
| 6866 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6867 | public void setAnimation(Animation anim) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6868 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6869 | TAG, "Setting animation in " + this + ": " + anim); |
| 6870 | mAnimating = false; |
| 6871 | mLocalAnimating = false; |
| 6872 | mAnimation = anim; |
| 6873 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 6874 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 6875 | } |
| 6876 | |
| 6877 | public void clearAnimation() { |
| 6878 | if (mAnimation != null) { |
| 6879 | mAnimating = true; |
| 6880 | mLocalAnimating = false; |
| 6881 | mAnimation = null; |
| 6882 | } |
| 6883 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6884 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6885 | Surface createSurfaceLocked() { |
| 6886 | if (mSurface == null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6887 | mReportDestroySurface = false; |
| 6888 | mSurfacePendingDestroy = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6889 | mDrawPending = true; |
| 6890 | mCommitDrawPending = false; |
| 6891 | mReadyToShow = false; |
| 6892 | if (mAppToken != null) { |
| 6893 | mAppToken.allDrawn = false; |
| 6894 | } |
| 6895 | |
| 6896 | int flags = 0; |
Mathias Agopian | 317a628 | 2009-08-13 17:29:02 -0700 | [diff] [blame] | 6897 | if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6898 | flags |= Surface.PUSH_BUFFERS; |
| 6899 | } |
| 6900 | |
| 6901 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 6902 | flags |= Surface.SECURE; |
| 6903 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6904 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6905 | TAG, "Creating surface in session " |
| 6906 | + mSession.mSurfaceSession + " window " + this |
| 6907 | + " w=" + mFrame.width() |
| 6908 | + " h=" + mFrame.height() + " format=" |
| 6909 | + mAttrs.format + " flags=" + flags); |
| 6910 | |
| 6911 | int w = mFrame.width(); |
| 6912 | int h = mFrame.height(); |
| 6913 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 6914 | // for a scaled surface, we always want the requested |
| 6915 | // size. |
| 6916 | w = mRequestedWidth; |
| 6917 | h = mRequestedHeight; |
| 6918 | } |
| 6919 | |
Romain Guy | 9825ec6 | 2009-10-01 00:58:09 -0700 | [diff] [blame] | 6920 | // Something is wrong and SurfaceFlinger will not like this, |
| 6921 | // try to revert to sane values |
| 6922 | if (w <= 0) w = 1; |
| 6923 | if (h <= 0) h = 1; |
| 6924 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6925 | mSurfaceShown = false; |
| 6926 | mSurfaceLayer = 0; |
| 6927 | mSurfaceAlpha = 1; |
| 6928 | mSurfaceX = 0; |
| 6929 | mSurfaceY = 0; |
| 6930 | mSurfaceW = w; |
| 6931 | mSurfaceH = h; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6932 | try { |
Romain Guy | d10cd57 | 2010-10-10 13:33:22 -0700 | [diff] [blame] | 6933 | final boolean isHwAccelerated = (mAttrs.flags & |
| 6934 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0; |
| 6935 | final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format; |
| 6936 | if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) { |
| 6937 | flags |= Surface.OPAQUE; |
| 6938 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6939 | mSurface = new Surface( |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6940 | mSession.mSurfaceSession, mSession.mPid, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 6941 | mAttrs.getTitle().toString(), |
Romain Guy | d10cd57 | 2010-10-10 13:33:22 -0700 | [diff] [blame] | 6942 | 0, w, h, format, flags); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6943 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6944 | + mSurface + " IN SESSION " |
| 6945 | + mSession.mSurfaceSession |
| 6946 | + ": pid=" + mSession.mPid + " format=" |
| 6947 | + mAttrs.format + " flags=0x" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6948 | + Integer.toHexString(flags) |
| 6949 | + " / " + this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6950 | } catch (Surface.OutOfResourcesException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6951 | Slog.w(TAG, "OutOfResourcesException creating surface"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6952 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 6953 | return null; |
| 6954 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6955 | Slog.e(TAG, "Exception creating surface", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6956 | return null; |
| 6957 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6958 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6959 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6960 | TAG, "Got surface: " + mSurface |
| 6961 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 6962 | + ", animLayer=" + mAnimLayer); |
| 6963 | if (SHOW_TRANSACTIONS) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6964 | Slog.i(TAG, ">>> OPEN TRANSACTION"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6965 | if (SHOW_TRANSACTIONS) logSurface(this, |
| 6966 | "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" + |
| 6967 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 6968 | mAnimLayer + " HIDE", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6969 | } |
| 6970 | Surface.openTransaction(); |
| 6971 | try { |
| 6972 | try { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6973 | mSurfaceX = mFrame.left + mXOffset; |
Dianne Hackborn | 529bef6 | 2010-03-25 11:48:43 -0700 | [diff] [blame] | 6974 | mSurfaceY = mFrame.top + mYOffset; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6975 | mSurface.setPosition(mSurfaceX, mSurfaceY); |
| 6976 | mSurfaceLayer = mAnimLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6977 | mSurface.setLayer(mAnimLayer); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6978 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6979 | mSurface.hide(); |
| 6980 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6981 | if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6982 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 6983 | Surface.SURFACE_DITHER); |
| 6984 | } |
| 6985 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6986 | Slog.w(TAG, "Error creating surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6987 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 6988 | } |
| 6989 | mLastHidden = true; |
| 6990 | } finally { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6991 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6992 | Surface.closeTransaction(); |
| 6993 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6994 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6995 | TAG, "Created surface " + this); |
| 6996 | } |
| 6997 | return mSurface; |
| 6998 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6999 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7000 | void destroySurfaceLocked() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7001 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 7002 | mAppToken.startingDisplayed = false; |
| 7003 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7004 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7005 | if (mSurface != null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7006 | mDrawPending = false; |
| 7007 | mCommitDrawPending = false; |
| 7008 | mReadyToShow = false; |
| 7009 | |
| 7010 | int i = mChildWindows.size(); |
| 7011 | while (i > 0) { |
| 7012 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7013 | WindowState c = mChildWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7014 | c.mAttachedHidden = true; |
| 7015 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7016 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7017 | if (mReportDestroySurface) { |
| 7018 | mReportDestroySurface = false; |
| 7019 | mSurfacePendingDestroy = true; |
| 7020 | try { |
| 7021 | mClient.dispatchGetNewSurface(); |
| 7022 | // We'll really destroy on the next time around. |
| 7023 | return; |
| 7024 | } catch (RemoteException e) { |
| 7025 | } |
| 7026 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7027 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7028 | try { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7029 | if (DEBUG_VISIBILITY) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7030 | RuntimeException e = null; |
| 7031 | if (!HIDE_STACK_CRAWLS) { |
| 7032 | e = new RuntimeException(); |
| 7033 | e.fillInStackTrace(); |
| 7034 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7035 | Slog.w(TAG, "Window " + this + " destroying surface " |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7036 | + mSurface + ", session " + mSession, e); |
| 7037 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7038 | if (SHOW_TRANSACTIONS) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7039 | RuntimeException e = null; |
| 7040 | if (!HIDE_STACK_CRAWLS) { |
| 7041 | e = new RuntimeException(); |
| 7042 | e.fillInStackTrace(); |
| 7043 | } |
| 7044 | if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7045 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7046 | mSurface.destroy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7047 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7048 | Slog.w(TAG, "Exception thrown when destroying Window " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7049 | + " surface " + mSurface + " session " + mSession |
| 7050 | + ": " + e.toString()); |
| 7051 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7052 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7053 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7054 | mSurface = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7055 | } |
| 7056 | } |
| 7057 | |
| 7058 | boolean finishDrawingLocked() { |
| 7059 | if (mDrawPending) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7060 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7061 | TAG, "finishDrawingLocked: " + mSurface); |
| 7062 | mCommitDrawPending = true; |
| 7063 | mDrawPending = false; |
| 7064 | return true; |
| 7065 | } |
| 7066 | return false; |
| 7067 | } |
| 7068 | |
| 7069 | // This must be called while inside a transaction. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7070 | boolean commitFinishDrawingLocked(long currentTime) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7071 | //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7072 | if (!mCommitDrawPending) { |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7073 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7074 | } |
| 7075 | mCommitDrawPending = false; |
| 7076 | mReadyToShow = true; |
| 7077 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 7078 | final AppWindowToken atoken = mAppToken; |
| 7079 | if (atoken == null || atoken.allDrawn || starting) { |
| 7080 | performShowLocked(); |
| 7081 | } |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7082 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7083 | } |
| 7084 | |
| 7085 | // This must be called while inside a transaction. |
| 7086 | boolean performShowLocked() { |
| 7087 | if (DEBUG_VISIBILITY) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7088 | RuntimeException e = null; |
| 7089 | if (!HIDE_STACK_CRAWLS) { |
| 7090 | e = new RuntimeException(); |
| 7091 | e.fillInStackTrace(); |
| 7092 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7093 | Slog.v(TAG, "performShow on " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7094 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 7095 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 7096 | } |
| 7097 | if (mReadyToShow && isReadyForDisplay()) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7098 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this, |
| 7099 | "SHOW (performShowLocked)", null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7100 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7101 | + " during animation: policyVis=" + mPolicyVisibility |
| 7102 | + " attHidden=" + mAttachedHidden |
| 7103 | + " tok.hiddenRequested=" |
| 7104 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7105 | + " tok.hidden=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7106 | + (mAppToken != null ? mAppToken.hidden : false) |
| 7107 | + " animating=" + mAnimating |
| 7108 | + " tok animating=" |
| 7109 | + (mAppToken != null ? mAppToken.animating : false)); |
| 7110 | if (!showSurfaceRobustlyLocked(this)) { |
| 7111 | return false; |
| 7112 | } |
| 7113 | mLastAlpha = -1; |
| 7114 | mHasDrawn = true; |
| 7115 | mLastHidden = false; |
| 7116 | mReadyToShow = false; |
| 7117 | enableScreenIfNeededLocked(); |
| 7118 | |
| 7119 | applyEnterAnimationLocked(this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7120 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7121 | int i = mChildWindows.size(); |
| 7122 | while (i > 0) { |
| 7123 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7124 | WindowState c = mChildWindows.get(i); |
Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7125 | if (c.mAttachedHidden) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7126 | c.mAttachedHidden = false; |
Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7127 | if (c.mSurface != null) { |
| 7128 | c.performShowLocked(); |
| 7129 | // It hadn't been shown, which means layout not |
| 7130 | // performed on it, so now we want to make sure to |
| 7131 | // do a layout. If called from within the transaction |
| 7132 | // loop, this will cause it to restart with a new |
| 7133 | // layout. |
| 7134 | mLayoutNeeded = true; |
| 7135 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7136 | } |
| 7137 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7138 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7139 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 7140 | && mAppToken != null) { |
| 7141 | mAppToken.firstWindowDrawn = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7142 | |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7143 | if (mAppToken.startingData != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7144 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7145 | "Finish starting " + mToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7146 | + ": first real window is shown, no animation"); |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7147 | // If this initial window is animating, stop it -- we |
| 7148 | // will do an animation to reveal it from behind the |
| 7149 | // starting window, so there is no need for it to also |
| 7150 | // be doing its own stuff. |
| 7151 | if (mAnimation != null) { |
| 7152 | mAnimation = null; |
| 7153 | // Make sure we clean up the animation. |
| 7154 | mAnimating = true; |
| 7155 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7156 | mFinishedStarting.add(mAppToken); |
| 7157 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7158 | } |
| 7159 | mAppToken.updateReportedVisibilityLocked(); |
| 7160 | } |
| 7161 | } |
| 7162 | return true; |
| 7163 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7164 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7165 | // This must be called while inside a transaction. Returns true if |
| 7166 | // there is more animation to run. |
| 7167 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7168 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7169 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7170 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7171 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 7172 | mHasTransformation = true; |
| 7173 | mHasLocalTransformation = true; |
| 7174 | if (!mLocalAnimating) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7175 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7176 | TAG, "Starting animation in " + this + |
| 7177 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 7178 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 7179 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 7180 | mAnimation.setStartTime(currentTime); |
| 7181 | mLocalAnimating = true; |
| 7182 | mAnimating = true; |
| 7183 | } |
| 7184 | mTransformation.clear(); |
| 7185 | final boolean more = mAnimation.getTransformation( |
| 7186 | currentTime, mTransformation); |
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, "Stepped animation in " + this + |
| 7189 | ": more=" + more + ", xform=" + mTransformation); |
| 7190 | if (more) { |
| 7191 | // we're not done! |
| 7192 | return true; |
| 7193 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7194 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7195 | TAG, "Finished animation in " + this + |
| 7196 | " @ " + currentTime); |
| 7197 | mAnimation = null; |
| 7198 | //WindowManagerService.this.dump(); |
| 7199 | } |
| 7200 | mHasLocalTransformation = false; |
| 7201 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7202 | && mAppToken.animation != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7203 | // When our app token is animating, we kind-of pretend like |
| 7204 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 7205 | // part of this check means that we will only do this if |
| 7206 | // our window is not currently exiting, or it is not |
| 7207 | // locally animating itself. The idea being that one that |
| 7208 | // is exiting and doing a local animation should be removed |
| 7209 | // once that animation is done. |
| 7210 | mAnimating = true; |
| 7211 | mHasTransformation = true; |
| 7212 | mTransformation.clear(); |
| 7213 | return false; |
| 7214 | } else if (mHasTransformation) { |
| 7215 | // Little trick to get through the path below to act like |
| 7216 | // we have finished an animation. |
| 7217 | mAnimating = true; |
| 7218 | } else if (isAnimating()) { |
| 7219 | mAnimating = true; |
| 7220 | } |
| 7221 | } else if (mAnimation != null) { |
| 7222 | // If the display is frozen, and there is a pending animation, |
| 7223 | // clear it and make sure we run the cleanup code. |
| 7224 | mAnimating = true; |
| 7225 | mLocalAnimating = true; |
| 7226 | mAnimation = null; |
| 7227 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7228 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7229 | if (!mAnimating && !mLocalAnimating) { |
| 7230 | return false; |
| 7231 | } |
| 7232 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7233 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7234 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 7235 | + ", reportedVisible=" |
| 7236 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7237 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7238 | mAnimating = false; |
| 7239 | mLocalAnimating = false; |
| 7240 | mAnimation = null; |
| 7241 | mAnimLayer = mLayer; |
| 7242 | if (mIsImWindow) { |
| 7243 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7244 | } else if (mIsWallpaper) { |
| 7245 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7246 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7247 | if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7248 | + " anim layer: " + mAnimLayer); |
| 7249 | mHasTransformation = false; |
| 7250 | mHasLocalTransformation = false; |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7251 | if (mPolicyVisibility != mPolicyVisibilityAfterAnim) { |
| 7252 | if (DEBUG_VISIBILITY) { |
| 7253 | Slog.v(TAG, "Policy visibility changing after anim in " + this + ": " |
| 7254 | + mPolicyVisibilityAfterAnim); |
| 7255 | } |
| 7256 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 7257 | if (!mPolicyVisibility) { |
| 7258 | if (mCurrentFocus == this) { |
| 7259 | mFocusMayChange = true; |
| 7260 | } |
| 7261 | // Window is no longer visible -- make sure if we were waiting |
| 7262 | // for it to be displayed before enabling the display, that |
| 7263 | // we allow the display to be enabled now. |
| 7264 | enableScreenIfNeededLocked(); |
| 7265 | } |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7266 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7267 | mTransformation.clear(); |
| 7268 | if (mHasDrawn |
| 7269 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 7270 | && mAppToken != null |
| 7271 | && mAppToken.firstWindowDrawn |
| 7272 | && mAppToken.startingData != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7273 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7274 | + mToken + ": first real window done animating"); |
| 7275 | mFinishedStarting.add(mAppToken); |
| 7276 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7277 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7278 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7279 | finishExit(); |
| 7280 | |
| 7281 | if (mAppToken != null) { |
| 7282 | mAppToken.updateReportedVisibilityLocked(); |
| 7283 | } |
| 7284 | |
| 7285 | return false; |
| 7286 | } |
| 7287 | |
| 7288 | void finishExit() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7289 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7290 | TAG, "finishExit in " + this |
| 7291 | + ": exiting=" + mExiting |
| 7292 | + " remove=" + mRemoveOnExit |
| 7293 | + " windowAnimating=" + isWindowAnimating()); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7294 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7295 | final int N = mChildWindows.size(); |
| 7296 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7297 | mChildWindows.get(i).finishExit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7298 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7299 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7300 | if (!mExiting) { |
| 7301 | return; |
| 7302 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7303 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7304 | if (isWindowAnimating()) { |
| 7305 | return; |
| 7306 | } |
| 7307 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7308 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7309 | TAG, "Exit animation finished in " + this |
| 7310 | + ": remove=" + mRemoveOnExit); |
| 7311 | if (mSurface != null) { |
| 7312 | mDestroySurface.add(this); |
| 7313 | mDestroying = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7314 | if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7315 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7316 | try { |
| 7317 | mSurface.hide(); |
| 7318 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7319 | Slog.w(TAG, "Error hiding surface in " + this, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7320 | } |
| 7321 | mLastHidden = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7322 | } |
| 7323 | mExiting = false; |
| 7324 | if (mRemoveOnExit) { |
| 7325 | mPendingRemove.add(this); |
| 7326 | mRemoveOnExit = false; |
| 7327 | } |
| 7328 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7329 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7330 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 7331 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 7332 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 7333 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 7334 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 7335 | return true; |
| 7336 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7337 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7338 | void computeShownFrameLocked() { |
| 7339 | final boolean selfTransformation = mHasLocalTransformation; |
| 7340 | Transformation attachedTransformation = |
| 7341 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 7342 | ? mAttachedWindow.mTransformation : null; |
| 7343 | Transformation appTransformation = |
| 7344 | (mAppToken != null && mAppToken.hasTransformation) |
| 7345 | ? mAppToken.transformation : null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7346 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7347 | // Wallpapers are animated based on the "real" window they |
| 7348 | // are currently targeting. |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7349 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7350 | && mWallpaperTarget != null) { |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7351 | if (mWallpaperTarget.mHasLocalTransformation && |
| 7352 | mWallpaperTarget.mAnimation != null && |
| 7353 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7354 | attachedTransformation = mWallpaperTarget.mTransformation; |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7355 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7356 | Slog.v(TAG, "WP target attached xform: " + attachedTransformation); |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7357 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7358 | } |
| 7359 | if (mWallpaperTarget.mAppToken != null && |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7360 | mWallpaperTarget.mAppToken.hasTransformation && |
| 7361 | mWallpaperTarget.mAppToken.animation != null && |
| 7362 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7363 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7364 | if (DEBUG_WALLPAPER && appTransformation != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7365 | Slog.v(TAG, "WP target app xform: " + appTransformation); |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7366 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7367 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7368 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7369 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7370 | if (selfTransformation || attachedTransformation != null |
| 7371 | || appTransformation != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7372 | // cache often used attributes locally |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7373 | final Rect frame = mFrame; |
| 7374 | final float tmpFloats[] = mTmpFloats; |
| 7375 | final Matrix tmpMatrix = mTmpMatrix; |
| 7376 | |
| 7377 | // Compute the desired transformation. |
Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7378 | tmpMatrix.setTranslate(0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7379 | if (selfTransformation) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7380 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7381 | } |
Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7382 | tmpMatrix.postTranslate(frame.left, frame.top); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7383 | if (attachedTransformation != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7384 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7385 | } |
| 7386 | if (appTransformation != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7387 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7388 | } |
| 7389 | |
| 7390 | // "convert" it into SurfaceFlinger's format |
| 7391 | // (a 2x2 matrix + an offset) |
| 7392 | // Here we must not transform the position of the surface |
| 7393 | // since it is already included in the transformation. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7394 | //Slog.i(TAG, "Transform: " + matrix); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7395 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7396 | tmpMatrix.getValues(tmpFloats); |
| 7397 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 7398 | mDtDx = tmpFloats[Matrix.MSKEW_X]; |
| 7399 | mDsDy = tmpFloats[Matrix.MSKEW_Y]; |
| 7400 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7401 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 7402 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7403 | int w = frame.width(); |
| 7404 | int h = frame.height(); |
| 7405 | mShownFrame.set(x, y, x+w, y+h); |
| 7406 | |
| 7407 | // Now set the alpha... but because our current hardware |
| 7408 | // can't do alpha transformation on a non-opaque surface, |
| 7409 | // turn it off if we are running an animation that is also |
| 7410 | // transforming since it is more important to have that |
| 7411 | // animation be smooth. |
| 7412 | mShownAlpha = mAlpha; |
| 7413 | if (!mLimitedAlphaCompositing |
| 7414 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 7415 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 7416 | && x == frame.left && y == frame.top))) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7417 | //Slog.i(TAG, "Applying alpha transform"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7418 | if (selfTransformation) { |
| 7419 | mShownAlpha *= mTransformation.getAlpha(); |
| 7420 | } |
| 7421 | if (attachedTransformation != null) { |
| 7422 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 7423 | } |
| 7424 | if (appTransformation != null) { |
| 7425 | mShownAlpha *= appTransformation.getAlpha(); |
| 7426 | } |
| 7427 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7428 | //Slog.i(TAG, "Not applying alpha transform"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7429 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7430 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7431 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7432 | TAG, "Continuing animation in " + this + |
| 7433 | ": " + mShownFrame + |
| 7434 | ", alpha=" + mTransformation.getAlpha()); |
| 7435 | return; |
| 7436 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7437 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7438 | mShownFrame.set(mFrame); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7439 | if (mXOffset != 0 || mYOffset != 0) { |
| 7440 | mShownFrame.offset(mXOffset, mYOffset); |
| 7441 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7442 | mShownAlpha = mAlpha; |
| 7443 | mDsDx = 1; |
| 7444 | mDtDx = 0; |
| 7445 | mDsDy = 0; |
| 7446 | mDtDy = 1; |
| 7447 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7448 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7449 | /** |
| 7450 | * Is this window visible? It is not visible if there is no |
| 7451 | * surface, or we are in the process of running an exit animation |
| 7452 | * that will remove the surface, or its app token has been hidden. |
| 7453 | */ |
| 7454 | public boolean isVisibleLw() { |
| 7455 | final AppWindowToken atoken = mAppToken; |
| 7456 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7457 | && (atoken == null || !atoken.hiddenRequested) |
| 7458 | && !mExiting && !mDestroying; |
| 7459 | } |
| 7460 | |
| 7461 | /** |
Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7462 | * Like {@link #isVisibleLw}, but also counts a window that is currently |
| 7463 | * "hidden" behind the keyguard as visible. This allows us to apply |
| 7464 | * things like window flags that impact the keyguard. |
| 7465 | * XXX I am starting to think we need to have ANOTHER visibility flag |
| 7466 | * for this "hidden behind keyguard" state rather than overloading |
| 7467 | * mPolicyVisibility. Ungh. |
| 7468 | */ |
| 7469 | public boolean isVisibleOrBehindKeyguardLw() { |
| 7470 | final AppWindowToken atoken = mAppToken; |
| 7471 | return mSurface != null && !mAttachedHidden |
| 7472 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7473 | && !mDrawPending && !mCommitDrawPending |
Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7474 | && !mExiting && !mDestroying; |
| 7475 | } |
| 7476 | |
| 7477 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7478 | * Is this window visible, ignoring its app token? It is not visible |
| 7479 | * if there is no surface, or we are in the process of running an exit animation |
| 7480 | * that will remove the surface. |
| 7481 | */ |
| 7482 | public boolean isWinVisibleLw() { |
| 7483 | final AppWindowToken atoken = mAppToken; |
| 7484 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7485 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 7486 | && !mExiting && !mDestroying; |
| 7487 | } |
| 7488 | |
| 7489 | /** |
| 7490 | * The same as isVisible(), but follows the current hidden state of |
| 7491 | * the associated app token, not the pending requested hidden state. |
| 7492 | */ |
| 7493 | boolean isVisibleNow() { |
| 7494 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7495 | && !mRootToken.hidden && !mExiting && !mDestroying; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7496 | } |
| 7497 | |
| 7498 | /** |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7499 | * Can this window possibly be a drag/drop target? The test here is |
| 7500 | * a combination of the above "visible now" with the check that the |
| 7501 | * Input Manager uses when discarding windows from input consideration. |
| 7502 | */ |
| 7503 | boolean isPotentialDragTarget() { |
| 7504 | return isVisibleNow() && (mInputChannel != null) && !mRemoved; |
| 7505 | } |
| 7506 | |
| 7507 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7508 | * Same as isVisible(), but we also count it as visible between the |
| 7509 | * call to IWindowSession.add() and the first relayout(). |
| 7510 | */ |
| 7511 | boolean isVisibleOrAdding() { |
| 7512 | final AppWindowToken atoken = mAppToken; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7513 | return ((mSurface != null && !mReportDestroySurface) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7514 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 7515 | && mPolicyVisibility && !mAttachedHidden |
| 7516 | && (atoken == null || !atoken.hiddenRequested) |
| 7517 | && !mExiting && !mDestroying; |
| 7518 | } |
| 7519 | |
| 7520 | /** |
| 7521 | * Is this window currently on-screen? It is on-screen either if it |
| 7522 | * is visible or it is currently running an animation before no longer |
| 7523 | * being visible. |
| 7524 | */ |
| 7525 | boolean isOnScreen() { |
| 7526 | final AppWindowToken atoken = mAppToken; |
| 7527 | if (atoken != null) { |
| 7528 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7529 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7530 | || mAnimation != null || atoken.animation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7531 | } else { |
| 7532 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7533 | && (!mAttachedHidden || mAnimation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7534 | } |
| 7535 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7536 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7537 | /** |
| 7538 | * Like isOnScreen(), but we don't return true if the window is part |
| 7539 | * of a transition that has not yet been started. |
| 7540 | */ |
| 7541 | boolean isReadyForDisplay() { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7542 | if (mRootToken.waitingToShow && |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 7543 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7544 | return false; |
| 7545 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7546 | final AppWindowToken atoken = mAppToken; |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7547 | final boolean animating = atoken != null |
| 7548 | ? (atoken.animation != null) : false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7549 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7550 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 7551 | && !mRootToken.hidden) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7552 | || mAnimation != null || animating); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7553 | } |
| 7554 | |
| 7555 | /** Is the window or its container currently animating? */ |
| 7556 | boolean isAnimating() { |
| 7557 | final WindowState attached = mAttachedWindow; |
| 7558 | final AppWindowToken atoken = mAppToken; |
| 7559 | return mAnimation != null |
| 7560 | || (attached != null && attached.mAnimation != null) |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7561 | || (atoken != null && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7562 | (atoken.animation != null |
| 7563 | || atoken.inPendingTransaction)); |
| 7564 | } |
| 7565 | |
| 7566 | /** Is this window currently animating? */ |
| 7567 | boolean isWindowAnimating() { |
| 7568 | return mAnimation != null; |
| 7569 | } |
| 7570 | |
| 7571 | /** |
| 7572 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 7573 | * been drawn. |
| 7574 | */ |
| 7575 | public boolean isDisplayedLw() { |
| 7576 | final AppWindowToken atoken = mAppToken; |
| 7577 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7578 | && !mDrawPending && !mCommitDrawPending |
| 7579 | && ((!mAttachedHidden && |
| 7580 | (atoken == null || !atoken.hiddenRequested)) |
| 7581 | || mAnimating); |
| 7582 | } |
| 7583 | |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7584 | /** |
| 7585 | * Returns true if the window has a surface that it has drawn a |
| 7586 | * complete UI in to. |
| 7587 | */ |
| 7588 | public boolean isDrawnLw() { |
| 7589 | final AppWindowToken atoken = mAppToken; |
| 7590 | return mSurface != null && !mDestroying |
| 7591 | && !mDrawPending && !mCommitDrawPending; |
| 7592 | } |
| 7593 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7594 | /** |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7595 | * Return true if the window is opaque and fully drawn. This indicates |
| 7596 | * it may obscure windows behind it. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7597 | */ |
| 7598 | boolean isOpaqueDrawn() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7599 | return (mAttrs.format == PixelFormat.OPAQUE |
| 7600 | || mAttrs.type == TYPE_WALLPAPER) |
| 7601 | && mSurface != null && mAnimation == null |
| 7602 | && (mAppToken == null || mAppToken.animation == null) |
| 7603 | && !mDrawPending && !mCommitDrawPending; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7604 | } |
| 7605 | |
| 7606 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 7607 | return |
| 7608 | // only if the application is requesting compatible window |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7609 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 7610 | // only if it's visible |
| 7611 | mHasDrawn && mViewVisibility == View.VISIBLE && |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7612 | // and only if the application fills the compatible screen |
| 7613 | mFrame.left <= mCompatibleScreenFrame.left && |
| 7614 | mFrame.top <= mCompatibleScreenFrame.top && |
| 7615 | mFrame.right >= mCompatibleScreenFrame.right && |
| 7616 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7617 | // and starting window do not need background filler |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7618 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7619 | } |
| 7620 | |
| 7621 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 7622 | return mFrame.left <= 0 && mFrame.top <= 0 && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7623 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7624 | } |
| 7625 | |
| 7626 | void removeLocked() { |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 7627 | disposeInputChannel(); |
| 7628 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7629 | if (mAttachedWindow != null) { |
| 7630 | mAttachedWindow.mChildWindows.remove(this); |
| 7631 | } |
| 7632 | destroySurfaceLocked(); |
| 7633 | mSession.windowRemovedLocked(); |
| 7634 | try { |
| 7635 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 7636 | } catch (RuntimeException e) { |
| 7637 | // Ignore if it has already been removed (usually because |
| 7638 | // we are doing this as part of processing a death note.) |
| 7639 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 7640 | } |
| 7641 | |
| 7642 | void disposeInputChannel() { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 7643 | if (mInputChannel != null) { |
| 7644 | mInputManager.unregisterInputChannel(mInputChannel); |
| 7645 | |
| 7646 | mInputChannel.dispose(); |
| 7647 | mInputChannel = null; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7648 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7649 | } |
| 7650 | |
| 7651 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 7652 | public void binderDied() { |
| 7653 | try { |
| 7654 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7655 | WindowState win = windowForClientLocked(mSession, mClient, false); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7656 | Slog.i(TAG, "WIN DEATH: " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7657 | if (win != null) { |
| 7658 | removeWindowLocked(mSession, win); |
| 7659 | } |
| 7660 | } |
| 7661 | } catch (IllegalArgumentException ex) { |
| 7662 | // This will happen if the window has already been |
| 7663 | // removed. |
| 7664 | } |
| 7665 | } |
| 7666 | } |
| 7667 | |
| 7668 | /** Returns true if this window desires key events. */ |
| 7669 | public final boolean canReceiveKeys() { |
| 7670 | return isVisibleOrAdding() |
| 7671 | && (mViewVisibility == View.VISIBLE) |
| 7672 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 7673 | } |
| 7674 | |
| 7675 | public boolean hasDrawnLw() { |
| 7676 | return mHasDrawn; |
| 7677 | } |
| 7678 | |
| 7679 | public boolean showLw(boolean doAnimation) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7680 | return showLw(doAnimation, true); |
| 7681 | } |
| 7682 | |
| 7683 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 7684 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 7685 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7686 | } |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7687 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7688 | if (doAnimation) { |
| 7689 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
| 7690 | + mPolicyVisibility + " mAnimation=" + mAnimation); |
| 7691 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 7692 | doAnimation = false; |
| 7693 | } else if (mPolicyVisibility && mAnimation == null) { |
| 7694 | // Check for the case where we are currently visible and |
| 7695 | // not animating; we do not want to do animation at such a |
| 7696 | // point to become visible when we already are. |
| 7697 | doAnimation = false; |
| 7698 | } |
| 7699 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7700 | mPolicyVisibility = true; |
| 7701 | mPolicyVisibilityAfterAnim = true; |
| 7702 | if (doAnimation) { |
| 7703 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 7704 | } |
| 7705 | if (requestAnim) { |
| 7706 | requestAnimationLocked(0); |
| 7707 | } |
| 7708 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7709 | } |
| 7710 | |
| 7711 | public boolean hideLw(boolean doAnimation) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7712 | return hideLw(doAnimation, true); |
| 7713 | } |
| 7714 | |
| 7715 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7716 | if (doAnimation) { |
| 7717 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 7718 | doAnimation = false; |
| 7719 | } |
| 7720 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7721 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 7722 | : mPolicyVisibility; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7723 | if (!current) { |
| 7724 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7725 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7726 | if (doAnimation) { |
| 7727 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 7728 | if (mAnimation == null) { |
| 7729 | doAnimation = false; |
| 7730 | } |
| 7731 | } |
| 7732 | if (doAnimation) { |
| 7733 | mPolicyVisibilityAfterAnim = false; |
| 7734 | } else { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7735 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7736 | mPolicyVisibilityAfterAnim = false; |
| 7737 | mPolicyVisibility = false; |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7738 | // Window is no longer visible -- make sure if we were waiting |
| 7739 | // for it to be displayed before enabling the display, that |
| 7740 | // we allow the display to be enabled now. |
| 7741 | enableScreenIfNeededLocked(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7742 | if (mCurrentFocus == this) { |
| 7743 | mFocusMayChange = true; |
| 7744 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7745 | } |
| 7746 | if (requestAnim) { |
| 7747 | requestAnimationLocked(0); |
| 7748 | } |
| 7749 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7750 | } |
| 7751 | |
| 7752 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7753 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 7754 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 7755 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 7756 | if (mAttachedWindow != null || mLayoutAttached) { |
| 7757 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 7758 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 7759 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7760 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 7761 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 7762 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7763 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 7764 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7765 | } |
| 7766 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 7767 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 7768 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 7769 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 7770 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 7771 | pw.print("="); pw.print(mAnimLayer); |
| 7772 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 7773 | if (mSurface != null) { |
| 7774 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7775 | pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown); |
| 7776 | pw.print(" layer="); pw.print(mSurfaceLayer); |
| 7777 | pw.print(" alpha="); pw.print(mSurfaceAlpha); |
| 7778 | pw.print(" rect=("); pw.print(mSurfaceX); |
| 7779 | pw.print(","); pw.print(mSurfaceY); |
| 7780 | pw.print(") "); pw.print(mSurfaceW); |
| 7781 | pw.print(" x "); pw.println(mSurfaceH); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7782 | } |
| 7783 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 7784 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 7785 | if (mAppToken != null) { |
| 7786 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 7787 | } |
| 7788 | if (mTargetAppToken != null) { |
| 7789 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 7790 | } |
| 7791 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 7792 | pw.print(Integer.toHexString(mViewVisibility)); |
| 7793 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7794 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 7795 | pw.print(" mObscured="); pw.println(mObscured); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7796 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 7797 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 7798 | pw.print(mPolicyVisibility); |
| 7799 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 7800 | pw.print(mPolicyVisibilityAfterAnim); |
| 7801 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 7802 | } |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 7803 | if (!mRelayoutCalled) { |
| 7804 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled); |
| 7805 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7806 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7807 | pw.print(" h="); pw.print(mRequestedHeight); |
| 7808 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7809 | if (mXOffset != 0 || mYOffset != 0) { |
| 7810 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 7811 | pw.print(" y="); pw.println(mYOffset); |
| 7812 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7813 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 7814 | mGivenContentInsets.printShortString(pw); |
| 7815 | pw.print(" mGivenVisibleInsets="); |
| 7816 | mGivenVisibleInsets.printShortString(pw); |
| 7817 | pw.println(); |
| 7818 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 7819 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 7820 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 7821 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7822 | pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7823 | pw.print(prefix); pw.print("mShownFrame="); |
| 7824 | mShownFrame.printShortString(pw); |
| 7825 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 7826 | pw.println(); |
| 7827 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 7828 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 7829 | pw.println(); |
| 7830 | pw.print(prefix); pw.print("mContainingFrame="); |
| 7831 | mContainingFrame.printShortString(pw); |
| 7832 | pw.print(" mDisplayFrame="); |
| 7833 | mDisplayFrame.printShortString(pw); |
| 7834 | pw.println(); |
| 7835 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 7836 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 7837 | pw.println(); |
| 7838 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 7839 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 7840 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 7841 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 7842 | pw.println(); |
| 7843 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 7844 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 7845 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 7846 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 7847 | } |
| 7848 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 7849 | || mAnimation != null) { |
| 7850 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 7851 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 7852 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 7853 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 7854 | } |
| 7855 | if (mHasTransformation || mHasLocalTransformation) { |
| 7856 | pw.print(prefix); pw.print("XForm: has="); |
| 7857 | pw.print(mHasTransformation); |
| 7858 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 7859 | pw.print(" "); mTransformation.printShortString(pw); |
| 7860 | pw.println(); |
| 7861 | } |
| 7862 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 7863 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 7864 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 7865 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 7866 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 7867 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 7868 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 7869 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 7870 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 7871 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7872 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7873 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 7874 | pw.print(mOrientationChanging); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7875 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 7876 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7877 | } |
Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 7878 | if (mHScale != 1 || mVScale != 1) { |
| 7879 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 7880 | pw.print(" mVScale="); pw.println(mVScale); |
| 7881 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7882 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7883 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 7884 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 7885 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 7886 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 7887 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 7888 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 7889 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7890 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7891 | |
| 7892 | String makeInputChannelName() { |
| 7893 | return Integer.toHexString(System.identityHashCode(this)) |
| 7894 | + " " + mAttrs.getTitle(); |
| 7895 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7896 | |
| 7897 | @Override |
| 7898 | public String toString() { |
| 7899 | return "Window{" |
| 7900 | + Integer.toHexString(System.identityHashCode(this)) |
| 7901 | + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}"; |
| 7902 | } |
| 7903 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7904 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7905 | // ------------------------------------------------------------- |
| 7906 | // Window Token State |
| 7907 | // ------------------------------------------------------------- |
| 7908 | |
| 7909 | class WindowToken { |
| 7910 | // The actual token. |
| 7911 | final IBinder token; |
| 7912 | |
| 7913 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 7914 | final int windowType; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7915 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7916 | // Set if this token was explicitly added by a client, so should |
| 7917 | // not be removed when all windows are removed. |
| 7918 | final boolean explicit; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7919 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7920 | // For printing. |
| 7921 | String stringName; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7922 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7923 | // If this is an AppWindowToken, this is non-null. |
| 7924 | AppWindowToken appWindowToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7925 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7926 | // All of the windows associated with this token. |
| 7927 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 7928 | |
| 7929 | // Is key dispatching paused for this token? |
| 7930 | boolean paused = false; |
| 7931 | |
| 7932 | // Should this token's windows be hidden? |
| 7933 | boolean hidden; |
| 7934 | |
| 7935 | // Temporary for finding which tokens no longer have visible windows. |
| 7936 | boolean hasVisible; |
| 7937 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7938 | // Set to true when this token is in a pending transaction where it |
| 7939 | // will be shown. |
| 7940 | boolean waitingToShow; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7941 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7942 | // Set to true when this token is in a pending transaction where it |
| 7943 | // will be hidden. |
| 7944 | boolean waitingToHide; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7945 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7946 | // Set to true when this token is in a pending transaction where its |
| 7947 | // windows will be put to the bottom of the list. |
| 7948 | boolean sendingToBottom; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7949 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7950 | // Set to true when this token is in a pending transaction where its |
| 7951 | // windows will be put to the top of the list. |
| 7952 | boolean sendingToTop; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7953 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7954 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 7955 | token = _token; |
| 7956 | windowType = type; |
| 7957 | explicit = _explicit; |
| 7958 | } |
| 7959 | |
| 7960 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7961 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 7962 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 7963 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 7964 | pw.print(" hidden="); pw.print(hidden); |
| 7965 | pw.print(" hasVisible="); pw.println(hasVisible); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7966 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 7967 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 7968 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 7969 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 7970 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 7971 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7972 | } |
| 7973 | |
| 7974 | @Override |
| 7975 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7976 | if (stringName == null) { |
| 7977 | StringBuilder sb = new StringBuilder(); |
| 7978 | sb.append("WindowToken{"); |
| 7979 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7980 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 7981 | stringName = sb.toString(); |
| 7982 | } |
| 7983 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7984 | } |
| 7985 | }; |
| 7986 | |
| 7987 | class AppWindowToken extends WindowToken { |
| 7988 | // Non-null only for application tokens. |
| 7989 | final IApplicationToken appToken; |
| 7990 | |
| 7991 | // All of the windows and child windows that are included in this |
| 7992 | // application token. Note this list is NOT sorted! |
| 7993 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 7994 | |
| 7995 | int groupId = -1; |
| 7996 | boolean appFullscreen; |
| 7997 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 7998 | |
| 7999 | // The input dispatching timeout for this application token in nanoseconds. |
| 8000 | long inputDispatchingTimeoutNanos; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8001 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8002 | // These are used for determining when all windows associated with |
| 8003 | // an activity have been drawn, so they can be made visible together |
| 8004 | // at the same time. |
| 8005 | int lastTransactionSequence = mTransactionSequence-1; |
| 8006 | int numInterestingWindows; |
| 8007 | int numDrawnWindows; |
| 8008 | boolean inPendingTransaction; |
| 8009 | boolean allDrawn; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8010 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8011 | // Is this token going to be hidden in a little while? If so, it |
| 8012 | // won't be taken into account for setting the screen orientation. |
| 8013 | boolean willBeHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8014 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8015 | // Is this window's surface needed? This is almost like hidden, except |
| 8016 | // it will sometimes be true a little earlier: when the token has |
| 8017 | // been shown, but is still waiting for its app transition to execute |
| 8018 | // before making its windows shown. |
| 8019 | boolean hiddenRequested; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8020 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8021 | // Have we told the window clients to hide themselves? |
| 8022 | boolean clientHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8023 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8024 | // Last visibility state we reported to the app token. |
| 8025 | boolean reportedVisible; |
| 8026 | |
| 8027 | // Set to true when the token has been removed from the window mgr. |
| 8028 | boolean removed; |
| 8029 | |
| 8030 | // Have we been asked to have this token keep the screen frozen? |
| 8031 | boolean freezingScreen; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8032 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8033 | boolean animating; |
| 8034 | Animation animation; |
| 8035 | boolean hasTransformation; |
| 8036 | final Transformation transformation = new Transformation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8037 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8038 | // Offset to the window of all layers in the token, for use by |
| 8039 | // AppWindowToken animations. |
| 8040 | int animLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8041 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8042 | // Information about an application starting window if displayed. |
| 8043 | StartingData startingData; |
| 8044 | WindowState startingWindow; |
| 8045 | View startingView; |
| 8046 | boolean startingDisplayed; |
| 8047 | boolean startingMoved; |
| 8048 | boolean firstWindowDrawn; |
| 8049 | |
| 8050 | AppWindowToken(IApplicationToken _token) { |
| 8051 | super(_token.asBinder(), |
| 8052 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 8053 | appWindowToken = this; |
| 8054 | appToken = _token; |
| 8055 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8056 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8057 | public void setAnimation(Animation anim) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8058 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8059 | TAG, "Setting animation in " + this + ": " + anim); |
| 8060 | animation = anim; |
| 8061 | animating = false; |
| 8062 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 8063 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 8064 | int zorder = anim.getZAdjustment(); |
| 8065 | int adj = 0; |
| 8066 | if (zorder == Animation.ZORDER_TOP) { |
| 8067 | adj = TYPE_LAYER_OFFSET; |
| 8068 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 8069 | adj = -TYPE_LAYER_OFFSET; |
| 8070 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8071 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8072 | if (animLayerAdjustment != adj) { |
| 8073 | animLayerAdjustment = adj; |
| 8074 | updateLayers(); |
| 8075 | } |
| 8076 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8077 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8078 | public void setDummyAnimation() { |
| 8079 | if (animation == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8080 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8081 | TAG, "Setting dummy animation in " + this); |
| 8082 | animation = sDummyAnimation; |
| 8083 | } |
| 8084 | } |
| 8085 | |
| 8086 | public void clearAnimation() { |
| 8087 | if (animation != null) { |
| 8088 | animation = null; |
| 8089 | animating = true; |
| 8090 | } |
| 8091 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8092 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8093 | void updateLayers() { |
| 8094 | final int N = allAppWindows.size(); |
| 8095 | final int adj = animLayerAdjustment; |
| 8096 | for (int i=0; i<N; i++) { |
| 8097 | WindowState w = allAppWindows.get(i); |
| 8098 | w.mAnimLayer = w.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8099 | if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8100 | + w.mAnimLayer); |
| 8101 | if (w == mInputMethodTarget) { |
| 8102 | setInputMethodAnimLayerAdjustment(adj); |
| 8103 | } |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8104 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8105 | setWallpaperAnimLayerAdjustmentLocked(adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8106 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8107 | } |
| 8108 | } |
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 | void sendAppVisibilityToClients() { |
| 8111 | final int N = allAppWindows.size(); |
| 8112 | for (int i=0; i<N; i++) { |
| 8113 | WindowState win = allAppWindows.get(i); |
| 8114 | if (win == startingWindow && clientHidden) { |
| 8115 | // Don't hide the starting window. |
| 8116 | continue; |
| 8117 | } |
| 8118 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8119 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8120 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 8121 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 8122 | } catch (RemoteException e) { |
| 8123 | } |
| 8124 | } |
| 8125 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8126 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8127 | void showAllWindowsLocked() { |
| 8128 | final int NW = allAppWindows.size(); |
| 8129 | for (int i=0; i<NW; i++) { |
| 8130 | WindowState w = allAppWindows.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8131 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8132 | "performing show on: " + w); |
| 8133 | w.performShowLocked(); |
| 8134 | } |
| 8135 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8136 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8137 | // This must be called while inside a transaction. |
| 8138 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8139 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8140 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8141 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8142 | if (animation == sDummyAnimation) { |
| 8143 | // This guy is going to animate, but not yet. For now count |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8144 | // it as not animating for purposes of scheduling transactions; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8145 | // when it is really time to animate, this will be set to |
| 8146 | // a real animation and the next call will execute normally. |
| 8147 | return false; |
| 8148 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8149 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8150 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 8151 | if (!animating) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8152 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8153 | TAG, "Starting animation in " + this + |
| 8154 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 8155 | + " scale=" + mTransitionAnimationScale |
| 8156 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 8157 | animation.initialize(dw, dh, dw, dh); |
| 8158 | animation.setStartTime(currentTime); |
| 8159 | animating = true; |
| 8160 | } |
| 8161 | transformation.clear(); |
| 8162 | final boolean more = animation.getTransformation( |
| 8163 | currentTime, transformation); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8164 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8165 | TAG, "Stepped animation in " + this + |
| 8166 | ": more=" + more + ", xform=" + transformation); |
| 8167 | if (more) { |
| 8168 | // we're done! |
| 8169 | hasTransformation = true; |
| 8170 | return true; |
| 8171 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8172 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8173 | TAG, "Finished animation in " + this + |
| 8174 | " @ " + currentTime); |
| 8175 | animation = null; |
| 8176 | } |
| 8177 | } else if (animation != null) { |
| 8178 | // If the display is frozen, and there is a pending animation, |
| 8179 | // clear it and make sure we run the cleanup code. |
| 8180 | animating = true; |
| 8181 | animation = null; |
| 8182 | } |
| 8183 | |
| 8184 | hasTransformation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8185 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8186 | if (!animating) { |
| 8187 | return false; |
| 8188 | } |
| 8189 | |
| 8190 | clearAnimation(); |
| 8191 | animating = false; |
| 8192 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 8193 | moveInputMethodWindowsIfNeededLocked(true); |
| 8194 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8195 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8196 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8197 | TAG, "Animation done in " + this |
| 8198 | + ": reportedVisible=" + reportedVisible); |
| 8199 | |
| 8200 | transformation.clear(); |
| 8201 | if (animLayerAdjustment != 0) { |
| 8202 | animLayerAdjustment = 0; |
| 8203 | updateLayers(); |
| 8204 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8205 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8206 | final int N = windows.size(); |
| 8207 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8208 | windows.get(i).finishExit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8209 | } |
| 8210 | updateReportedVisibilityLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8211 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8212 | return false; |
| 8213 | } |
| 8214 | |
| 8215 | void updateReportedVisibilityLocked() { |
| 8216 | if (appToken == null) { |
| 8217 | return; |
| 8218 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8219 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8220 | int numInteresting = 0; |
| 8221 | int numVisible = 0; |
| 8222 | boolean nowGone = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8223 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8224 | 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] | 8225 | final int N = allAppWindows.size(); |
| 8226 | for (int i=0; i<N; i++) { |
| 8227 | WindowState win = allAppWindows.get(i); |
Dianne Hackborn | 6cf67fa | 2009-12-21 16:46:34 -0800 | [diff] [blame] | 8228 | if (win == startingWindow || win.mAppFreezing |
The Android Open Source Project | 727cec0 | 2010-04-08 11:35:37 -0700 | [diff] [blame] | 8229 | || win.mViewVisibility != View.VISIBLE |
Ulf Rosdahl | 3935770 | 2010-09-29 12:34:38 +0200 | [diff] [blame] | 8230 | || win.mAttrs.type == TYPE_APPLICATION_STARTING |
| 8231 | || win.mDestroying) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8232 | continue; |
| 8233 | } |
| 8234 | if (DEBUG_VISIBILITY) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8235 | Slog.v(TAG, "Win " + win + ": isDrawn=" |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8236 | + win.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8237 | + ", isAnimating=" + win.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8238 | if (!win.isDrawnLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8239 | Slog.v(TAG, "Not displayed: s=" + win.mSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8240 | + " pv=" + win.mPolicyVisibility |
| 8241 | + " dp=" + win.mDrawPending |
| 8242 | + " cdp=" + win.mCommitDrawPending |
| 8243 | + " ah=" + win.mAttachedHidden |
| 8244 | + " th=" |
| 8245 | + (win.mAppToken != null |
| 8246 | ? win.mAppToken.hiddenRequested : false) |
| 8247 | + " a=" + win.mAnimating); |
| 8248 | } |
| 8249 | } |
| 8250 | numInteresting++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8251 | if (win.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8252 | if (!win.isAnimating()) { |
| 8253 | numVisible++; |
| 8254 | } |
| 8255 | nowGone = false; |
| 8256 | } else if (win.isAnimating()) { |
| 8257 | nowGone = false; |
| 8258 | } |
| 8259 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8260 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8261 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8262 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8263 | + numInteresting + " visible=" + numVisible); |
| 8264 | if (nowVisible != reportedVisible) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8265 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8266 | TAG, "Visibility changed in " + this |
| 8267 | + ": vis=" + nowVisible); |
| 8268 | reportedVisible = nowVisible; |
| 8269 | Message m = mH.obtainMessage( |
| 8270 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 8271 | nowVisible ? 1 : 0, |
| 8272 | nowGone ? 1 : 0, |
| 8273 | this); |
| 8274 | mH.sendMessage(m); |
| 8275 | } |
| 8276 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8277 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8278 | WindowState findMainWindow() { |
| 8279 | int j = windows.size(); |
| 8280 | while (j > 0) { |
| 8281 | j--; |
| 8282 | WindowState win = windows.get(j); |
| 8283 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 8284 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 8285 | return win; |
| 8286 | } |
| 8287 | } |
| 8288 | return null; |
| 8289 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8290 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8291 | void dump(PrintWriter pw, String prefix) { |
| 8292 | super.dump(pw, prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8293 | if (appToken != null) { |
| 8294 | pw.print(prefix); pw.println("app=true"); |
| 8295 | } |
| 8296 | if (allAppWindows.size() > 0) { |
| 8297 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 8298 | } |
| 8299 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8300 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8301 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 8302 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 8303 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 8304 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 8305 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 8306 | if (paused || freezingScreen) { |
| 8307 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 8308 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 8309 | } |
| 8310 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 8311 | || inPendingTransaction || allDrawn) { |
| 8312 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 8313 | pw.print(numInterestingWindows); |
| 8314 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 8315 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 8316 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 8317 | } |
| 8318 | if (animating || animation != null) { |
| 8319 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 8320 | pw.print(" animation="); pw.println(animation); |
| 8321 | } |
| 8322 | if (animLayerAdjustment != 0) { |
| 8323 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 8324 | } |
| 8325 | if (hasTransformation) { |
| 8326 | pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation); |
| 8327 | pw.print(" transformation="); transformation.printShortString(pw); |
| 8328 | pw.println(); |
| 8329 | } |
| 8330 | if (startingData != null || removed || firstWindowDrawn) { |
| 8331 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 8332 | pw.print(" removed="); pw.print(removed); |
| 8333 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 8334 | } |
| 8335 | if (startingWindow != null || startingView != null |
| 8336 | || startingDisplayed || startingMoved) { |
| 8337 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 8338 | pw.print(" startingView="); pw.print(startingView); |
| 8339 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 8340 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 8341 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8342 | } |
| 8343 | |
| 8344 | @Override |
| 8345 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8346 | if (stringName == null) { |
| 8347 | StringBuilder sb = new StringBuilder(); |
| 8348 | sb.append("AppWindowToken{"); |
| 8349 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8350 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8351 | stringName = sb.toString(); |
| 8352 | } |
| 8353 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8354 | } |
| 8355 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8356 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8357 | // ------------------------------------------------------------- |
| 8358 | // DummyAnimation |
| 8359 | // ------------------------------------------------------------- |
| 8360 | |
| 8361 | // This is an animation that does nothing: it just immediately finishes |
| 8362 | // itself every time it is called. It is used as a stub animation in cases |
| 8363 | // where we want to synchronize multiple things that may be animating. |
| 8364 | static final class DummyAnimation extends Animation { |
| 8365 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 8366 | return false; |
| 8367 | } |
| 8368 | } |
| 8369 | static final Animation sDummyAnimation = new DummyAnimation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8370 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8371 | // ------------------------------------------------------------- |
| 8372 | // Async Handler |
| 8373 | // ------------------------------------------------------------- |
| 8374 | |
| 8375 | static final class StartingData { |
| 8376 | final String pkg; |
| 8377 | final int theme; |
| 8378 | final CharSequence nonLocalizedLabel; |
| 8379 | final int labelRes; |
| 8380 | final int icon; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8381 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8382 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| 8383 | int _labelRes, int _icon) { |
| 8384 | pkg = _pkg; |
| 8385 | theme = _theme; |
| 8386 | nonLocalizedLabel = _nonLocalizedLabel; |
| 8387 | labelRes = _labelRes; |
| 8388 | icon = _icon; |
| 8389 | } |
| 8390 | } |
| 8391 | |
| 8392 | private final class H extends Handler { |
| 8393 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 8394 | public static final int REPORT_LOSING_FOCUS = 3; |
| 8395 | public static final int ANIMATE = 4; |
| 8396 | public static final int ADD_STARTING = 5; |
| 8397 | public static final int REMOVE_STARTING = 6; |
| 8398 | public static final int FINISHED_STARTING = 7; |
| 8399 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8400 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 8401 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 8402 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 8403 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 8404 | public static final int FORCE_GC = 15; |
| 8405 | public static final int ENABLE_SCREEN = 16; |
| 8406 | public static final int APP_FREEZE_TIMEOUT = 17; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8407 | public static final int SEND_NEW_CONFIGURATION = 18; |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8408 | public static final int REPORT_WINDOWS_CHANGE = 19; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8409 | public static final int DRAG_START_TIMEOUT = 20; |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 8410 | public static final int DRAG_END_TIMEOUT = 21; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8411 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8412 | private Session mLastReportedHold; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8413 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8414 | public H() { |
| 8415 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8416 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8417 | @Override |
| 8418 | public void handleMessage(Message msg) { |
| 8419 | switch (msg.what) { |
| 8420 | case REPORT_FOCUS_CHANGE: { |
| 8421 | WindowState lastFocus; |
| 8422 | WindowState newFocus; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8423 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8424 | synchronized(mWindowMap) { |
| 8425 | lastFocus = mLastFocus; |
| 8426 | newFocus = mCurrentFocus; |
| 8427 | if (lastFocus == newFocus) { |
| 8428 | // Focus is not changing, so nothing to do. |
| 8429 | return; |
| 8430 | } |
| 8431 | mLastFocus = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8432 | //Slog.i(TAG, "Focus moving from " + lastFocus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8433 | // + " to " + newFocus); |
| 8434 | if (newFocus != null && lastFocus != null |
| 8435 | && !newFocus.isDisplayedLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8436 | //Slog.i(TAG, "Delaying loss of focus..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8437 | mLosingFocus.add(lastFocus); |
| 8438 | lastFocus = null; |
| 8439 | } |
| 8440 | } |
| 8441 | |
| 8442 | if (lastFocus != newFocus) { |
| 8443 | //System.out.println("Changing focus from " + lastFocus |
| 8444 | // + " to " + newFocus); |
| 8445 | if (newFocus != null) { |
| 8446 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8447 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8448 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 8449 | } catch (RemoteException e) { |
| 8450 | // Ignore if process has died. |
| 8451 | } |
Konstantin Lopyrev | 5e7833a | 2010-08-09 17:01:11 -0700 | [diff] [blame] | 8452 | notifyFocusChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8453 | } |
| 8454 | |
| 8455 | if (lastFocus != null) { |
| 8456 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8457 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8458 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 8459 | } catch (RemoteException e) { |
| 8460 | // Ignore if process has died. |
| 8461 | } |
| 8462 | } |
| 8463 | } |
| 8464 | } break; |
| 8465 | |
| 8466 | case REPORT_LOSING_FOCUS: { |
| 8467 | ArrayList<WindowState> losers; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8468 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8469 | synchronized(mWindowMap) { |
| 8470 | losers = mLosingFocus; |
| 8471 | mLosingFocus = new ArrayList<WindowState>(); |
| 8472 | } |
| 8473 | |
| 8474 | final int N = losers.size(); |
| 8475 | for (int i=0; i<N; i++) { |
| 8476 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8477 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8478 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 8479 | } catch (RemoteException e) { |
| 8480 | // Ignore if process has died. |
| 8481 | } |
| 8482 | } |
| 8483 | } break; |
| 8484 | |
| 8485 | case ANIMATE: { |
| 8486 | synchronized(mWindowMap) { |
| 8487 | mAnimationPending = false; |
| 8488 | performLayoutAndPlaceSurfacesLocked(); |
| 8489 | } |
| 8490 | } break; |
| 8491 | |
| 8492 | case ADD_STARTING: { |
| 8493 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8494 | final StartingData sd = wtoken.startingData; |
| 8495 | |
| 8496 | if (sd == null) { |
| 8497 | // Animation has been canceled... do nothing. |
| 8498 | return; |
| 8499 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8500 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8501 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8502 | + wtoken + ": pkg=" + sd.pkg); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8503 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8504 | View view = null; |
| 8505 | try { |
| 8506 | view = mPolicy.addStartingWindow( |
| 8507 | wtoken.token, sd.pkg, |
| 8508 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| 8509 | sd.icon); |
| 8510 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8511 | Slog.w(TAG, "Exception when adding starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8512 | } |
| 8513 | |
| 8514 | if (view != null) { |
| 8515 | boolean abort = false; |
| 8516 | |
| 8517 | synchronized(mWindowMap) { |
| 8518 | if (wtoken.removed || wtoken.startingData == null) { |
| 8519 | // If the window was successfully added, then |
| 8520 | // we need to remove it. |
| 8521 | if (wtoken.startingWindow != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8522 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8523 | "Aborted starting " + wtoken |
| 8524 | + ": removed=" + wtoken.removed |
| 8525 | + " startingData=" + wtoken.startingData); |
| 8526 | wtoken.startingWindow = null; |
| 8527 | wtoken.startingData = null; |
| 8528 | abort = true; |
| 8529 | } |
| 8530 | } else { |
| 8531 | wtoken.startingView = view; |
| 8532 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8533 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8534 | "Added starting " + wtoken |
| 8535 | + ": startingWindow=" |
| 8536 | + wtoken.startingWindow + " startingView=" |
| 8537 | + wtoken.startingView); |
| 8538 | } |
| 8539 | |
| 8540 | if (abort) { |
| 8541 | try { |
| 8542 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 8543 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8544 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8545 | } |
| 8546 | } |
| 8547 | } |
| 8548 | } break; |
| 8549 | |
| 8550 | case REMOVE_STARTING: { |
| 8551 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8552 | IBinder token = null; |
| 8553 | View view = null; |
| 8554 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8555 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8556 | + wtoken + ": startingWindow=" |
| 8557 | + wtoken.startingWindow + " startingView=" |
| 8558 | + wtoken.startingView); |
| 8559 | if (wtoken.startingWindow != null) { |
| 8560 | view = wtoken.startingView; |
| 8561 | token = wtoken.token; |
| 8562 | wtoken.startingData = null; |
| 8563 | wtoken.startingView = null; |
| 8564 | wtoken.startingWindow = null; |
| 8565 | } |
| 8566 | } |
| 8567 | if (view != null) { |
| 8568 | try { |
| 8569 | mPolicy.removeStartingWindow(token, view); |
| 8570 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8571 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8572 | } |
| 8573 | } |
| 8574 | } break; |
| 8575 | |
| 8576 | case FINISHED_STARTING: { |
| 8577 | IBinder token = null; |
| 8578 | View view = null; |
| 8579 | while (true) { |
| 8580 | synchronized (mWindowMap) { |
| 8581 | final int N = mFinishedStarting.size(); |
| 8582 | if (N <= 0) { |
| 8583 | break; |
| 8584 | } |
| 8585 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 8586 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8587 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8588 | "Finished starting " + wtoken |
| 8589 | + ": startingWindow=" + wtoken.startingWindow |
| 8590 | + " startingView=" + wtoken.startingView); |
| 8591 | |
| 8592 | if (wtoken.startingWindow == null) { |
| 8593 | continue; |
| 8594 | } |
| 8595 | |
| 8596 | view = wtoken.startingView; |
| 8597 | token = wtoken.token; |
| 8598 | wtoken.startingData = null; |
| 8599 | wtoken.startingView = null; |
| 8600 | wtoken.startingWindow = null; |
| 8601 | } |
| 8602 | |
| 8603 | try { |
| 8604 | mPolicy.removeStartingWindow(token, view); |
| 8605 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8606 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8607 | } |
| 8608 | } |
| 8609 | } break; |
| 8610 | |
| 8611 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 8612 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8613 | |
| 8614 | boolean nowVisible = msg.arg1 != 0; |
| 8615 | boolean nowGone = msg.arg2 != 0; |
| 8616 | |
| 8617 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8618 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8619 | TAG, "Reporting visible in " + wtoken |
| 8620 | + " visible=" + nowVisible |
| 8621 | + " gone=" + nowGone); |
| 8622 | if (nowVisible) { |
| 8623 | wtoken.appToken.windowsVisible(); |
| 8624 | } else { |
| 8625 | wtoken.appToken.windowsGone(); |
| 8626 | } |
| 8627 | } catch (RemoteException ex) { |
| 8628 | } |
| 8629 | } break; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8630 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8631 | case WINDOW_FREEZE_TIMEOUT: { |
| 8632 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8633 | Slog.w(TAG, "Window freeze timeout expired."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8634 | int i = mWindows.size(); |
| 8635 | while (i > 0) { |
| 8636 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8637 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8638 | if (w.mOrientationChanging) { |
| 8639 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8640 | Slog.w(TAG, "Force clearing orientation change: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8641 | } |
| 8642 | } |
| 8643 | performLayoutAndPlaceSurfacesLocked(); |
| 8644 | } |
| 8645 | break; |
| 8646 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8647 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8648 | case HOLD_SCREEN_CHANGED: { |
| 8649 | Session oldHold; |
| 8650 | Session newHold; |
| 8651 | synchronized (mWindowMap) { |
| 8652 | oldHold = mLastReportedHold; |
| 8653 | newHold = (Session)msg.obj; |
| 8654 | mLastReportedHold = newHold; |
| 8655 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8656 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8657 | if (oldHold != newHold) { |
| 8658 | try { |
| 8659 | if (oldHold != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8660 | mBatteryStats.noteStopWakelock(oldHold.mUid, -1, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8661 | "window", |
| 8662 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8663 | } |
| 8664 | if (newHold != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8665 | mBatteryStats.noteStartWakelock(newHold.mUid, -1, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8666 | "window", |
| 8667 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8668 | } |
| 8669 | } catch (RemoteException e) { |
| 8670 | } |
| 8671 | } |
| 8672 | break; |
| 8673 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8674 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8675 | case APP_TRANSITION_TIMEOUT: { |
| 8676 | synchronized (mWindowMap) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8677 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8678 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8679 | "*** APP TRANSITION TIMEOUT"); |
| 8680 | mAppTransitionReady = true; |
| 8681 | mAppTransitionTimeout = true; |
| 8682 | performLayoutAndPlaceSurfacesLocked(); |
| 8683 | } |
| 8684 | } |
| 8685 | break; |
| 8686 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8687 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8688 | case PERSIST_ANIMATION_SCALE: { |
| 8689 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8690 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 8691 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8692 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 8693 | break; |
| 8694 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8695 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8696 | case FORCE_GC: { |
| 8697 | synchronized(mWindowMap) { |
| 8698 | if (mAnimationPending) { |
| 8699 | // If we are animating, don't do the gc now but |
| 8700 | // delay a bit so we don't interrupt the animation. |
| 8701 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 8702 | 2000); |
| 8703 | return; |
| 8704 | } |
| 8705 | // If we are currently rotating the display, it will |
| 8706 | // schedule a new message when done. |
| 8707 | if (mDisplayFrozen) { |
| 8708 | return; |
| 8709 | } |
| 8710 | mFreezeGcPending = 0; |
| 8711 | } |
| 8712 | Runtime.getRuntime().gc(); |
| 8713 | break; |
| 8714 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8715 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8716 | case ENABLE_SCREEN: { |
| 8717 | performEnableScreen(); |
| 8718 | break; |
| 8719 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8720 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8721 | case APP_FREEZE_TIMEOUT: { |
| 8722 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8723 | Slog.w(TAG, "App freeze timeout expired."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8724 | int i = mAppTokens.size(); |
| 8725 | while (i > 0) { |
| 8726 | i--; |
| 8727 | AppWindowToken tok = mAppTokens.get(i); |
| 8728 | if (tok.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8729 | Slog.w(TAG, "Force clearing freeze: " + tok); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8730 | unsetAppFreezingScreenLocked(tok, true, true); |
| 8731 | } |
| 8732 | } |
| 8733 | } |
| 8734 | break; |
| 8735 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8736 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8737 | case SEND_NEW_CONFIGURATION: { |
| 8738 | removeMessages(SEND_NEW_CONFIGURATION); |
| 8739 | sendNewConfiguration(); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8740 | break; |
| 8741 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8742 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8743 | case REPORT_WINDOWS_CHANGE: { |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8744 | if (mWindowsChanged) { |
| 8745 | synchronized (mWindowMap) { |
| 8746 | mWindowsChanged = false; |
| 8747 | } |
| 8748 | notifyWindowsChanged(); |
| 8749 | } |
| 8750 | break; |
| 8751 | } |
| 8752 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8753 | case DRAG_START_TIMEOUT: { |
| 8754 | IBinder win = (IBinder)msg.obj; |
| 8755 | if (DEBUG_DRAG) { |
| 8756 | Slog.w(TAG, "Timeout starting drag by win " + win); |
| 8757 | } |
| 8758 | synchronized (mWindowMap) { |
| 8759 | // !!! TODO: ANR the app that has failed to start the drag in time |
| 8760 | if (mDragState != null) { |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 8761 | mDragState.unregister(); |
| 8762 | mInputMonitor.updateInputWindowsLw(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8763 | mDragState.reset(); |
| 8764 | mDragState = null; |
| 8765 | } |
| 8766 | } |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 8767 | break; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8768 | } |
| 8769 | |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 8770 | case DRAG_END_TIMEOUT: { |
| 8771 | IBinder win = (IBinder)msg.obj; |
| 8772 | if (DEBUG_DRAG) { |
| 8773 | Slog.w(TAG, "Timeout ending drag to win " + win); |
| 8774 | } |
| 8775 | synchronized (mWindowMap) { |
| 8776 | // !!! TODO: ANR the drag-receiving app |
| 8777 | mDragState.mDragResult = false; |
| 8778 | mDragState.endDragLw(); |
| 8779 | } |
| 8780 | break; |
| 8781 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8782 | } |
| 8783 | } |
| 8784 | } |
| 8785 | |
| 8786 | // ------------------------------------------------------------- |
| 8787 | // IWindowManager API |
| 8788 | // ------------------------------------------------------------- |
| 8789 | |
| 8790 | public IWindowSession openSession(IInputMethodClient client, |
| 8791 | IInputContext inputContext) { |
| 8792 | if (client == null) throw new IllegalArgumentException("null client"); |
| 8793 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8794 | Session session = new Session(client, inputContext); |
| 8795 | return session; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8796 | } |
| 8797 | |
| 8798 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 8799 | synchronized (mWindowMap) { |
| 8800 | // The focus for the client is the window immediately below |
| 8801 | // where we would place the input method window. |
| 8802 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 8803 | WindowState imFocus; |
| 8804 | if (idx > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8805 | imFocus = mWindows.get(idx-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8806 | if (imFocus != null) { |
| 8807 | if (imFocus.mSession.mClient != null && |
| 8808 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 8809 | return true; |
| 8810 | } |
| 8811 | } |
| 8812 | } |
| 8813 | } |
| 8814 | return false; |
| 8815 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8816 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8817 | // ------------------------------------------------------------- |
| 8818 | // Internals |
| 8819 | // ------------------------------------------------------------- |
| 8820 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8821 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 8822 | boolean throwOnError) { |
| 8823 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8824 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8825 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8826 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 8827 | boolean throwOnError) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8828 | WindowState win = mWindowMap.get(client); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8829 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8830 | TAG, "Looking up client " + client + ": " + win); |
| 8831 | if (win == null) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8832 | RuntimeException ex = new IllegalArgumentException( |
| 8833 | "Requested window " + client + " does not exist"); |
| 8834 | if (throwOnError) { |
| 8835 | throw ex; |
| 8836 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8837 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8838 | return null; |
| 8839 | } |
| 8840 | if (session != null && win.mSession != session) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8841 | RuntimeException ex = new IllegalArgumentException( |
| 8842 | "Requested window " + client + " is in session " + |
| 8843 | win.mSession + ", not " + session); |
| 8844 | if (throwOnError) { |
| 8845 | throw ex; |
| 8846 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8847 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8848 | return null; |
| 8849 | } |
| 8850 | |
| 8851 | return win; |
| 8852 | } |
| 8853 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8854 | final void rebuildAppWindowListLocked() { |
| 8855 | int NW = mWindows.size(); |
| 8856 | int i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8857 | int lastWallpaper = -1; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8858 | int numRemoved = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8859 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8860 | // First remove all existing app windows. |
| 8861 | i=0; |
| 8862 | while (i < NW) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8863 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8864 | if (w.mAppToken != null) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8865 | WindowState win = mWindows.remove(i); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8866 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8867 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8868 | "Rebuild removing window: " + win); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8869 | NW--; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8870 | numRemoved++; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8871 | continue; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8872 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 8873 | && lastWallpaper == i-1) { |
| 8874 | lastWallpaper = i; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8875 | } |
| 8876 | i++; |
| 8877 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8878 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8879 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 8880 | // so skip them before adding app tokens. |
| 8881 | lastWallpaper++; |
| 8882 | i = lastWallpaper; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8883 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8884 | // First add all of the exiting app tokens... these are no longer |
| 8885 | // in the main app list, but still have windows shown. We put them |
| 8886 | // in the back because now that the animation is over we no longer |
| 8887 | // will care about them. |
| 8888 | int NT = mExitingAppTokens.size(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8889 | for (int j=0; j<NT; j++) { |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8890 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 8891 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8892 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8893 | // And add in the still active app tokens in Z order. |
| 8894 | NT = mAppTokens.size(); |
| 8895 | for (int j=0; j<NT; j++) { |
| 8896 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8897 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8898 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8899 | i -= lastWallpaper; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8900 | if (i != numRemoved) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8901 | Slog.w(TAG, "Rebuild removed " + numRemoved |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8902 | + " windows but added " + i); |
| 8903 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8904 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8905 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8906 | private final void assignLayersLocked() { |
| 8907 | int N = mWindows.size(); |
| 8908 | int curBaseLayer = 0; |
| 8909 | int curLayer = 0; |
| 8910 | int i; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8911 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8912 | for (i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8913 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8914 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 8915 | || (i > 0 && w.mIsWallpaper)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8916 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 8917 | w.mLayer = curLayer; |
| 8918 | } else { |
| 8919 | curBaseLayer = curLayer = w.mBaseLayer; |
| 8920 | w.mLayer = curLayer; |
| 8921 | } |
| 8922 | if (w.mTargetAppToken != null) { |
| 8923 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 8924 | } else if (w.mAppToken != null) { |
| 8925 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 8926 | } else { |
| 8927 | w.mAnimLayer = w.mLayer; |
| 8928 | } |
| 8929 | if (w.mIsImWindow) { |
| 8930 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8931 | } else if (w.mIsWallpaper) { |
| 8932 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8933 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8934 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8935 | + w.mAnimLayer); |
| 8936 | //System.out.println( |
| 8937 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 8938 | } |
| 8939 | } |
| 8940 | |
| 8941 | private boolean mInLayout = false; |
| 8942 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 8943 | if (mInLayout) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 8944 | if (DEBUG) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8945 | throw new RuntimeException("Recursive call!"); |
| 8946 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8947 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8948 | return; |
| 8949 | } |
| 8950 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8951 | if (mWaitingForConfig) { |
| 8952 | // Our configuration has changed (most likely rotation), but we |
| 8953 | // don't yet have the complete configuration to report to |
| 8954 | // applications. Don't do any window layout until we have it. |
| 8955 | return; |
| 8956 | } |
| 8957 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8958 | if (mDisplay == null) { |
| 8959 | // Not yet initialized, nothing to do. |
| 8960 | return; |
| 8961 | } |
| 8962 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8963 | boolean recoveringMemory = false; |
| 8964 | if (mForceRemoves != null) { |
| 8965 | recoveringMemory = true; |
| 8966 | // Wait a little it for things to settle down, and off we go. |
| 8967 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 8968 | WindowState ws = mForceRemoves.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8969 | Slog.i(TAG, "Force removing: " + ws); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8970 | removeWindowInnerLocked(ws.mSession, ws); |
| 8971 | } |
| 8972 | mForceRemoves = null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8973 | 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] | 8974 | Object tmp = new Object(); |
| 8975 | synchronized (tmp) { |
| 8976 | try { |
| 8977 | tmp.wait(250); |
| 8978 | } catch (InterruptedException e) { |
| 8979 | } |
| 8980 | } |
| 8981 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8982 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8983 | mInLayout = true; |
| 8984 | try { |
| 8985 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8986 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8987 | int i = mPendingRemove.size()-1; |
| 8988 | if (i >= 0) { |
| 8989 | while (i >= 0) { |
| 8990 | WindowState w = mPendingRemove.get(i); |
| 8991 | removeWindowInnerLocked(w.mSession, w); |
| 8992 | i--; |
| 8993 | } |
| 8994 | mPendingRemove.clear(); |
| 8995 | |
| 8996 | mInLayout = false; |
| 8997 | assignLayersLocked(); |
| 8998 | mLayoutNeeded = true; |
| 8999 | performLayoutAndPlaceSurfacesLocked(); |
| 9000 | |
| 9001 | } else { |
| 9002 | mInLayout = false; |
| 9003 | if (mLayoutNeeded) { |
| 9004 | requestAnimationLocked(0); |
| 9005 | } |
| 9006 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 9007 | if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) { |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 9008 | mH.removeMessages(H.REPORT_WINDOWS_CHANGE); |
| 9009 | mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE)); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 9010 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9011 | } catch (RuntimeException e) { |
| 9012 | mInLayout = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9013 | 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] | 9014 | } |
| 9015 | } |
| 9016 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9017 | private final int performLayoutLockedInner() { |
| 9018 | if (!mLayoutNeeded) { |
| 9019 | return 0; |
| 9020 | } |
| 9021 | |
| 9022 | mLayoutNeeded = false; |
| 9023 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9024 | final int dw = mDisplay.getWidth(); |
| 9025 | final int dh = mDisplay.getHeight(); |
| 9026 | |
| 9027 | final int N = mWindows.size(); |
| 9028 | int i; |
| 9029 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9030 | if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed=" |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 9031 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 9032 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9033 | mPolicy.beginLayoutLw(dw, dh); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9034 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9035 | int seq = mLayoutSeq+1; |
| 9036 | if (seq < 0) seq = 0; |
| 9037 | mLayoutSeq = seq; |
| 9038 | |
| 9039 | // First perform layout of any root windows (not attached |
| 9040 | // to another window). |
| 9041 | int topAttached = -1; |
| 9042 | for (i = N-1; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9043 | WindowState win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9044 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9045 | // Don't do layout of a window if it is not visible, or |
| 9046 | // soon won't be visible, to avoid wasting time and funky |
| 9047 | // changes while a window is animating away. |
| 9048 | final AppWindowToken atoken = win.mAppToken; |
| 9049 | final boolean gone = win.mViewVisibility == View.GONE |
| 9050 | || !win.mRelayoutCalled |
| 9051 | || win.mRootToken.hidden |
| 9052 | || (atoken != null && atoken.hiddenRequested) |
| 9053 | || win.mAttachedHidden |
| 9054 | || win.mExiting || win.mDestroying; |
| 9055 | |
| 9056 | if (!win.mLayoutAttached) { |
| 9057 | if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win |
| 9058 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 9059 | + " mLayoutAttached=" + win.mLayoutAttached); |
| 9060 | if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility=" |
| 9061 | + win.mViewVisibility + " mRelayoutCalled=" |
| 9062 | + win.mRelayoutCalled + " hidden=" |
| 9063 | + win.mRootToken.hidden + " hiddenRequested=" |
| 9064 | + (atoken != null && atoken.hiddenRequested) |
| 9065 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 9066 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9067 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9068 | // If this view is GONE, then skip it -- keep the current |
| 9069 | // frame, and let the caller know so they can ignore it |
| 9070 | // if they want. (We do the normal layout for INVISIBLE |
| 9071 | // windows, since that means "perform layout as normal, |
| 9072 | // just don't display"). |
| 9073 | if (!gone || !win.mHaveFrame) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9074 | if (!win.mLayoutAttached) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9075 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 9076 | win.mLayoutSeq = seq; |
| 9077 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 9078 | + win.mFrame + " mContainingFrame=" |
| 9079 | + win.mContainingFrame + " mDisplayFrame=" |
| 9080 | + win.mDisplayFrame); |
| 9081 | } else { |
| 9082 | if (topAttached < 0) topAttached = i; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9083 | } |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9084 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9085 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9086 | |
| 9087 | // Now perform layout of attached windows, which usually |
| 9088 | // depend on the position of the window they are attached to. |
| 9089 | // XXX does not deal with windows that are attached to windows |
| 9090 | // that are themselves attached. |
| 9091 | for (i = topAttached; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9092 | WindowState win = mWindows.get(i); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9093 | |
| 9094 | // If this view is GONE, then skip it -- keep the current |
| 9095 | // frame, and let the caller know so they can ignore it |
| 9096 | // if they want. (We do the normal layout for INVISIBLE |
| 9097 | // windows, since that means "perform layout as normal, |
| 9098 | // just don't display"). |
| 9099 | if (win.mLayoutAttached) { |
| 9100 | if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win |
| 9101 | + " mHaveFrame=" + win.mHaveFrame |
| 9102 | + " mViewVisibility=" + win.mViewVisibility |
| 9103 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
| 9104 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 9105 | || !win.mHaveFrame) { |
| 9106 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 9107 | win.mLayoutSeq = seq; |
| 9108 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 9109 | + win.mFrame + " mContainingFrame=" |
| 9110 | + win.mContainingFrame + " mDisplayFrame=" |
| 9111 | + win.mDisplayFrame); |
| 9112 | } |
| 9113 | } |
| 9114 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9115 | |
| 9116 | // Window frames may have changed. Tell the input dispatcher about it. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9117 | mInputMonitor.updateInputWindowsLw(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9118 | |
| 9119 | return mPolicy.finishLayoutLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9120 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9121 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9122 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 9123 | boolean recoveringMemory) { |
Joe Onorato | 34bcebc | 2010-07-07 18:05:01 -0400 | [diff] [blame] | 9124 | if (mDisplay == null) { |
| 9125 | Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay"); |
| 9126 | return; |
| 9127 | } |
| 9128 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9129 | final long currentTime = SystemClock.uptimeMillis(); |
| 9130 | final int dw = mDisplay.getWidth(); |
| 9131 | final int dh = mDisplay.getHeight(); |
| 9132 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9133 | int i; |
| 9134 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9135 | if (mFocusMayChange) { |
| 9136 | mFocusMayChange = false; |
| 9137 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 9138 | } |
| 9139 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9140 | // Initialize state of exiting tokens. |
| 9141 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9142 | mExitingTokens.get(i).hasVisible = false; |
| 9143 | } |
| 9144 | |
| 9145 | // Initialize state of exiting applications. |
| 9146 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9147 | mExitingAppTokens.get(i).hasVisible = false; |
| 9148 | } |
| 9149 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9150 | boolean orientationChangeComplete = true; |
| 9151 | Session holdScreen = null; |
| 9152 | float screenBrightness = -1; |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9153 | float buttonBrightness = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9154 | boolean focusDisplayed = false; |
| 9155 | boolean animating = false; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9156 | boolean createWatermark = false; |
| 9157 | |
| 9158 | if (mFxSession == null) { |
| 9159 | mFxSession = new SurfaceSession(); |
| 9160 | createWatermark = true; |
| 9161 | } |
| 9162 | |
| 9163 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9164 | |
| 9165 | Surface.openTransaction(); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9166 | |
| 9167 | if (createWatermark) { |
| 9168 | createWatermark(); |
| 9169 | } |
| 9170 | if (mWatermark != null) { |
| 9171 | mWatermark.positionSurface(dw, dh); |
| 9172 | } |
| 9173 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9174 | try { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9175 | boolean wallpaperForceHidingChanged = false; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9176 | int repeats = 0; |
| 9177 | int changes = 0; |
| 9178 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9179 | do { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9180 | repeats++; |
| 9181 | if (repeats > 6) { |
| 9182 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 9183 | mLayoutNeeded = false; |
| 9184 | break; |
| 9185 | } |
| 9186 | |
| 9187 | if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER |
| 9188 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG |
| 9189 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) { |
| 9190 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 9191 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 9192 | assignLayersLocked(); |
| 9193 | mLayoutNeeded = true; |
| 9194 | } |
| 9195 | } |
| 9196 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 9197 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
| 9198 | if (updateOrientationFromAppTokensLocked()) { |
| 9199 | mLayoutNeeded = true; |
| 9200 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 9201 | } |
| 9202 | } |
| 9203 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 9204 | mLayoutNeeded = true; |
| 9205 | } |
| 9206 | } |
| 9207 | |
| 9208 | // FIRST LOOP: Perform a layout, if needed. |
| 9209 | if (repeats < 4) { |
| 9210 | changes = performLayoutLockedInner(); |
| 9211 | if (changes != 0) { |
| 9212 | continue; |
| 9213 | } |
| 9214 | } else { |
| 9215 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 9216 | changes = 0; |
| 9217 | } |
| 9218 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9219 | final int transactionSequence = ++mTransactionSequence; |
| 9220 | |
| 9221 | // Update animations of all applications, including those |
| 9222 | // associated with exiting/removed apps |
| 9223 | boolean tokensAnimating = false; |
| 9224 | final int NAT = mAppTokens.size(); |
| 9225 | for (i=0; i<NAT; i++) { |
| 9226 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9227 | tokensAnimating = true; |
| 9228 | } |
| 9229 | } |
| 9230 | final int NEAT = mExitingAppTokens.size(); |
| 9231 | for (i=0; i<NEAT; i++) { |
| 9232 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9233 | tokensAnimating = true; |
| 9234 | } |
| 9235 | } |
| 9236 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9237 | // SECOND LOOP: Execute animations and update visibility of windows. |
| 9238 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9239 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq=" |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9240 | + transactionSequence + " tokensAnimating=" |
| 9241 | + tokensAnimating); |
| 9242 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9243 | animating = tokensAnimating; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9244 | |
| 9245 | boolean tokenMayBeDrawn = false; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9246 | boolean wallpaperMayChange = false; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9247 | boolean forceHiding = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9248 | |
| 9249 | mPolicy.beginAnimationLw(dw, dh); |
| 9250 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9251 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9252 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9253 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9254 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9255 | |
| 9256 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9257 | |
| 9258 | if (w.mSurface != null) { |
| 9259 | // Execute animation. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9260 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 9261 | if ((w.mAttrs.flags |
| 9262 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9263 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9264 | "First draw done in potential wallpaper target " + w); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9265 | wallpaperMayChange = true; |
| 9266 | } |
| 9267 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9268 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9269 | boolean wasAnimating = w.mAnimating; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9270 | if (w.stepAnimationLocked(currentTime, dw, dh)) { |
| 9271 | animating = true; |
| 9272 | //w.dump(" "); |
| 9273 | } |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9274 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 9275 | wallpaperMayChange = true; |
| 9276 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9277 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9278 | if (mPolicy.doesForceHide(w, attrs)) { |
| 9279 | if (!wasAnimating && animating) { |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9280 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 9281 | "Animation done that could impact force hide: " |
| 9282 | + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9283 | wallpaperForceHidingChanged = true; |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9284 | mFocusMayChange = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9285 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 9286 | forceHiding = true; |
| 9287 | } |
| 9288 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9289 | boolean changed; |
| 9290 | if (forceHiding) { |
| 9291 | changed = w.hideLw(false, false); |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9292 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9293 | "Now policy hidden: " + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9294 | } else { |
| 9295 | changed = w.showLw(false, false); |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9296 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9297 | "Now policy shown: " + w); |
| 9298 | if (changed) { |
| 9299 | if (wallpaperForceHidingChanged |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9300 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9301 | // Assume we will need to animate. If |
| 9302 | // we don't (because the wallpaper will |
| 9303 | // stay with the lock screen), then we will |
| 9304 | // clean up later. |
| 9305 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 9306 | if (a != null) { |
| 9307 | w.setAnimation(a); |
| 9308 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9309 | } |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9310 | if (mCurrentFocus == null || |
| 9311 | mCurrentFocus.mLayer < w.mLayer) { |
| 9312 | // We are showing on to of the current |
| 9313 | // focus, so re-evaluate focus to make |
| 9314 | // sure it is correct. |
| 9315 | mFocusMayChange = true; |
| 9316 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9317 | } |
| 9318 | } |
| 9319 | if (changed && (attrs.flags |
| 9320 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 9321 | wallpaperMayChange = true; |
| 9322 | } |
| 9323 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9324 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9325 | mPolicy.animatingWindowLw(w, attrs); |
| 9326 | } |
| 9327 | |
| 9328 | final AppWindowToken atoken = w.mAppToken; |
| 9329 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 9330 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 9331 | atoken.lastTransactionSequence = transactionSequence; |
| 9332 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 9333 | atoken.startingDisplayed = false; |
| 9334 | } |
| 9335 | if ((w.isOnScreen() || w.mAttrs.type |
| 9336 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 9337 | && !w.mExiting && !w.mDestroying) { |
| 9338 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9339 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9340 | + w.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9341 | + ", isAnimating=" + w.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9342 | if (!w.isDrawnLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9343 | Slog.v(TAG, "Not displayed: s=" + w.mSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9344 | + " pv=" + w.mPolicyVisibility |
| 9345 | + " dp=" + w.mDrawPending |
| 9346 | + " cdp=" + w.mCommitDrawPending |
| 9347 | + " ah=" + w.mAttachedHidden |
| 9348 | + " th=" + atoken.hiddenRequested |
| 9349 | + " a=" + w.mAnimating); |
| 9350 | } |
| 9351 | } |
| 9352 | if (w != atoken.startingWindow) { |
| 9353 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 9354 | atoken.numInterestingWindows++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9355 | if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9356 | atoken.numDrawnWindows++; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9357 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9358 | "tokenMayBeDrawn: " + atoken |
| 9359 | + " freezingScreen=" + atoken.freezingScreen |
| 9360 | + " mAppFreezing=" + w.mAppFreezing); |
| 9361 | tokenMayBeDrawn = true; |
| 9362 | } |
| 9363 | } |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9364 | } else if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9365 | atoken.startingDisplayed = true; |
| 9366 | } |
| 9367 | } |
| 9368 | } else if (w.mReadyToShow) { |
| 9369 | w.performShowLocked(); |
| 9370 | } |
| 9371 | } |
| 9372 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9373 | changes |= mPolicy.finishAnimationLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9374 | |
| 9375 | if (tokenMayBeDrawn) { |
| 9376 | // See if any windows have been drawn, so they (and others |
| 9377 | // associated with them) can now be shown. |
| 9378 | final int NT = mTokenList.size(); |
| 9379 | for (i=0; i<NT; i++) { |
| 9380 | AppWindowToken wtoken = mTokenList.get(i).appWindowToken; |
| 9381 | if (wtoken == null) { |
| 9382 | continue; |
| 9383 | } |
| 9384 | if (wtoken.freezingScreen) { |
| 9385 | int numInteresting = wtoken.numInterestingWindows; |
| 9386 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9387 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9388 | "allDrawn: " + wtoken |
| 9389 | + " interesting=" + numInteresting |
| 9390 | + " drawn=" + wtoken.numDrawnWindows); |
| 9391 | wtoken.showAllWindowsLocked(); |
| 9392 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 9393 | orientationChangeComplete = true; |
| 9394 | } |
| 9395 | } else if (!wtoken.allDrawn) { |
| 9396 | int numInteresting = wtoken.numInterestingWindows; |
| 9397 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9398 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9399 | "allDrawn: " + wtoken |
| 9400 | + " interesting=" + numInteresting |
| 9401 | + " drawn=" + wtoken.numDrawnWindows); |
| 9402 | wtoken.allDrawn = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9403 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9404 | |
| 9405 | // We can now show all of the drawn windows! |
| 9406 | if (!mOpeningApps.contains(wtoken)) { |
| 9407 | wtoken.showAllWindowsLocked(); |
| 9408 | } |
| 9409 | } |
| 9410 | } |
| 9411 | } |
| 9412 | } |
| 9413 | |
| 9414 | // If we are ready to perform an app transition, check through |
| 9415 | // all of the app tokens to be shown and see if they are ready |
| 9416 | // to go. |
| 9417 | if (mAppTransitionReady) { |
| 9418 | int NN = mOpeningApps.size(); |
| 9419 | boolean goodToGo = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9420 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9421 | "Checking " + NN + " opening apps (frozen=" |
| 9422 | + mDisplayFrozen + " timeout=" |
| 9423 | + mAppTransitionTimeout + ")..."); |
| 9424 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 9425 | // If the display isn't frozen, wait to do anything until |
| 9426 | // all of the apps are ready. Otherwise just go because |
| 9427 | // we'll unfreeze the display when everyone is ready. |
| 9428 | for (i=0; i<NN && goodToGo; i++) { |
| 9429 | AppWindowToken wtoken = mOpeningApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9430 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9431 | "Check opening app" + wtoken + ": allDrawn=" |
| 9432 | + wtoken.allDrawn + " startingDisplayed=" |
| 9433 | + wtoken.startingDisplayed); |
| 9434 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 9435 | && !wtoken.startingMoved) { |
| 9436 | goodToGo = false; |
| 9437 | } |
| 9438 | } |
| 9439 | } |
| 9440 | if (goodToGo) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9441 | 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] | 9442 | int transit = mNextAppTransition; |
| 9443 | if (mSkipAppTransitionAnimation) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9444 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9445 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9446 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9447 | mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9448 | mAppTransitionRunning = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9449 | mAppTransitionTimeout = false; |
| 9450 | mStartingIconInTransition = false; |
| 9451 | mSkipAppTransitionAnimation = false; |
| 9452 | |
| 9453 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 9454 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9455 | // If there are applications waiting to come to the |
| 9456 | // top of the stack, now is the time to move their windows. |
| 9457 | // (Note that we don't do apps going to the bottom |
| 9458 | // here -- we want to keep their windows in the old |
| 9459 | // Z-order until the animation completes.) |
| 9460 | if (mToTopApps.size() > 0) { |
| 9461 | NN = mAppTokens.size(); |
| 9462 | for (i=0; i<NN; i++) { |
| 9463 | AppWindowToken wtoken = mAppTokens.get(i); |
| 9464 | if (wtoken.sendingToTop) { |
| 9465 | wtoken.sendingToTop = false; |
| 9466 | moveAppWindowsLocked(wtoken, NN, false); |
| 9467 | } |
| 9468 | } |
| 9469 | mToTopApps.clear(); |
| 9470 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9471 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9472 | WindowState oldWallpaper = mWallpaperTarget; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9473 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9474 | adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9475 | wallpaperMayChange = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9476 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9477 | // The top-most window will supply the layout params, |
| 9478 | // and we will determine it below. |
| 9479 | LayoutParams animLp = null; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9480 | AppWindowToken animToken = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9481 | int bestAnimLayer = -1; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9482 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9483 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9484 | "New wallpaper target=" + mWallpaperTarget |
| 9485 | + ", lower target=" + mLowerWallpaperTarget |
| 9486 | + ", upper target=" + mUpperWallpaperTarget); |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9487 | int foundWallpapers = 0; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9488 | // Do a first pass through the tokens for two |
| 9489 | // things: |
| 9490 | // (1) Determine if both the closing and opening |
| 9491 | // app token sets are wallpaper targets, in which |
| 9492 | // case special animations are needed |
| 9493 | // (since the wallpaper needs to stay static |
| 9494 | // behind them). |
| 9495 | // (2) Find the layout params of the top-most |
| 9496 | // application window in the tokens, which is |
| 9497 | // what will control the animation theme. |
| 9498 | final int NC = mClosingApps.size(); |
| 9499 | NN = NC + mOpeningApps.size(); |
| 9500 | for (i=0; i<NN; i++) { |
| 9501 | AppWindowToken wtoken; |
| 9502 | int mode; |
| 9503 | if (i < NC) { |
| 9504 | wtoken = mClosingApps.get(i); |
| 9505 | mode = 1; |
| 9506 | } else { |
| 9507 | wtoken = mOpeningApps.get(i-NC); |
| 9508 | mode = 2; |
| 9509 | } |
| 9510 | if (mLowerWallpaperTarget != null) { |
| 9511 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 9512 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 9513 | foundWallpapers |= mode; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9514 | } |
| 9515 | } |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9516 | if (wtoken.appFullscreen) { |
| 9517 | WindowState ws = wtoken.findMainWindow(); |
| 9518 | if (ws != null) { |
| 9519 | // If this is a compatibility mode |
| 9520 | // window, we will always use its anim. |
| 9521 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 9522 | animLp = ws.mAttrs; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9523 | animToken = ws.mAppToken; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9524 | bestAnimLayer = Integer.MAX_VALUE; |
| 9525 | } else if (ws.mLayer > bestAnimLayer) { |
| 9526 | animLp = ws.mAttrs; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9527 | animToken = ws.mAppToken; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9528 | bestAnimLayer = ws.mLayer; |
| 9529 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9530 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9531 | } |
| 9532 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9533 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9534 | if (foundWallpapers == 3) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9535 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9536 | "Wallpaper animation!"); |
| 9537 | switch (transit) { |
| 9538 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 9539 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 9540 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 9541 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 9542 | break; |
| 9543 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 9544 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 9545 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 9546 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 9547 | break; |
| 9548 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9549 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9550 | "New transit: " + transit); |
| 9551 | } else if (oldWallpaper != null) { |
| 9552 | // We are transitioning from an activity with |
| 9553 | // a wallpaper to one without. |
| 9554 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9555 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9556 | "New transit away from wallpaper: " + transit); |
| 9557 | } else if (mWallpaperTarget != null) { |
| 9558 | // We are transitioning from an activity without |
| 9559 | // a wallpaper to now showing the wallpaper |
| 9560 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9561 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9562 | "New transit into wallpaper: " + transit); |
| 9563 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9564 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9565 | if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) { |
| 9566 | mLastEnterAnimToken = animToken; |
| 9567 | mLastEnterAnimParams = animLp; |
| 9568 | } else if (mLastEnterAnimParams != null) { |
| 9569 | animLp = mLastEnterAnimParams; |
| 9570 | mLastEnterAnimToken = null; |
| 9571 | mLastEnterAnimParams = null; |
| 9572 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9573 | |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9574 | // If all closing windows are obscured, then there is |
| 9575 | // no need to do an animation. This is the case, for |
| 9576 | // example, when this transition is being done behind |
| 9577 | // the lock screen. |
| 9578 | if (!mPolicy.allowAppAnimationsLw()) { |
| 9579 | animLp = null; |
| 9580 | } |
| 9581 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9582 | NN = mOpeningApps.size(); |
| 9583 | for (i=0; i<NN; i++) { |
| 9584 | AppWindowToken wtoken = mOpeningApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9585 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9586 | "Now opening app" + wtoken); |
| 9587 | wtoken.reportedVisible = false; |
| 9588 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9589 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9590 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9591 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9592 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9593 | wtoken.showAllWindowsLocked(); |
| 9594 | } |
| 9595 | NN = mClosingApps.size(); |
| 9596 | for (i=0; i<NN; i++) { |
| 9597 | AppWindowToken wtoken = mClosingApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9598 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9599 | "Now closing app" + wtoken); |
| 9600 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9601 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9602 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9603 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9604 | wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9605 | // Force the allDrawn flag, because we want to start |
| 9606 | // this guy's animations regardless of whether it's |
| 9607 | // gotten drawn. |
| 9608 | wtoken.allDrawn = true; |
| 9609 | } |
| 9610 | |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 9611 | mNextAppTransitionPackage = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9612 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9613 | mOpeningApps.clear(); |
| 9614 | mClosingApps.clear(); |
| 9615 | |
| 9616 | // This has changed the visibility of windows, so perform |
| 9617 | // a new layout to get them all up-to-date. |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9618 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9619 | mLayoutNeeded = true; |
Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 9620 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 9621 | assignLayersLocked(); |
| 9622 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9623 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9624 | mFocusMayChange = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9625 | } |
| 9626 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9627 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9628 | int adjResult = 0; |
| 9629 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9630 | if (!animating && mAppTransitionRunning) { |
| 9631 | // We have finished the animation of an app transition. To do |
| 9632 | // this, we have delayed a lot of operations like showing and |
| 9633 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 9634 | // reflects the correct Z-order, but the window list may now |
| 9635 | // be out of sync with it. So here we will just rebuild the |
| 9636 | // entire app window list. Fun! |
| 9637 | mAppTransitionRunning = false; |
| 9638 | // Clear information about apps that were moving. |
| 9639 | mToBottomApps.clear(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9640 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9641 | rebuildAppWindowListLocked(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9642 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9643 | adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9644 | moveInputMethodWindowsIfNeededLocked(false); |
| 9645 | wallpaperMayChange = true; |
Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 9646 | // Since the window list has been rebuilt, focus might |
| 9647 | // have to be recomputed since the actual order of windows |
| 9648 | // might have changed again. |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9649 | mFocusMayChange = true; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9650 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9651 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9652 | if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9653 | // At this point, there was a window with a wallpaper that |
| 9654 | // was force hiding other windows behind it, but now it |
| 9655 | // is going away. This may be simple -- just animate |
| 9656 | // away the wallpaper and its window -- or it may be |
| 9657 | // hard -- the wallpaper now needs to be shown behind |
| 9658 | // something that was hidden. |
| 9659 | WindowState oldWallpaper = mWallpaperTarget; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9660 | if (mLowerWallpaperTarget != null |
| 9661 | && mLowerWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9662 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9663 | "wallpaperForceHiding changed with lower=" |
| 9664 | + mLowerWallpaperTarget); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9665 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9666 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 9667 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 9668 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 9669 | // The lower target has become hidden before we |
| 9670 | // actually started the animation... let's completely |
| 9671 | // re-evaluate everything. |
| 9672 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9673 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9674 | } |
| 9675 | } |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9676 | adjResult |= adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9677 | wallpaperMayChange = false; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9678 | wallpaperForceHidingChanged = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9679 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9680 | + " NEW: " + mWallpaperTarget |
| 9681 | + " LOWER: " + mLowerWallpaperTarget); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9682 | if (mLowerWallpaperTarget == null) { |
| 9683 | // Whoops, we don't need a special wallpaper animation. |
| 9684 | // Clear them out. |
| 9685 | forceHiding = false; |
| 9686 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9687 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9688 | if (w.mSurface != null) { |
| 9689 | final WindowManager.LayoutParams attrs = w.mAttrs; |
Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 9690 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9691 | if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9692 | forceHiding = true; |
| 9693 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9694 | if (!w.mAnimating) { |
| 9695 | // We set the animation above so it |
| 9696 | // is not yet running. |
| 9697 | w.clearAnimation(); |
| 9698 | } |
| 9699 | } |
| 9700 | } |
| 9701 | } |
| 9702 | } |
| 9703 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9704 | |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9705 | if (wallpaperMayChange) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9706 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9707 | "Wallpaper may change! Adjusting"); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9708 | adjResult |= adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9709 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9710 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9711 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9712 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9713 | "Wallpaper layer changed: assigning layers + relayout"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9714 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9715 | assignLayersLocked(); |
| 9716 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9717 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9718 | "Wallpaper visibility changed: relayout"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9719 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9720 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9721 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9722 | if (mFocusMayChange) { |
| 9723 | mFocusMayChange = false; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9724 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9725 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9726 | adjResult = 0; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9727 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9728 | } |
| 9729 | |
| 9730 | if (mLayoutNeeded) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9731 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9732 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9733 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9734 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x" |
| 9735 | + Integer.toHexString(changes)); |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9736 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9737 | mInputMonitor.updateInputWindowsLw(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9738 | } while (changes != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9739 | |
| 9740 | // THIRD LOOP: Update the surfaces of all windows. |
| 9741 | |
| 9742 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 9743 | |
| 9744 | boolean obscured = false; |
| 9745 | boolean blurring = false; |
| 9746 | boolean dimming = false; |
| 9747 | boolean covered = false; |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9748 | boolean syswin = false; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9749 | boolean backgroundFillerShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9750 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9751 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9752 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9753 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9754 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9755 | |
| 9756 | boolean displayed = false; |
| 9757 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9758 | final int attrFlags = attrs.flags; |
| 9759 | |
| 9760 | if (w.mSurface != null) { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9761 | // XXX NOTE: The logic here could be improved. We have |
| 9762 | // the decision about whether to resize a window separated |
| 9763 | // from whether to hide the surface. This can cause us to |
| 9764 | // resize a surface even if we are going to hide it. You |
| 9765 | // can see this by (1) holding device in landscape mode on |
| 9766 | // home screen; (2) tapping browser icon (device will rotate |
| 9767 | // to landscape; (3) tap home. The wallpaper will be resized |
| 9768 | // in step 2 but then immediately hidden, causing us to |
| 9769 | // have to resize and then redraw it again in step 3. It |
| 9770 | // would be nice to figure out how to avoid this, but it is |
| 9771 | // difficult because we do need to resize surfaces in some |
| 9772 | // cases while they are hidden such as when first showing a |
| 9773 | // window. |
| 9774 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9775 | w.computeShownFrameLocked(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9776 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9777 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 9778 | + ": new=" + w.mShownFrame + ", old=" |
| 9779 | + w.mLastShownFrame); |
| 9780 | |
| 9781 | boolean resize; |
| 9782 | int width, height; |
| 9783 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 9784 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 9785 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 9786 | // for a scaled surface, we just want to use |
| 9787 | // the requested size. |
| 9788 | width = w.mRequestedWidth; |
| 9789 | height = w.mRequestedHeight; |
| 9790 | w.mLastRequestedWidth = width; |
| 9791 | w.mLastRequestedHeight = height; |
| 9792 | w.mLastShownFrame.set(w.mShownFrame); |
| 9793 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9794 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9795 | "POS " + w.mShownFrame.left |
| 9796 | + ", " + w.mShownFrame.top, null); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9797 | w.mSurfaceX = w.mShownFrame.left; |
| 9798 | w.mSurfaceY = w.mShownFrame.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9799 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 9800 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9801 | Slog.w(TAG, "Error positioning surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9802 | if (!recoveringMemory) { |
| 9803 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 9804 | } |
| 9805 | } |
| 9806 | } else { |
| 9807 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 9808 | width = w.mShownFrame.width(); |
| 9809 | height = w.mShownFrame.height(); |
| 9810 | w.mLastShownFrame.set(w.mShownFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9811 | } |
| 9812 | |
| 9813 | if (resize) { |
| 9814 | if (width < 1) width = 1; |
| 9815 | if (height < 1) height = 1; |
| 9816 | if (w.mSurface != null) { |
| 9817 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9818 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9819 | "POS " + w.mShownFrame.left + "," |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9820 | + w.mShownFrame.top + " SIZE " |
| 9821 | + w.mShownFrame.width() + "x" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9822 | + w.mShownFrame.height(), null); |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9823 | w.mSurfaceResized = true; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9824 | w.mSurfaceW = width; |
| 9825 | w.mSurfaceH = height; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9826 | w.mSurface.setSize(width, height); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9827 | w.mSurfaceX = w.mShownFrame.left; |
| 9828 | w.mSurfaceY = w.mShownFrame.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9829 | w.mSurface.setPosition(w.mShownFrame.left, |
| 9830 | w.mShownFrame.top); |
| 9831 | } catch (RuntimeException e) { |
| 9832 | // If something goes wrong with the surface (such |
| 9833 | // as running out of memory), don't take down the |
| 9834 | // entire system. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9835 | Slog.e(TAG, "Failure updating surface of " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9836 | + "size=(" + width + "x" + height |
| 9837 | + "), pos=(" + w.mShownFrame.left |
| 9838 | + "," + w.mShownFrame.top + ")", e); |
| 9839 | if (!recoveringMemory) { |
| 9840 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 9841 | } |
| 9842 | } |
| 9843 | } |
| 9844 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9845 | if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9846 | w.mContentInsetsChanged = |
| 9847 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 9848 | w.mVisibleInsetsChanged = |
| 9849 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9850 | boolean configChanged = |
| 9851 | w.mConfiguration != mCurConfiguration |
| 9852 | && (w.mConfiguration == null |
| 9853 | || mCurConfiguration.diff(w.mConfiguration) != 0); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9854 | if (DEBUG_CONFIGURATION && configChanged) { |
| 9855 | Slog.v(TAG, "Win " + w + " config changed: " |
| 9856 | + mCurConfiguration); |
| 9857 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9858 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9859 | + ": configChanged=" + configChanged |
| 9860 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9861 | if (!w.mLastFrame.equals(w.mFrame) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9862 | || w.mContentInsetsChanged |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9863 | || w.mVisibleInsetsChanged |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9864 | || w.mSurfaceResized |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9865 | || configChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9866 | w.mLastFrame.set(w.mFrame); |
| 9867 | w.mLastContentInsets.set(w.mContentInsets); |
| 9868 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9869 | // If the screen is currently frozen, then keep |
| 9870 | // it frozen until this window draws at its new |
| 9871 | // orientation. |
| 9872 | if (mDisplayFrozen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9873 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9874 | "Resizing while display frozen: " + w); |
| 9875 | w.mOrientationChanging = true; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9876 | if (!mWindowsFreezingScreen) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9877 | mWindowsFreezingScreen = true; |
| 9878 | // XXX should probably keep timeout from |
| 9879 | // when we first froze the display. |
| 9880 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 9881 | mH.sendMessageDelayed(mH.obtainMessage( |
| 9882 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 9883 | } |
| 9884 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9885 | // If the orientation is changing, then we need to |
| 9886 | // hold off on unfreezing the display until this |
| 9887 | // window has been redrawn; to do that, we need |
| 9888 | // to go through the process of getting informed |
| 9889 | // by the application when it has finished drawing. |
| 9890 | if (w.mOrientationChanging) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9891 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9892 | "Orientation start waiting for draw in " |
| 9893 | + w + ", surface " + w.mSurface); |
| 9894 | w.mDrawPending = true; |
| 9895 | w.mCommitDrawPending = false; |
| 9896 | w.mReadyToShow = false; |
| 9897 | if (w.mAppToken != null) { |
| 9898 | w.mAppToken.allDrawn = false; |
| 9899 | } |
| 9900 | } |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9901 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9902 | "Resizing window " + w + " to " + w.mFrame); |
| 9903 | mResizingWindows.add(w); |
| 9904 | } else if (w.mOrientationChanging) { |
| 9905 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9906 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9907 | "Orientation not waiting for draw in " |
| 9908 | + w + ", surface " + w.mSurface); |
| 9909 | w.mOrientationChanging = false; |
| 9910 | } |
| 9911 | } |
| 9912 | } |
| 9913 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9914 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9915 | if (!w.mLastHidden) { |
| 9916 | //dump(); |
| 9917 | w.mLastHidden = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9918 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9919 | "HIDE (performLayout)", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9920 | if (w.mSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9921 | w.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9922 | try { |
| 9923 | w.mSurface.hide(); |
| 9924 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9925 | Slog.w(TAG, "Exception hiding surface in " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9926 | } |
| 9927 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9928 | } |
| 9929 | // If we are waiting for this window to handle an |
| 9930 | // orientation change, well, it is hidden, so |
| 9931 | // doesn't really matter. Note that this does |
| 9932 | // introduce a potential glitch if the window |
| 9933 | // becomes unhidden before it has drawn for the |
| 9934 | // new orientation. |
| 9935 | if (w.mOrientationChanging) { |
| 9936 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9937 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9938 | "Orientation change skips hidden " + w); |
| 9939 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9940 | } else if (w.mLastLayer != w.mAnimLayer |
| 9941 | || w.mLastAlpha != w.mShownAlpha |
| 9942 | || w.mLastDsDx != w.mDsDx |
| 9943 | || w.mLastDtDx != w.mDtDx |
| 9944 | || w.mLastDsDy != w.mDsDy |
| 9945 | || w.mLastDtDy != w.mDtDy |
| 9946 | || w.mLastHScale != w.mHScale |
| 9947 | || w.mLastVScale != w.mVScale |
| 9948 | || w.mLastHidden) { |
| 9949 | displayed = true; |
| 9950 | w.mLastAlpha = w.mShownAlpha; |
| 9951 | w.mLastLayer = w.mAnimLayer; |
| 9952 | w.mLastDsDx = w.mDsDx; |
| 9953 | w.mLastDtDx = w.mDtDx; |
| 9954 | w.mLastDsDy = w.mDsDy; |
| 9955 | w.mLastDtDy = w.mDtDy; |
| 9956 | w.mLastHScale = w.mHScale; |
| 9957 | w.mLastVScale = w.mVScale; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9958 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9959 | "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9960 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 9961 | + "," + (w.mDtDx*w.mVScale) |
| 9962 | + "][" + (w.mDsDy*w.mHScale) |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9963 | + "," + (w.mDtDy*w.mVScale) + "]", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9964 | if (w.mSurface != null) { |
| 9965 | try { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9966 | w.mSurfaceAlpha = w.mShownAlpha; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9967 | w.mSurface.setAlpha(w.mShownAlpha); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9968 | w.mSurfaceLayer = w.mAnimLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9969 | w.mSurface.setLayer(w.mAnimLayer); |
| 9970 | w.mSurface.setMatrix( |
| 9971 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 9972 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 9973 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9974 | Slog.w(TAG, "Error updating surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9975 | if (!recoveringMemory) { |
| 9976 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 9977 | } |
| 9978 | } |
| 9979 | } |
| 9980 | |
| 9981 | if (w.mLastHidden && !w.mDrawPending |
| 9982 | && !w.mCommitDrawPending |
| 9983 | && !w.mReadyToShow) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9984 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9985 | "SHOW (performLayout)", null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9986 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9987 | + " during relayout"); |
| 9988 | if (showSurfaceRobustlyLocked(w)) { |
| 9989 | w.mHasDrawn = true; |
| 9990 | w.mLastHidden = false; |
| 9991 | } else { |
| 9992 | w.mOrientationChanging = false; |
| 9993 | } |
| 9994 | } |
| 9995 | if (w.mSurface != null) { |
| 9996 | w.mToken.hasVisible = true; |
| 9997 | } |
| 9998 | } else { |
| 9999 | displayed = true; |
| 10000 | } |
| 10001 | |
| 10002 | if (displayed) { |
| 10003 | if (!covered) { |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 10004 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 10005 | && attrs.height == LayoutParams.MATCH_PARENT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10006 | covered = true; |
| 10007 | } |
| 10008 | } |
| 10009 | if (w.mOrientationChanging) { |
| 10010 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 10011 | orientationChangeComplete = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10012 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10013 | "Orientation continue waiting for draw in " + w); |
| 10014 | } else { |
| 10015 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10016 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10017 | "Orientation change complete in " + w); |
| 10018 | } |
| 10019 | } |
| 10020 | w.mToken.hasVisible = true; |
| 10021 | } |
| 10022 | } else if (w.mOrientationChanging) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10023 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10024 | "Orientation change skips hidden " + w); |
| 10025 | w.mOrientationChanging = false; |
| 10026 | } |
| 10027 | |
| 10028 | final boolean canBeSeen = w.isDisplayedLw(); |
| 10029 | |
| 10030 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 10031 | focusDisplayed = true; |
| 10032 | } |
| 10033 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10034 | final boolean obscuredChanged = w.mObscured != obscured; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10035 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10036 | // Update effect. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10037 | if (!(w.mObscured=obscured)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10038 | if (w.mSurface != null) { |
| 10039 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 10040 | holdScreen = w.mSession; |
| 10041 | } |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10042 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 10043 | && screenBrightness < 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10044 | screenBrightness = w.mAttrs.screenBrightness; |
| 10045 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10046 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 10047 | && buttonBrightness < 0) { |
| 10048 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 10049 | } |
Mike Lockwood | 46af6a8 | 2010-03-09 08:28:22 -0500 | [diff] [blame] | 10050 | if (canBeSeen |
| 10051 | && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 10052 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 10053 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) { |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10054 | syswin = true; |
| 10055 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10056 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10057 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10058 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 10059 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10060 | // This window completely covers everything behind it, |
| 10061 | // so we want to leave all of them as unblurred (for |
| 10062 | // performance reasons). |
| 10063 | obscured = true; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10064 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10065 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler"); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10066 | // This window is in compatibility mode, and needs background filler. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10067 | obscured = true; |
| 10068 | if (mBackgroundFillerSurface == null) { |
| 10069 | try { |
| 10070 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10071 | "BackGroundFiller", |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10072 | 0, dw, dh, |
| 10073 | PixelFormat.OPAQUE, |
| 10074 | Surface.FX_SURFACE_NORMAL); |
| 10075 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10076 | Slog.e(TAG, "Exception creating filler surface", e); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10077 | } |
| 10078 | } |
| 10079 | try { |
| 10080 | mBackgroundFillerSurface.setPosition(0, 0); |
| 10081 | mBackgroundFillerSurface.setSize(dw, dh); |
| 10082 | // Using the same layer as Dim because they will never be shown at the |
| 10083 | // same time. |
| 10084 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 10085 | mBackgroundFillerSurface.show(); |
| 10086 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10087 | Slog.e(TAG, "Exception showing filler surface"); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10088 | } |
| 10089 | backgroundFillerShown = true; |
| 10090 | mBackgroundFillerShown = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10091 | } else if (canBeSeen && !obscured && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10092 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10093 | if (localLOGV) Slog.v(TAG, "Win " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10094 | + ": blurring=" + blurring |
| 10095 | + " obscured=" + obscured |
| 10096 | + " displayed=" + displayed); |
| 10097 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 10098 | if (!dimming) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10099 | //Slog.i(TAG, "DIM BEHIND: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10100 | dimming = true; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10101 | if (mDimAnimator == null) { |
| 10102 | mDimAnimator = new DimAnimator(mFxSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10103 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10104 | mDimAnimator.show(dw, dh); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10105 | mDimAnimator.updateParameters(w, currentTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10106 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10107 | } |
| 10108 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 10109 | if (!blurring) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10110 | //Slog.i(TAG, "BLUR BEHIND: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10111 | blurring = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10112 | if (mBlurSurface == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10113 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10114 | + mBlurSurface + ": CREATE"); |
| 10115 | try { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10116 | mBlurSurface = new Surface(mFxSession, 0, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10117 | "BlurSurface", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10118 | -1, 16, 16, |
| 10119 | PixelFormat.OPAQUE, |
| 10120 | Surface.FX_SURFACE_BLUR); |
| 10121 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10122 | Slog.e(TAG, "Exception creating Blur surface", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10123 | } |
| 10124 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10125 | if (mBlurSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10126 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10127 | + mBlurSurface + ": pos=(0,0) (" + |
| 10128 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10129 | mBlurSurface.setPosition(0, 0); |
| 10130 | mBlurSurface.setSize(dw, dh); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10131 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 10132 | if (!mBlurShown) { |
| 10133 | try { |
| 10134 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10135 | + mBlurSurface + ": SHOW"); |
| 10136 | mBlurSurface.show(); |
| 10137 | } catch (RuntimeException e) { |
| 10138 | Slog.w(TAG, "Failure showing blur surface", e); |
| 10139 | } |
| 10140 | mBlurShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10141 | } |
| 10142 | } |
| 10143 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10144 | } |
| 10145 | } |
| 10146 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10147 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10148 | if (obscuredChanged && mWallpaperTarget == w) { |
| 10149 | // This is the wallpaper target and its obscured state |
| 10150 | // changed... make sure the current wallaper's visibility |
| 10151 | // has been updated accordingly. |
| 10152 | updateWallpaperVisibilityLocked(); |
| 10153 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10154 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10155 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10156 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 10157 | mBackgroundFillerShown = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10158 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler"); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10159 | try { |
| 10160 | mBackgroundFillerSurface.hide(); |
| 10161 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10162 | Slog.e(TAG, "Exception hiding filler surface", e); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10163 | } |
| 10164 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10165 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10166 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10167 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 10168 | mDisplayFrozen || !mPolicy.isScreenOn()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10169 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10170 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10171 | if (!blurring && mBlurShown) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10172 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10173 | + ": HIDE"); |
| 10174 | try { |
| 10175 | mBlurSurface.hide(); |
| 10176 | } catch (IllegalArgumentException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10177 | Slog.w(TAG, "Illegal argument exception hiding blur surface"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10178 | } |
| 10179 | mBlurShown = false; |
| 10180 | } |
| 10181 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10182 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10183 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10184 | Slog.e(TAG, "Unhandled exception in Window Manager", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10185 | } |
| 10186 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10187 | mInputMonitor.updateInputWindowsLw(); |
| 10188 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10189 | Surface.closeTransaction(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10190 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10191 | if (mWatermark != null) { |
| 10192 | mWatermark.drawIfNeeded(); |
| 10193 | } |
| 10194 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10195 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10196 | "With display frozen, orientationChangeComplete=" |
| 10197 | + orientationChangeComplete); |
| 10198 | if (orientationChangeComplete) { |
| 10199 | if (mWindowsFreezingScreen) { |
| 10200 | mWindowsFreezingScreen = false; |
| 10201 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10202 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10203 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10204 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10205 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10206 | i = mResizingWindows.size(); |
| 10207 | if (i > 0) { |
| 10208 | do { |
| 10209 | i--; |
| 10210 | WindowState win = mResizingWindows.get(i); |
| 10211 | try { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10212 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| 10213 | "Reporting new frame to " + win + ": " + win.mFrame); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10214 | int diff = 0; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10215 | boolean configChanged = |
| 10216 | win.mConfiguration != mCurConfiguration |
| 10217 | && (win.mConfiguration == null |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10218 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); |
| 10219 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) |
| 10220 | && configChanged) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10221 | Slog.i(TAG, "Sending new config to window " + win + ": " |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10222 | + win.mFrame.width() + "x" + win.mFrame.height() |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10223 | + " / " + mCurConfiguration + " / 0x" |
| 10224 | + Integer.toHexString(diff)); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10225 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10226 | win.mConfiguration = mCurConfiguration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10227 | win.mClient.resized(win.mFrame.width(), |
| 10228 | win.mFrame.height(), win.mLastContentInsets, |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10229 | win.mLastVisibleInsets, win.mDrawPending, |
| 10230 | configChanged ? win.mConfiguration : null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10231 | win.mContentInsetsChanged = false; |
| 10232 | win.mVisibleInsetsChanged = false; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10233 | win.mSurfaceResized = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10234 | } catch (RemoteException e) { |
| 10235 | win.mOrientationChanging = false; |
| 10236 | } |
| 10237 | } while (i > 0); |
| 10238 | mResizingWindows.clear(); |
| 10239 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10240 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10241 | // Destroy the surface of any windows that are no longer visible. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10242 | boolean wallpaperDestroyed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10243 | i = mDestroySurface.size(); |
| 10244 | if (i > 0) { |
| 10245 | do { |
| 10246 | i--; |
| 10247 | WindowState win = mDestroySurface.get(i); |
| 10248 | win.mDestroying = false; |
| 10249 | if (mInputMethodWindow == win) { |
| 10250 | mInputMethodWindow = null; |
| 10251 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10252 | if (win == mWallpaperTarget) { |
| 10253 | wallpaperDestroyed = true; |
| 10254 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10255 | win.destroySurfaceLocked(); |
| 10256 | } while (i > 0); |
| 10257 | mDestroySurface.clear(); |
| 10258 | } |
| 10259 | |
| 10260 | // Time to remove any exiting tokens? |
| 10261 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 10262 | WindowToken token = mExitingTokens.get(i); |
| 10263 | if (!token.hasVisible) { |
| 10264 | mExitingTokens.remove(i); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10265 | if (token.windowType == TYPE_WALLPAPER) { |
| 10266 | mWallpaperTokens.remove(token); |
| 10267 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10268 | } |
| 10269 | } |
| 10270 | |
| 10271 | // Time to remove any exiting applications? |
| 10272 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10273 | AppWindowToken token = mExitingAppTokens.get(i); |
| 10274 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 10275 | // Make sure there is no animation running on this token, |
| 10276 | // so any windows associated with it will be removed as |
| 10277 | // soon as their animations are complete |
| 10278 | token.animation = null; |
| 10279 | token.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10280 | mAppTokens.remove(token); |
| 10281 | mExitingAppTokens.remove(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10282 | if (mLastEnterAnimToken == token) { |
| 10283 | mLastEnterAnimToken = null; |
| 10284 | mLastEnterAnimParams = null; |
| 10285 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10286 | } |
| 10287 | } |
| 10288 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10289 | boolean needRelayout = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10290 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10291 | if (!animating && mAppTransitionRunning) { |
| 10292 | // We have finished the animation of an app transition. To do |
| 10293 | // this, we have delayed a lot of operations like showing and |
| 10294 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10295 | // reflects the correct Z-order, but the window list may now |
| 10296 | // be out of sync with it. So here we will just rebuild the |
| 10297 | // entire app window list. Fun! |
| 10298 | mAppTransitionRunning = false; |
| 10299 | needRelayout = true; |
| 10300 | rebuildAppWindowListLocked(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10301 | assignLayersLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10302 | // Clear information about apps that were moving. |
| 10303 | mToBottomApps.clear(); |
| 10304 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10305 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10306 | if (focusDisplayed) { |
| 10307 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 10308 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10309 | if (wallpaperDestroyed) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10310 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10311 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10312 | if (needRelayout) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10313 | requestAnimationLocked(0); |
| 10314 | } else if (animating) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10315 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 10316 | } |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 10317 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10318 | mInputMonitor.updateInputWindowsLw(); |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 10319 | |
Jeff Brown | 8e03b75 | 2010-06-13 19:16:55 -0700 | [diff] [blame] | 10320 | setHoldScreenLocked(holdScreen != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10321 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 10322 | mPowerManager.setScreenBrightnessOverride(-1); |
| 10323 | } else { |
| 10324 | mPowerManager.setScreenBrightnessOverride((int) |
| 10325 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 10326 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10327 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 10328 | mPowerManager.setButtonBrightnessOverride(-1); |
| 10329 | } else { |
| 10330 | mPowerManager.setButtonBrightnessOverride((int) |
| 10331 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 10332 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10333 | if (holdScreen != mHoldingScreenOn) { |
| 10334 | mHoldingScreenOn = holdScreen; |
| 10335 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 10336 | mH.sendMessage(m); |
| 10337 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10338 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10339 | if (mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10340 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10341 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 10342 | LocalPowerManager.BUTTON_EVENT, true); |
| 10343 | mTurnOnScreen = false; |
| 10344 | } |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 10345 | |
| 10346 | // Check to see if we are now in a state where the screen should |
| 10347 | // be enabled, because the window obscured flags have changed. |
| 10348 | enableScreenIfNeededLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10349 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 10350 | |
| 10351 | /** |
| 10352 | * Must be called with the main window manager lock held. |
| 10353 | */ |
| 10354 | void setHoldScreenLocked(boolean holding) { |
| 10355 | boolean state = mHoldingScreenWakeLock.isHeld(); |
| 10356 | if (holding != state) { |
| 10357 | if (holding) { |
| 10358 | mHoldingScreenWakeLock.acquire(); |
| 10359 | } else { |
| 10360 | mPolicy.screenOnStoppedLw(); |
| 10361 | mHoldingScreenWakeLock.release(); |
| 10362 | } |
| 10363 | } |
| 10364 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10365 | |
| 10366 | void requestAnimationLocked(long delay) { |
| 10367 | if (!mAnimationPending) { |
| 10368 | mAnimationPending = true; |
| 10369 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 10370 | } |
| 10371 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10372 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10373 | /** |
| 10374 | * Have the surface flinger show a surface, robustly dealing with |
| 10375 | * error conditions. In particular, if there is not enough memory |
| 10376 | * to show the surface, then we will try to get rid of other surfaces |
| 10377 | * in order to succeed. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10378 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10379 | * @return Returns true if the surface was successfully shown. |
| 10380 | */ |
| 10381 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 10382 | try { |
| 10383 | if (win.mSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10384 | win.mSurfaceShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10385 | win.mSurface.show(); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10386 | if (win.mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10387 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 10388 | "Show surface turning screen on: " + win); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10389 | win.mTurnOnScreen = false; |
| 10390 | mTurnOnScreen = true; |
| 10391 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10392 | } |
| 10393 | return true; |
| 10394 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10395 | 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] | 10396 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10397 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10398 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10399 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10400 | return false; |
| 10401 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10402 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10403 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 10404 | final Surface surface = win.mSurface; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10405 | |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10406 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10407 | win.mSession.mPid, operation); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10408 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10409 | if (mForceRemoves == null) { |
| 10410 | mForceRemoves = new ArrayList<WindowState>(); |
| 10411 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10412 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10413 | long callingIdentity = Binder.clearCallingIdentity(); |
| 10414 | try { |
| 10415 | // There was some problem... first, do a sanity check of the |
| 10416 | // window list to make sure we haven't left any dangling surfaces |
| 10417 | // around. |
| 10418 | int N = mWindows.size(); |
| 10419 | boolean leakedSurface = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10420 | 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] | 10421 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10422 | WindowState ws = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10423 | if (ws.mSurface != null) { |
| 10424 | if (!mSessions.contains(ws.mSession)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10425 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10426 | + ws + " surface=" + ws.mSurface |
| 10427 | + " token=" + win.mToken |
| 10428 | + " pid=" + ws.mSession.mPid |
| 10429 | + " uid=" + ws.mSession.mUid); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10430 | ws.mSurface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10431 | ws.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10432 | ws.mSurface = null; |
| 10433 | mForceRemoves.add(ws); |
| 10434 | i--; |
| 10435 | N--; |
| 10436 | leakedSurface = true; |
| 10437 | } else if (win.mAppToken != null && win.mAppToken.clientHidden) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10438 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10439 | + ws + " surface=" + ws.mSurface |
| 10440 | + " token=" + win.mAppToken); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10441 | ws.mSurface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10442 | ws.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10443 | ws.mSurface = null; |
| 10444 | leakedSurface = true; |
| 10445 | } |
| 10446 | } |
| 10447 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10448 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10449 | boolean killedApps = false; |
| 10450 | if (!leakedSurface) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10451 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10452 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 10453 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10454 | WindowState ws = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10455 | if (ws.mSurface != null) { |
| 10456 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 10457 | } |
| 10458 | } |
| 10459 | if (pidCandidates.size() > 0) { |
| 10460 | int[] pids = new int[pidCandidates.size()]; |
| 10461 | for (int i=0; i<pids.length; i++) { |
| 10462 | pids[i] = pidCandidates.keyAt(i); |
| 10463 | } |
| 10464 | try { |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 10465 | if (mActivityManager.killPids(pids, "Free memory")) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10466 | killedApps = true; |
| 10467 | } |
| 10468 | } catch (RemoteException e) { |
| 10469 | } |
| 10470 | } |
| 10471 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10472 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10473 | if (leakedSurface || killedApps) { |
| 10474 | // We managed to reclaim some memory, so get rid of the trouble |
| 10475 | // surface and ask the app to request another one. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10476 | 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] | 10477 | if (surface != null) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10478 | surface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10479 | win.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10480 | win.mSurface = null; |
| 10481 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10482 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10483 | try { |
| 10484 | win.mClient.dispatchGetNewSurface(); |
| 10485 | } catch (RemoteException e) { |
| 10486 | } |
| 10487 | } |
| 10488 | } finally { |
| 10489 | Binder.restoreCallingIdentity(callingIdentity); |
| 10490 | } |
| 10491 | } |
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 | private boolean updateFocusedWindowLocked(int mode) { |
| 10494 | WindowState newFocus = computeFocusedWindowLocked(); |
| 10495 | if (mCurrentFocus != newFocus) { |
| 10496 | // This check makes sure that we don't already have the focus |
| 10497 | // change message pending. |
| 10498 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 10499 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10500 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10501 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 10502 | final WindowState oldFocus = mCurrentFocus; |
| 10503 | mCurrentFocus = newFocus; |
| 10504 | mLosingFocus.remove(newFocus); |
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 | final WindowState imWindow = mInputMethodWindow; |
| 10507 | if (newFocus != imWindow && oldFocus != imWindow) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10508 | if (moveInputMethodWindowsIfNeededLocked( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10509 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10510 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 10511 | mLayoutNeeded = true; |
| 10512 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10513 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 10514 | performLayoutLockedInner(); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10515 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 10516 | // Client will do the layout, but we need to assign layers |
| 10517 | // for handleNewWindowLocked() below. |
| 10518 | assignLayersLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10519 | } |
| 10520 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10521 | |
| 10522 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 10523 | // If we defer assigning layers, then the caller is responsible for |
| 10524 | // doing this part. |
| 10525 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10526 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10527 | return true; |
| 10528 | } |
| 10529 | return false; |
| 10530 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10531 | |
| 10532 | private void finishUpdateFocusedWindowAfterAssignLayersLocked() { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10533 | mInputMonitor.setInputFocusLw(mCurrentFocus); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10534 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10535 | |
| 10536 | private WindowState computeFocusedWindowLocked() { |
| 10537 | WindowState result = null; |
| 10538 | WindowState win; |
| 10539 | |
| 10540 | int i = mWindows.size() - 1; |
| 10541 | int nextAppIndex = mAppTokens.size()-1; |
| 10542 | WindowToken nextApp = nextAppIndex >= 0 |
| 10543 | ? mAppTokens.get(nextAppIndex) : null; |
| 10544 | |
| 10545 | while (i >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10546 | win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10547 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10548 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10549 | TAG, "Looking for focus: " + i |
| 10550 | + " = " + win |
| 10551 | + ", flags=" + win.mAttrs.flags |
| 10552 | + ", canReceive=" + win.canReceiveKeys()); |
| 10553 | |
| 10554 | AppWindowToken thisApp = win.mAppToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10555 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10556 | // If this window's application has been removed, just skip it. |
| 10557 | if (thisApp != null && thisApp.removed) { |
| 10558 | i--; |
| 10559 | continue; |
| 10560 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10561 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10562 | // If there is a focused app, don't allow focus to go to any |
| 10563 | // windows below it. If this is an application window, step |
| 10564 | // through the app tokens until we find its app. |
| 10565 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 10566 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 10567 | int origAppIndex = nextAppIndex; |
| 10568 | while (nextAppIndex > 0) { |
| 10569 | if (nextApp == mFocusedApp) { |
| 10570 | // Whoops, we are below the focused app... no focus |
| 10571 | // for you! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10572 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10573 | TAG, "Reached focused app: " + mFocusedApp); |
| 10574 | return null; |
| 10575 | } |
| 10576 | nextAppIndex--; |
| 10577 | nextApp = mAppTokens.get(nextAppIndex); |
| 10578 | if (nextApp == thisApp) { |
| 10579 | break; |
| 10580 | } |
| 10581 | } |
| 10582 | if (thisApp != nextApp) { |
| 10583 | // Uh oh, the app token doesn't exist! This shouldn't |
| 10584 | // happen, but if it does we can get totally hosed... |
| 10585 | // so restart at the original app. |
| 10586 | nextAppIndex = origAppIndex; |
| 10587 | nextApp = mAppTokens.get(nextAppIndex); |
| 10588 | } |
| 10589 | } |
| 10590 | |
| 10591 | // Dispatch to this window if it is wants key events. |
| 10592 | if (win.canReceiveKeys()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10593 | if (DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10594 | TAG, "Found focus @ " + i + " = " + win); |
| 10595 | result = win; |
| 10596 | break; |
| 10597 | } |
| 10598 | |
| 10599 | i--; |
| 10600 | } |
| 10601 | |
| 10602 | return result; |
| 10603 | } |
| 10604 | |
| 10605 | private void startFreezingDisplayLocked() { |
| 10606 | if (mDisplayFrozen) { |
| 10607 | return; |
| 10608 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10609 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10610 | mScreenFrozenLock.acquire(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10611 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10612 | long now = SystemClock.uptimeMillis(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10613 | //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10614 | if (mFreezeGcPending != 0) { |
| 10615 | if (now > (mFreezeGcPending+1000)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10616 | //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10617 | mH.removeMessages(H.FORCE_GC); |
| 10618 | Runtime.getRuntime().gc(); |
| 10619 | mFreezeGcPending = now; |
| 10620 | } |
| 10621 | } else { |
| 10622 | mFreezeGcPending = now; |
| 10623 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10624 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10625 | mDisplayFrozen = true; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10626 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10627 | mInputMonitor.freezeInputDispatchingLw(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10628 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 10629 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 10630 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10631 | mNextAppTransitionPackage = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10632 | mAppTransitionReady = true; |
| 10633 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10634 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10635 | if (PROFILE_ORIENTATION) { |
| 10636 | File file = new File("/data/system/frozen"); |
| 10637 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 10638 | } |
| 10639 | Surface.freezeDisplay(0); |
| 10640 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10641 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10642 | private void stopFreezingDisplayLocked() { |
| 10643 | if (!mDisplayFrozen) { |
| 10644 | return; |
| 10645 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10646 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10647 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) { |
| 10648 | return; |
| 10649 | } |
| 10650 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10651 | mDisplayFrozen = false; |
| 10652 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 10653 | if (PROFILE_ORIENTATION) { |
| 10654 | Debug.stopMethodTracing(); |
| 10655 | } |
| 10656 | Surface.unfreezeDisplay(0); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10657 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10658 | mInputMonitor.thawInputDispatchingLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10659 | |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 10660 | // While the display is frozen we don't re-compute the orientation |
| 10661 | // to avoid inconsistent states. However, something interesting |
| 10662 | // could have actually changed during that time so re-evaluate it |
| 10663 | // now to catch that. |
| 10664 | if (updateOrientationFromAppTokensLocked()) { |
| 10665 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 10666 | } |
| 10667 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10668 | // A little kludge: a lot could have happened while the |
| 10669 | // display was frozen, so now that we are coming back we |
| 10670 | // do a gc so that any remote references the system |
| 10671 | // processes holds on others can be released if they are |
| 10672 | // no longer needed. |
| 10673 | mH.removeMessages(H.FORCE_GC); |
| 10674 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 10675 | 2000); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10676 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10677 | mScreenFrozenLock.release(); |
| 10678 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10679 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10680 | static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps, |
| 10681 | DisplayMetrics dm) { |
| 10682 | if (index < tokens.length) { |
| 10683 | String str = tokens[index]; |
| 10684 | if (str != null && str.length() > 0) { |
| 10685 | try { |
| 10686 | int val = Integer.parseInt(str); |
| 10687 | return val; |
| 10688 | } catch (Exception e) { |
| 10689 | } |
| 10690 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10691 | } |
| 10692 | if (defUnits == TypedValue.COMPLEX_UNIT_PX) { |
| 10693 | return defDps; |
| 10694 | } |
| 10695 | int val = (int)TypedValue.applyDimension(defUnits, defDps, dm); |
| 10696 | return val; |
| 10697 | } |
| 10698 | |
| 10699 | class Watermark { |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10700 | final String[] mTokens; |
| 10701 | final String mText; |
| 10702 | final Paint mTextPaint; |
| 10703 | final int mTextWidth; |
| 10704 | final int mTextHeight; |
| 10705 | final int mTextAscent; |
| 10706 | final int mTextDescent; |
| 10707 | final int mDeltaX; |
| 10708 | final int mDeltaY; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10709 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10710 | Surface mSurface; |
| 10711 | int mLastDW; |
| 10712 | int mLastDH; |
| 10713 | boolean mDrawNeeded; |
| 10714 | |
| 10715 | Watermark(SurfaceSession session, String[] tokens) { |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10716 | final DisplayMetrics dm = new DisplayMetrics(); |
| 10717 | mDisplay.getMetrics(dm); |
| 10718 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10719 | if (false) { |
| 10720 | Log.i(TAG, "*********************** WATERMARK"); |
| 10721 | for (int i=0; i<tokens.length; i++) { |
| 10722 | Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]); |
| 10723 | } |
| 10724 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10725 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10726 | mTokens = tokens; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10727 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10728 | StringBuilder builder = new StringBuilder(32); |
| 10729 | int len = mTokens[0].length(); |
| 10730 | len = len & ~1; |
| 10731 | for (int i=0; i<len; i+=2) { |
| 10732 | int c1 = mTokens[0].charAt(i); |
| 10733 | int c2 = mTokens[0].charAt(i+1); |
| 10734 | if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10; |
| 10735 | else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10; |
| 10736 | else c1 -= '0'; |
| 10737 | if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10; |
| 10738 | else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10; |
| 10739 | else c2 -= '0'; |
| 10740 | builder.append((char)(255-((c1*16)+c2))); |
| 10741 | } |
| 10742 | mText = builder.toString(); |
| 10743 | if (false) { |
| 10744 | Log.i(TAG, "Final text: " + mText); |
| 10745 | } |
| 10746 | |
| 10747 | int fontSize = getPropertyInt(tokens, 1, |
| 10748 | TypedValue.COMPLEX_UNIT_DIP, 20, dm); |
| 10749 | |
| 10750 | mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
| 10751 | mTextPaint.setTextSize(fontSize); |
| 10752 | mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD)); |
| 10753 | |
| 10754 | FontMetricsInt fm = mTextPaint.getFontMetricsInt(); |
| 10755 | mTextWidth = (int)mTextPaint.measureText(mText); |
| 10756 | mTextAscent = fm.ascent; |
| 10757 | mTextDescent = fm.descent; |
| 10758 | mTextHeight = fm.descent - fm.ascent; |
| 10759 | |
| 10760 | mDeltaX = getPropertyInt(tokens, 2, |
| 10761 | TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm); |
| 10762 | mDeltaY = getPropertyInt(tokens, 3, |
| 10763 | TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm); |
| 10764 | int shadowColor = getPropertyInt(tokens, 4, |
| 10765 | TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm); |
| 10766 | int color = getPropertyInt(tokens, 5, |
| 10767 | TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm); |
| 10768 | int shadowRadius = getPropertyInt(tokens, 6, |
| 10769 | TypedValue.COMPLEX_UNIT_PX, 7, dm); |
| 10770 | int shadowDx = getPropertyInt(tokens, 8, |
| 10771 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 10772 | int shadowDy = getPropertyInt(tokens, 9, |
| 10773 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 10774 | |
| 10775 | mTextPaint.setColor(color); |
| 10776 | mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10777 | |
| 10778 | try { |
| 10779 | mSurface = new Surface(session, 0, |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10780 | "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10781 | mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100); |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10782 | mSurface.setPosition(0, 0); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10783 | mSurface.show(); |
| 10784 | } catch (OutOfResourcesException e) { |
| 10785 | } |
| 10786 | } |
| 10787 | |
| 10788 | void positionSurface(int dw, int dh) { |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10789 | if (mLastDW != dw || mLastDH != dh) { |
| 10790 | mLastDW = dw; |
| 10791 | mLastDH = dh; |
| 10792 | mSurface.setSize(dw, dh); |
| 10793 | mDrawNeeded = true; |
| 10794 | } |
| 10795 | } |
| 10796 | |
| 10797 | void drawIfNeeded() { |
| 10798 | if (mDrawNeeded) { |
| 10799 | final int dw = mLastDW; |
| 10800 | final int dh = mLastDH; |
| 10801 | |
| 10802 | mDrawNeeded = false; |
| 10803 | Rect dirty = new Rect(0, 0, dw, dh); |
| 10804 | Canvas c = null; |
| 10805 | try { |
| 10806 | c = mSurface.lockCanvas(dirty); |
| 10807 | } catch (IllegalArgumentException e) { |
| 10808 | } catch (OutOfResourcesException e) { |
| 10809 | } |
| 10810 | if (c != null) { |
| 10811 | int deltaX = mDeltaX; |
| 10812 | int deltaY = mDeltaY; |
| 10813 | |
| 10814 | // deltaX shouldn't be close to a round fraction of our |
| 10815 | // x step, or else things will line up too much. |
| 10816 | int div = (dw+mTextWidth)/deltaX; |
| 10817 | int rem = (dw+mTextWidth) - (div*deltaX); |
| 10818 | int qdelta = deltaX/4; |
| 10819 | if (rem < qdelta || rem > (deltaX-qdelta)) { |
| 10820 | deltaX += deltaX/3; |
| 10821 | } |
| 10822 | |
| 10823 | int y = -mTextHeight; |
| 10824 | int x = -mTextWidth; |
| 10825 | while (y < (dh+mTextHeight)) { |
| 10826 | c.drawText(mText, x, y, mTextPaint); |
| 10827 | x += deltaX; |
| 10828 | if (x >= dw) { |
| 10829 | x -= (dw+mTextWidth); |
| 10830 | y += deltaY; |
| 10831 | } |
| 10832 | } |
| 10833 | mSurface.unlockCanvasAndPost(c); |
| 10834 | } |
| 10835 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10836 | } |
| 10837 | } |
| 10838 | |
| 10839 | void createWatermark() { |
| 10840 | if (mWatermark != null) { |
| 10841 | return; |
| 10842 | } |
| 10843 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10844 | File file = new File("/system/etc/setup.conf"); |
| 10845 | FileInputStream in = null; |
| 10846 | try { |
| 10847 | in = new FileInputStream(file); |
| 10848 | DataInputStream ind = new DataInputStream(in); |
| 10849 | String line = ind.readLine(); |
| 10850 | if (line != null) { |
| 10851 | String[] toks = line.split("%"); |
| 10852 | if (toks != null && toks.length > 0) { |
| 10853 | mWatermark = new Watermark(mFxSession, toks); |
| 10854 | } |
| 10855 | } |
| 10856 | } catch (FileNotFoundException e) { |
| 10857 | } catch (IOException e) { |
| 10858 | } finally { |
| 10859 | if (in != null) { |
| 10860 | try { |
| 10861 | in.close(); |
| 10862 | } catch (IOException e) { |
| 10863 | } |
| 10864 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10865 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10866 | } |
| 10867 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10868 | @Override |
| 10869 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 10870 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 10871 | != PackageManager.PERMISSION_GRANTED) { |
| 10872 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 10873 | + Binder.getCallingPid() |
| 10874 | + ", uid=" + Binder.getCallingUid()); |
| 10875 | return; |
| 10876 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10877 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10878 | mInputManager.dump(pw); |
Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 10879 | pw.println(" "); |
| 10880 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10881 | synchronized(mWindowMap) { |
| 10882 | pw.println("Current Window Manager state:"); |
| 10883 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10884 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10885 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 10886 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10887 | w.dump(pw, " "); |
| 10888 | } |
| 10889 | if (mInputMethodDialogs.size() > 0) { |
| 10890 | pw.println(" "); |
| 10891 | pw.println(" Input method dialogs:"); |
| 10892 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 10893 | WindowState w = mInputMethodDialogs.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10894 | 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] | 10895 | } |
| 10896 | } |
| 10897 | if (mPendingRemove.size() > 0) { |
| 10898 | pw.println(" "); |
| 10899 | pw.println(" Remove pending for:"); |
| 10900 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 10901 | WindowState w = mPendingRemove.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10902 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 10903 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10904 | w.dump(pw, " "); |
| 10905 | } |
| 10906 | } |
| 10907 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 10908 | pw.println(" "); |
| 10909 | pw.println(" Windows force removing:"); |
| 10910 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 10911 | WindowState w = mForceRemoves.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10912 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 10913 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10914 | w.dump(pw, " "); |
| 10915 | } |
| 10916 | } |
| 10917 | if (mDestroySurface.size() > 0) { |
| 10918 | pw.println(" "); |
| 10919 | pw.println(" Windows waiting to destroy their surface:"); |
| 10920 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 10921 | WindowState w = mDestroySurface.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10922 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 10923 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10924 | w.dump(pw, " "); |
| 10925 | } |
| 10926 | } |
| 10927 | if (mLosingFocus.size() > 0) { |
| 10928 | pw.println(" "); |
| 10929 | pw.println(" Windows losing focus:"); |
| 10930 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 10931 | WindowState w = mLosingFocus.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10932 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 10933 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10934 | w.dump(pw, " "); |
| 10935 | } |
| 10936 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10937 | if (mResizingWindows.size() > 0) { |
| 10938 | pw.println(" "); |
| 10939 | pw.println(" Windows waiting to resize:"); |
| 10940 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 10941 | WindowState w = mResizingWindows.get(i); |
| 10942 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 10943 | pw.print(w); pw.println(":"); |
| 10944 | w.dump(pw, " "); |
| 10945 | } |
| 10946 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10947 | if (mSessions.size() > 0) { |
| 10948 | pw.println(" "); |
| 10949 | pw.println(" All active sessions:"); |
| 10950 | Iterator<Session> it = mSessions.iterator(); |
| 10951 | while (it.hasNext()) { |
| 10952 | Session s = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10953 | pw.print(" Session "); pw.print(s); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10954 | s.dump(pw, " "); |
| 10955 | } |
| 10956 | } |
| 10957 | if (mTokenMap.size() > 0) { |
| 10958 | pw.println(" "); |
| 10959 | pw.println(" All tokens:"); |
| 10960 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 10961 | while (it.hasNext()) { |
| 10962 | WindowToken token = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10963 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10964 | token.dump(pw, " "); |
| 10965 | } |
| 10966 | } |
| 10967 | if (mTokenList.size() > 0) { |
| 10968 | pw.println(" "); |
| 10969 | pw.println(" Window token list:"); |
| 10970 | for (int i=0; i<mTokenList.size(); i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10971 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 10972 | pw.println(mTokenList.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10973 | } |
| 10974 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10975 | if (mWallpaperTokens.size() > 0) { |
| 10976 | pw.println(" "); |
| 10977 | pw.println(" Wallpaper tokens:"); |
| 10978 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 10979 | WindowToken token = mWallpaperTokens.get(i); |
| 10980 | pw.print(" Wallpaper #"); pw.print(i); |
| 10981 | pw.print(' '); pw.print(token); pw.println(':'); |
| 10982 | token.dump(pw, " "); |
| 10983 | } |
| 10984 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10985 | if (mAppTokens.size() > 0) { |
| 10986 | pw.println(" "); |
| 10987 | pw.println(" Application tokens in Z order:"); |
| 10988 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10989 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 10990 | pw.println(mAppTokens.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10991 | } |
| 10992 | } |
| 10993 | if (mFinishedStarting.size() > 0) { |
| 10994 | pw.println(" "); |
| 10995 | pw.println(" Finishing start of application tokens:"); |
| 10996 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 10997 | WindowToken token = mFinishedStarting.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10998 | pw.print(" Finished Starting #"); pw.print(i); |
| 10999 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11000 | token.dump(pw, " "); |
| 11001 | } |
| 11002 | } |
| 11003 | if (mExitingTokens.size() > 0) { |
| 11004 | pw.println(" "); |
| 11005 | pw.println(" Exiting tokens:"); |
| 11006 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 11007 | WindowToken token = mExitingTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11008 | pw.print(" Exiting #"); pw.print(i); |
| 11009 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11010 | token.dump(pw, " "); |
| 11011 | } |
| 11012 | } |
| 11013 | if (mExitingAppTokens.size() > 0) { |
| 11014 | pw.println(" "); |
| 11015 | pw.println(" Exiting application tokens:"); |
| 11016 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 11017 | WindowToken token = mExitingAppTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11018 | pw.print(" Exiting App #"); pw.print(i); |
| 11019 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11020 | token.dump(pw, " "); |
| 11021 | } |
| 11022 | } |
| 11023 | pw.println(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11024 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 11025 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 11026 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 11027 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 11028 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 11029 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11030 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 11031 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 11032 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 11033 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11034 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 11035 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 11036 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11037 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 11038 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 11039 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 11040 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11041 | if (mDimAnimator != null) { |
| 11042 | mDimAnimator.printTo(pw); |
| 11043 | } else { |
Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 11044 | pw.println( " no DimAnimator "); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11045 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11046 | pw.print(" mInputMethodAnimLayerAdjustment="); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 11047 | pw.print(mInputMethodAnimLayerAdjustment); |
| 11048 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 11049 | pw.println(mWallpaperAnimLayerAdjustment); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11050 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 11051 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11052 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 11053 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11054 | pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); |
| 11055 | pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11056 | pw.print(" mRotation="); pw.print(mRotation); |
| 11057 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 11058 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 11059 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 11060 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 11061 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 11062 | pw.print(" mNextAppTransition=0x"); |
| 11063 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 11064 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11065 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11066 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11067 | if (mNextAppTransitionPackage != null) { |
| 11068 | pw.print(" mNextAppTransitionPackage="); |
| 11069 | pw.print(mNextAppTransitionPackage); |
| 11070 | pw.print(", mNextAppTransitionEnter=0x"); |
| 11071 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 11072 | pw.print(", mNextAppTransitionExit=0x"); |
| 11073 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 11074 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11075 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 11076 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11077 | if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) { |
| 11078 | pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken); |
| 11079 | pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams); |
| 11080 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11081 | if (mOpeningApps.size() > 0) { |
| 11082 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 11083 | } |
| 11084 | if (mClosingApps.size() > 0) { |
| 11085 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 11086 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11087 | if (mToTopApps.size() > 0) { |
| 11088 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 11089 | } |
| 11090 | if (mToBottomApps.size() > 0) { |
| 11091 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 11092 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11093 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 11094 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11095 | } |
| 11096 | } |
| 11097 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11098 | // 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] | 11099 | public void monitor() { |
| 11100 | synchronized (mWindowMap) { } |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 11101 | synchronized (mKeyguardTokenWatcher) { } |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 11102 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11103 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11104 | /** |
| 11105 | * DimAnimator class that controls the dim animation. This holds the surface and |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11106 | * all state used for dim animation. |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11107 | */ |
| 11108 | private static class DimAnimator { |
| 11109 | Surface mDimSurface; |
| 11110 | boolean mDimShown = false; |
| 11111 | float mDimCurrentAlpha; |
| 11112 | float mDimTargetAlpha; |
| 11113 | float mDimDeltaPerMs; |
| 11114 | long mLastDimAnimTime; |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11115 | |
| 11116 | int mLastDimWidth, mLastDimHeight; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11117 | |
| 11118 | DimAnimator (SurfaceSession session) { |
| 11119 | if (mDimSurface == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11120 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11121 | + mDimSurface + ": CREATE"); |
| 11122 | try { |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 11123 | mDimSurface = new Surface(session, 0, |
| 11124 | "DimSurface", |
| 11125 | -1, 16, 16, PixelFormat.OPAQUE, |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11126 | Surface.FX_SURFACE_DIM); |
Maciej Białka | 9ee5c22 | 2010-03-24 10:25:40 +0100 | [diff] [blame] | 11127 | mDimSurface.setAlpha(0.0f); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11128 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11129 | Slog.e(TAG, "Exception creating Dim surface", e); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11130 | } |
| 11131 | } |
| 11132 | } |
| 11133 | |
| 11134 | /** |
| 11135 | * Show the dim surface. |
| 11136 | */ |
| 11137 | void show(int dw, int dh) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11138 | if (!mDimShown) { |
| 11139 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 11140 | dw + "x" + dh + ")"); |
| 11141 | mDimShown = true; |
| 11142 | try { |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11143 | mLastDimWidth = dw; |
| 11144 | mLastDimHeight = dh; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11145 | mDimSurface.setPosition(0, 0); |
| 11146 | mDimSurface.setSize(dw, dh); |
| 11147 | mDimSurface.show(); |
| 11148 | } catch (RuntimeException e) { |
| 11149 | Slog.w(TAG, "Failure showing dim surface", e); |
| 11150 | } |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11151 | } else if (mLastDimWidth != dw || mLastDimHeight != dh) { |
| 11152 | mLastDimWidth = dw; |
| 11153 | mLastDimHeight = dh; |
| 11154 | mDimSurface.setSize(dw, dh); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11155 | } |
| 11156 | } |
| 11157 | |
| 11158 | /** |
| 11159 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 11160 | * {@link updateSurface} after all windows are examined. |
| 11161 | */ |
| 11162 | void updateParameters(WindowState w, long currentTime) { |
| 11163 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 11164 | |
| 11165 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11166 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11167 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11168 | if (mDimTargetAlpha != target) { |
| 11169 | // If the desired dim level has changed, then |
| 11170 | // start an animation to it. |
| 11171 | mLastDimAnimTime = currentTime; |
| 11172 | long duration = (w.mAnimating && w.mAnimation != null) |
| 11173 | ? w.mAnimation.computeDurationHint() |
| 11174 | : DEFAULT_DIM_DURATION; |
| 11175 | if (target > mDimTargetAlpha) { |
| 11176 | // This is happening behind the activity UI, |
| 11177 | // so we can make it run a little longer to |
| 11178 | // give a stronger impression without disrupting |
| 11179 | // the user. |
| 11180 | duration *= DIM_DURATION_MULTIPLIER; |
| 11181 | } |
| 11182 | if (duration < 1) { |
| 11183 | // Don't divide by zero |
| 11184 | duration = 1; |
| 11185 | } |
| 11186 | mDimTargetAlpha = target; |
| 11187 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 11188 | } |
| 11189 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11190 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11191 | /** |
| 11192 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 11193 | * false when the animation is finished and the dim surface is hidden. |
| 11194 | */ |
| 11195 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 11196 | if (!dimming) { |
| 11197 | if (mDimTargetAlpha != 0) { |
| 11198 | mLastDimAnimTime = currentTime; |
| 11199 | mDimTargetAlpha = 0; |
| 11200 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 11201 | } |
| 11202 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11203 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11204 | boolean animating = false; |
| 11205 | if (mLastDimAnimTime != 0) { |
| 11206 | mDimCurrentAlpha += mDimDeltaPerMs |
| 11207 | * (currentTime-mLastDimAnimTime); |
| 11208 | boolean more = true; |
| 11209 | if (displayFrozen) { |
| 11210 | // If the display is frozen, there is no reason to animate. |
| 11211 | more = false; |
| 11212 | } else if (mDimDeltaPerMs > 0) { |
| 11213 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 11214 | more = false; |
| 11215 | } |
| 11216 | } else if (mDimDeltaPerMs < 0) { |
| 11217 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 11218 | more = false; |
| 11219 | } |
| 11220 | } else { |
| 11221 | more = false; |
| 11222 | } |
| 11223 | |
| 11224 | // Do we need to continue animating? |
| 11225 | if (more) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11226 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11227 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 11228 | mLastDimAnimTime = currentTime; |
| 11229 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11230 | animating = true; |
| 11231 | } else { |
| 11232 | mDimCurrentAlpha = mDimTargetAlpha; |
| 11233 | mLastDimAnimTime = 0; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11234 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11235 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 11236 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11237 | if (!dimming) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11238 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11239 | + ": HIDE"); |
| 11240 | try { |
| 11241 | mDimSurface.hide(); |
| 11242 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11243 | Slog.w(TAG, "Illegal argument exception hiding dim surface"); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11244 | } |
| 11245 | mDimShown = false; |
| 11246 | } |
| 11247 | } |
| 11248 | } |
| 11249 | return animating; |
| 11250 | } |
| 11251 | |
| 11252 | public void printTo(PrintWriter pw) { |
| 11253 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 11254 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 11255 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 11256 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 11257 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 11258 | } |
| 11259 | } |
| 11260 | |
| 11261 | /** |
| 11262 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 11263 | * This is used for opening/closing transition for apps in compatible mode. |
| 11264 | */ |
| 11265 | private static class FadeInOutAnimation extends Animation { |
| 11266 | int mWidth; |
| 11267 | boolean mFadeIn; |
| 11268 | |
| 11269 | public FadeInOutAnimation(boolean fadeIn) { |
| 11270 | setInterpolator(new AccelerateInterpolator()); |
| 11271 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 11272 | mFadeIn = fadeIn; |
| 11273 | } |
| 11274 | |
| 11275 | @Override |
| 11276 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 11277 | float x = interpolatedTime; |
| 11278 | if (!mFadeIn) { |
| 11279 | x = 1.0f - x; // reverse the interpolation for fade out |
| 11280 | } |
| 11281 | if (x < 0.5) { |
| 11282 | // move the window out of the screen. |
| 11283 | t.getMatrix().setTranslate(mWidth, 0); |
| 11284 | } else { |
| 11285 | t.getMatrix().setTranslate(0, 0);// show |
| 11286 | t.setAlpha((x - 0.5f) * 2); |
| 11287 | } |
| 11288 | } |
| 11289 | |
| 11290 | @Override |
| 11291 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 11292 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 11293 | mWidth = width; |
| 11294 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11295 | |
| 11296 | @Override |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 11297 | public int getZAdjustment() { |
| 11298 | return Animation.ZORDER_TOP; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11299 | } |
| 11300 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11301 | } |