The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server; |
| 18 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
| 20 | import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; |
| 21 | import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 22 | import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND; |
| 24 | import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 25 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 27 | import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 28 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 30 | import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 32 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 33 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 34 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 35 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | |
| 37 | import com.android.internal.app.IBatteryStats; |
| 38 | import com.android.internal.policy.PolicyManager; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 39 | import com.android.internal.policy.impl.PhoneWindowManager; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 40 | import com.android.internal.view.BaseInputHandler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import com.android.internal.view.IInputContext; |
| 42 | import com.android.internal.view.IInputMethodClient; |
| 43 | import com.android.internal.view.IInputMethodManager; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 44 | import com.android.internal.view.WindowManagerPolicyThread; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import com.android.server.am.BatteryStatsService; |
| 46 | |
| 47 | import android.Manifest; |
| 48 | import android.app.ActivityManagerNative; |
| 49 | import android.app.IActivityManager; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 50 | import android.app.admin.DevicePolicyManager; |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 51 | import android.content.BroadcastReceiver; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 52 | import android.content.ClipData; |
| 53 | import android.content.ClipDescription; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | import android.content.Context; |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 55 | import android.content.Intent; |
| 56 | import android.content.IntentFilter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | import android.content.pm.ActivityInfo; |
| 58 | import android.content.pm.PackageManager; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 59 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | import android.content.res.Configuration; |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 61 | import android.content.res.Resources; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 62 | import android.graphics.Bitmap; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 63 | import android.graphics.Canvas; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | import android.graphics.Matrix; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 65 | import android.graphics.Paint; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | import android.graphics.PixelFormat; |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 67 | import android.graphics.PorterDuff; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | import android.graphics.Rect; |
| 69 | import android.graphics.Region; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 70 | import android.graphics.Typeface; |
| 71 | import android.graphics.Paint.FontMetricsInt; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | import android.os.BatteryStats; |
| 73 | import android.os.Binder; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 74 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | import android.os.Debug; |
| 76 | import android.os.Handler; |
| 77 | import android.os.IBinder; |
| 78 | import android.os.LocalPowerManager; |
| 79 | import android.os.Looper; |
| 80 | import android.os.Message; |
| 81 | import android.os.Parcel; |
| 82 | import android.os.ParcelFileDescriptor; |
| 83 | import android.os.Power; |
| 84 | import android.os.PowerManager; |
| 85 | import android.os.Process; |
| 86 | import android.os.RemoteException; |
| 87 | import android.os.ServiceManager; |
Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 88 | import android.os.StrictMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | import android.os.SystemClock; |
| 90 | import android.os.SystemProperties; |
| 91 | import android.os.TokenWatcher; |
| 92 | import android.provider.Settings; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 93 | import android.util.DisplayMetrics; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | import android.util.EventLog; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 95 | import android.util.Log; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 96 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | import android.util.SparseIntArray; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 98 | import android.util.TypedValue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | import android.view.Display; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 100 | import android.view.DragEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | import android.view.Gravity; |
| 102 | import android.view.IApplicationToken; |
| 103 | import android.view.IOnKeyguardExitResult; |
| 104 | import android.view.IRotationWatcher; |
| 105 | import android.view.IWindow; |
| 106 | import android.view.IWindowManager; |
| 107 | import android.view.IWindowSession; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 108 | import android.view.InputChannel; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 109 | import android.view.InputDevice; |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 110 | import android.view.InputEvent; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 111 | import android.view.InputHandler; |
| 112 | import android.view.InputQueue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | import android.view.KeyEvent; |
| 114 | import android.view.MotionEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | import android.view.Surface; |
| 116 | import android.view.SurfaceSession; |
| 117 | import android.view.View; |
| 118 | import android.view.ViewTreeObserver; |
| 119 | import android.view.WindowManager; |
| 120 | import android.view.WindowManagerImpl; |
| 121 | import android.view.WindowManagerPolicy; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 122 | import android.view.Surface.OutOfResourcesException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | import android.view.WindowManager.LayoutParams; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 124 | import android.view.animation.AccelerateInterpolator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | import android.view.animation.Animation; |
| 126 | import android.view.animation.AnimationUtils; |
| 127 | import android.view.animation.Transformation; |
| 128 | |
| 129 | import java.io.BufferedWriter; |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 130 | import java.io.DataInputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | import java.io.File; |
| 132 | import java.io.FileDescriptor; |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 133 | import java.io.FileInputStream; |
| 134 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | import java.io.IOException; |
| 136 | import java.io.OutputStream; |
| 137 | import java.io.OutputStreamWriter; |
| 138 | import java.io.PrintWriter; |
| 139 | import java.io.StringWriter; |
| 140 | import java.net.Socket; |
| 141 | import java.util.ArrayList; |
| 142 | import java.util.HashMap; |
| 143 | import java.util.HashSet; |
| 144 | import java.util.Iterator; |
| 145 | import java.util.List; |
| 146 | |
| 147 | /** {@hide} */ |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 148 | public class WindowManagerService extends IWindowManager.Stub |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 149 | implements Watchdog.Monitor { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | static final String TAG = "WindowManager"; |
| 151 | static final boolean DEBUG = false; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 152 | static final boolean DEBUG_ADD_REMOVE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | static final boolean DEBUG_FOCUS = false; |
| 154 | static final boolean DEBUG_ANIM = false; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 155 | static final boolean DEBUG_LAYOUT = false; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 156 | static final boolean DEBUG_RESIZE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | static final boolean DEBUG_LAYERS = false; |
| 158 | static final boolean DEBUG_INPUT = false; |
| 159 | static final boolean DEBUG_INPUT_METHOD = false; |
| 160 | static final boolean DEBUG_VISIBILITY = false; |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 161 | static final boolean DEBUG_WINDOW_MOVEMENT = false; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 162 | static final boolean DEBUG_TOKEN_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 | 994ef92 | 2011-01-12 20:06:07 -0800 | [diff] [blame] | 169 | static final boolean DEBUG_DRAG = false; |
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 | |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 206 | /** |
| 207 | * If true, the window manager will do its own custom freezing and general |
| 208 | * management of the screen during rotation. |
| 209 | */ |
| 210 | static final boolean CUSTOM_SCREEN_ROTATION = true; |
| 211 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 212 | // Maximum number of milliseconds to wait for input event injection. |
| 213 | // FIXME is this value reasonable? |
| 214 | private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000; |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 215 | |
| 216 | // Maximum number of milliseconds to wait for input devices to be enumerated before |
| 217 | // proceding with safe mode detection. |
| 218 | private static final int INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS = 1000; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 219 | |
| 220 | // Default input dispatching timeout in nanoseconds. |
| 221 | private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 222 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 224 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 225 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 226 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 227 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | private static final String SYSTEM_SECURE = "ro.secure"; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 229 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | |
| 231 | /** |
| 232 | * Condition waited on by {@link #reenableKeyguard} to know the call to |
| 233 | * the window policy has finished. |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 234 | * This is set to true only if mKeyguardTokenWatcher.acquired() has |
| 235 | * actually disabled the keyguard. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 236 | */ |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 237 | private boolean mKeyguardDisabled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 239 | private static final int ALLOW_DISABLE_YES = 1; |
| 240 | private static final int ALLOW_DISABLE_NO = 0; |
| 241 | private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager |
| 242 | private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher |
| 243 | |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 244 | final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher( |
| 245 | new Handler(), "WindowManagerService.mKeyguardTokenWatcher") { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | public void acquired() { |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 247 | if (shouldAllowDisableKeyguard()) { |
| 248 | mPolicy.enableKeyguard(false); |
| 249 | mKeyguardDisabled = true; |
| 250 | } else { |
| 251 | Log.v(TAG, "Not disabling keyguard since device policy is enforced"); |
| 252 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | } |
| 254 | public void released() { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 255 | mPolicy.enableKeyguard(true); |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 256 | synchronized (mKeyguardTokenWatcher) { |
| 257 | mKeyguardDisabled = false; |
| 258 | mKeyguardTokenWatcher.notifyAll(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | }; |
| 262 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 263 | final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 264 | @Override |
| 265 | public void onReceive(Context context, Intent intent) { |
| 266 | mPolicy.enableKeyguard(true); |
| 267 | synchronized(mKeyguardTokenWatcher) { |
| 268 | // lazily evaluate this next time we're asked to disable keyguard |
| 269 | mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; |
| 270 | mKeyguardDisabled = false; |
| 271 | } |
| 272 | } |
| 273 | }; |
| 274 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | final Context mContext; |
| 276 | |
| 277 | final boolean mHaveInputMethods; |
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 boolean mLimitedAlphaCompositing; |
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 | final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 282 | |
| 283 | final IActivityManager mActivityManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 284 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 285 | final IBatteryStats mBatteryStats; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 286 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 287 | /** |
| 288 | * All currently active sessions with clients. |
| 289 | */ |
| 290 | final HashSet<Session> mSessions = new HashSet<Session>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 291 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | /** |
| 293 | * Mapping from an IWindow IBinder to the server's Window object. |
| 294 | * This is also used as the lock for all of our state. |
| 295 | */ |
| 296 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 297 | |
| 298 | /** |
| 299 | * Mapping from a token IBinder to a WindowToken object. |
| 300 | */ |
| 301 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 302 | new HashMap<IBinder, WindowToken>(); |
| 303 | |
| 304 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 313 | * contains AppWindowToken objects. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | */ |
| 315 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
| 316 | |
| 317 | /** |
| 318 | * Application tokens that are in the process of exiting, but still |
| 319 | * on screen for animations. |
| 320 | */ |
| 321 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 322 | |
| 323 | /** |
| 324 | * List of window tokens that have finished starting their application, |
| 325 | * and now need to have the policy remove their windows. |
| 326 | */ |
| 327 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 328 | |
| 329 | /** |
| 330 | * Z-ordered (bottom-most first) list of all Window objects. |
| 331 | */ |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 332 | final ArrayList<WindowState> mWindows = new ArrayList<WindowState>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 | |
| 334 | /** |
| 335 | * Windows that are being resized. Used so we can tell the client about |
| 336 | * the resize after closing the transaction in which we resized the |
| 337 | * underlying surface. |
| 338 | */ |
| 339 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 340 | |
| 341 | /** |
| 342 | * Windows whose animations have ended and now must be removed. |
| 343 | */ |
| 344 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 345 | |
| 346 | /** |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 347 | * Used when processing mPendingRemove to avoid working on the original array. |
| 348 | */ |
| 349 | WindowState[] mPendingRemoveTmp = new WindowState[20]; |
| 350 | |
| 351 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 352 | * Windows whose surface should be destroyed. |
| 353 | */ |
| 354 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 355 | |
| 356 | /** |
| 357 | * Windows that have lost input focus and are waiting for the new |
| 358 | * focus window to be displayed before they are told about this. |
| 359 | */ |
| 360 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 361 | |
| 362 | /** |
| 363 | * This is set when we have run out of memory, and will either be an empty |
| 364 | * list or contain windows that need to be force removed. |
| 365 | */ |
| 366 | ArrayList<WindowState> mForceRemoves; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 367 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 368 | /** |
| 369 | * Used when rebuilding window list to keep track of windows that have |
| 370 | * been removed. |
| 371 | */ |
| 372 | WindowState[] mRebuildTmp = new WindowState[20]; |
| 373 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | IInputMethodManager mInputMethodManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 375 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | SurfaceSession mFxSession; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 377 | private DimAnimator mDimAnimator = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | Surface mBlurSurface; |
| 379 | boolean mBlurShown; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 380 | Watermark mWatermark; |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 381 | StrictModeFlash mStrictModeFlash; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 382 | ScreenRotationAnimation mScreenRotationAnimation; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 383 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 384 | int mTransactionSequence = 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 385 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 386 | final float[] mTmpFloats = new float[9]; |
| 387 | |
| 388 | boolean mSafeMode; |
| 389 | boolean mDisplayEnabled = false; |
| 390 | boolean mSystemBooted = false; |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 391 | int mInitialDisplayWidth = 0; |
| 392 | int mInitialDisplayHeight = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 393 | int mRotation = 0; |
| 394 | int mRequestedRotation = 0; |
| 395 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 396 | int mLastRotationFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | ArrayList<IRotationWatcher> mRotationWatchers |
| 398 | = new ArrayList<IRotationWatcher>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 399 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 400 | boolean mLayoutNeeded = true; |
| 401 | boolean mAnimationPending = false; |
| 402 | boolean mDisplayFrozen = false; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 403 | boolean mWaitingForConfig = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 404 | boolean mWindowsFreezingScreen = false; |
| 405 | long mFreezeGcPending = 0; |
| 406 | int mAppsFreezingScreen = 0; |
| 407 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 408 | int mLayoutSeq = 0; |
| 409 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 410 | // State while inside of layoutAndPlaceSurfacesLocked(). |
| 411 | boolean mFocusMayChange; |
| 412 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 413 | Configuration mCurConfiguration = new Configuration(); |
| 414 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 415 | // This is held as long as we have the screen frozen, to give us time to |
| 416 | // perform a rotation animation when turning off shows the lock screen which |
| 417 | // changes the orientation. |
| 418 | PowerManager.WakeLock mScreenFrozenLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 419 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 420 | // State management of app transitions. When we are preparing for a |
| 421 | // transition, mNextAppTransition will be the kind of transition to |
| 422 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 423 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 424 | // made visible or hidden at the next transition. |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 425 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 426 | String mNextAppTransitionPackage; |
| 427 | int mNextAppTransitionEnter; |
| 428 | int mNextAppTransitionExit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | boolean mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 430 | boolean mAppTransitionRunning = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 431 | boolean mAppTransitionTimeout = false; |
| 432 | boolean mStartingIconInTransition = false; |
| 433 | boolean mSkipAppTransitionAnimation = false; |
| 434 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 435 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 436 | final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>(); |
| 437 | final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 438 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 439 | Display mDisplay; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 440 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 441 | H mH = new H(); |
| 442 | |
| 443 | WindowState mCurrentFocus = null; |
| 444 | WindowState mLastFocus = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 445 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 446 | // This just indicates the window the input method is on top of, not |
| 447 | // necessarily the window its input is going to. |
| 448 | WindowState mInputMethodTarget = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 466 | // Window currently running an animation that has requested it be detached |
| 467 | // from the wallpaper. This means we need to ensure the wallpaper is |
| 468 | // visible behind it in case it animates in a way that would allow it to be |
| 469 | // seen. |
| 470 | WindowState mWindowDetachedWallpaper = null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 471 | int mWallpaperAnimLayerAdjustment; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 472 | float mLastWallpaperX = -1; |
| 473 | float mLastWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 474 | float mLastWallpaperXStep = -1; |
| 475 | float mLastWallpaperYStep = -1; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 476 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 477 | // changing its scroll position. |
| 478 | WindowState mWaitingOnWallpaper; |
| 479 | // The last time we had a timeout when waiting for a wallpaper. |
| 480 | long mLastWallpaperTimeoutTime; |
| 481 | // We give a wallpaper up to 150ms to finish scrolling. |
| 482 | static final long WALLPAPER_TIMEOUT = 150; |
| 483 | // Time we wait after a timeout before trying to wait again. |
| 484 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 485 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 486 | AppWindowToken mFocusedApp = null; |
| 487 | |
| 488 | PowerManagerService mPowerManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 489 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 490 | float mWindowAnimationScale = 1.0f; |
| 491 | float mTransitionAnimationScale = 1.0f; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 492 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 493 | final InputManager mInputManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 494 | |
| 495 | // Who is holding the screen on. |
| 496 | Session mHoldingScreenOn; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 497 | PowerManager.WakeLock mHoldingScreenWakeLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 498 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 499 | boolean mTurnOnScreen; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 500 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 501 | /** |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 502 | * Drag/drop state |
| 503 | */ |
| 504 | class DragState { |
| 505 | IBinder mToken; |
| 506 | Surface mSurface; |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 507 | int mFlags; |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 508 | IBinder mLocalWin; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 509 | ClipData mData; |
| 510 | ClipDescription mDataDescription; |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 511 | boolean mDragResult; |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 512 | float mCurrentX, mCurrentY; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 513 | float mThumbOffsetX, mThumbOffsetY; |
| 514 | InputChannel mServerChannel, mClientChannel; |
| 515 | WindowState mTargetWindow; |
| 516 | ArrayList<WindowState> mNotifiedWindows; |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 517 | boolean mDragInProgress; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 518 | |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 519 | boolean mPerformDeferredRotation; |
| 520 | int mRotation; |
| 521 | int mAnimFlags; |
| 522 | |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 523 | private final Region mTmpRegion = new Region(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 524 | |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 525 | DragState(IBinder token, Surface surface, int flags, IBinder localWin) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 526 | mToken = token; |
| 527 | mSurface = surface; |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 528 | mFlags = flags; |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 529 | mLocalWin = localWin; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 530 | mNotifiedWindows = new ArrayList<WindowState>(); |
| 531 | } |
| 532 | |
| 533 | void reset() { |
| 534 | if (mSurface != null) { |
| 535 | mSurface.destroy(); |
| 536 | } |
| 537 | mSurface = null; |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 538 | mFlags = 0; |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 539 | mLocalWin = null; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 540 | mToken = null; |
| 541 | mData = null; |
| 542 | mThumbOffsetX = mThumbOffsetY = 0; |
| 543 | mNotifiedWindows = null; |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 544 | mPerformDeferredRotation = false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | void register() { |
| 548 | if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel"); |
| 549 | if (mClientChannel != null) { |
| 550 | Slog.e(TAG, "Duplicate register of drag input channel"); |
| 551 | } else { |
| 552 | InputChannel[] channels = InputChannel.openInputChannelPair("drag"); |
| 553 | mServerChannel = channels[0]; |
| 554 | mClientChannel = channels[1]; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 555 | mInputManager.registerInputChannel(mServerChannel, null); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 556 | InputQueue.registerInputChannel(mClientChannel, mDragInputHandler, |
| 557 | mH.getLooper().getQueue()); |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | void unregister() { |
| 562 | if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel"); |
| 563 | if (mClientChannel == null) { |
| 564 | Slog.e(TAG, "Unregister of nonexistent drag input channel"); |
| 565 | } else { |
| 566 | mInputManager.unregisterInputChannel(mServerChannel); |
| 567 | InputQueue.unregisterInputChannel(mClientChannel); |
| 568 | mClientChannel.dispose(); |
Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 569 | mServerChannel.dispose(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 570 | mClientChannel = null; |
| 571 | mServerChannel = null; |
| 572 | } |
| 573 | } |
| 574 | |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 575 | int getDragLayerLw() { |
| 576 | return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG) |
| 577 | * TYPE_LAYER_MULTIPLIER |
| 578 | + TYPE_LAYER_OFFSET; |
| 579 | } |
| 580 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 581 | /* call out to each visible window/session informing it about the drag |
| 582 | */ |
Chris Tate | b8203e9 | 2010-10-12 14:23:21 -0700 | [diff] [blame] | 583 | void broadcastDragStartedLw(final float touchX, final float touchY) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 584 | // Cache a base-class instance of the clip metadata so that parceling |
| 585 | // works correctly in calling out to the apps. |
Christopher Tate | 1fc014f | 2011-01-19 12:56:26 -0800 | [diff] [blame] | 586 | mDataDescription = (mData != null) ? mData.getDescription() : null; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 587 | mNotifiedWindows.clear(); |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 588 | mDragInProgress = true; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 589 | |
| 590 | if (DEBUG_DRAG) { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 591 | Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")"); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 592 | } |
| 593 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 594 | final int N = mWindows.size(); |
| 595 | for (int i = 0; i < N; i++) { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 596 | sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 597 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the |
| 601 | * designated window is potentially a drop recipient. There are race situations |
| 602 | * around DRAG_ENDED broadcast, so we make sure that once we've declared that |
| 603 | * 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] | 604 | * |
| 605 | * This method clones the 'event' parameter if it's being delivered to the same |
| 606 | * 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] | 607 | */ |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 608 | private void sendDragStartedLw(WindowState newWin, float touchX, float touchY, |
| 609 | ClipDescription desc) { |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 610 | // Don't actually send the event if the drag is supposed to be pinned |
| 611 | // to the originating window but 'newWin' is not that window. |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 612 | if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) { |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 613 | final IBinder winBinder = newWin.mClient.asBinder(); |
| 614 | if (winBinder != mLocalWin) { |
| 615 | if (DEBUG_DRAG) { |
| 616 | Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin); |
| 617 | } |
| 618 | return; |
| 619 | } |
| 620 | } |
| 621 | |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 622 | if (mDragInProgress && newWin.isPotentialDragTarget()) { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 623 | DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED, |
| 624 | touchX - newWin.mFrame.left, touchY - newWin.mFrame.top, |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 625 | null, desc, null, false); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 626 | try { |
| 627 | newWin.mClient.dispatchDragEvent(event); |
| 628 | // track each window that we've notified that the drag is starting |
| 629 | mNotifiedWindows.add(newWin); |
| 630 | } catch (RemoteException e) { |
| 631 | Slog.w(TAG, "Unable to drag-start window " + newWin); |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 632 | } finally { |
| 633 | // if the callee was local, the dispatch has already recycled the event |
| 634 | if (Process.myPid() != newWin.mSession.mPid) { |
| 635 | event.recycle(); |
| 636 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 637 | } |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | /* helper - construct and send a DRAG_STARTED event only if the window has not |
| 642 | * previously been notified, i.e. it became visible after the drag operation |
| 643 | * was begun. This is a rare case. |
| 644 | */ |
| 645 | private void sendDragStartedIfNeededLw(WindowState newWin) { |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 646 | if (mDragInProgress) { |
| 647 | // If we have sent the drag-started, we needn't do so again |
| 648 | for (WindowState ws : mNotifiedWindows) { |
| 649 | if (ws == newWin) { |
| 650 | return; |
| 651 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 652 | } |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 653 | if (DEBUG_DRAG) { |
Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 654 | Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin); |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 655 | } |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 656 | sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 657 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 658 | } |
| 659 | |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 660 | void broadcastDragEndedLw() { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 661 | if (DEBUG_DRAG) { |
| 662 | Slog.d(TAG, "broadcasting DRAG_ENDED"); |
| 663 | } |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 664 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED, |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 665 | 0, 0, null, null, null, mDragResult); |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 666 | for (WindowState ws: mNotifiedWindows) { |
| 667 | try { |
| 668 | ws.mClient.dispatchDragEvent(evt); |
| 669 | } catch (RemoteException e) { |
| 670 | Slog.w(TAG, "Unable to drag-end window " + ws); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 671 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 672 | } |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 673 | mNotifiedWindows.clear(); |
| 674 | mDragInProgress = false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 675 | evt.recycle(); |
| 676 | } |
| 677 | |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 678 | void endDragLw() { |
| 679 | mDragState.broadcastDragEndedLw(); |
| 680 | |
| 681 | // stop intercepting input |
| 682 | mDragState.unregister(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 683 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 684 | mInputMonitor.updateInputWindowsLw(); |
| 685 | |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 686 | // Retain the parameters of any deferred rotation operation so |
| 687 | // that we can perform it after the reset / unref of the drag state |
| 688 | final boolean performRotation = mPerformDeferredRotation; |
| 689 | final int rotation = mRotation; |
| 690 | final int animFlags = mAnimFlags; |
| 691 | |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 692 | // free our resources and drop all the object references |
| 693 | mDragState.reset(); |
| 694 | mDragState = null; |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 695 | |
| 696 | // Now that we've officially ended the drag, execute any |
| 697 | // deferred rotation |
| 698 | if (performRotation) { |
| 699 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-drag rotation"); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 700 | boolean changed = setRotationUncheckedLocked(rotation, animFlags, false); |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 701 | if (changed) { |
| 702 | sendNewConfiguration(); |
| 703 | } |
| 704 | } |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 705 | } |
| 706 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 707 | void notifyMoveLw(float x, float y) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 708 | final int myPid = Process.myPid(); |
| 709 | |
| 710 | // Move the surface to the given touch |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 711 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION notifyMoveLw"); |
Christopher Tate | f01af75 | 2011-01-19 16:22:07 -0800 | [diff] [blame] | 712 | Surface.openTransaction(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 713 | try { |
| 714 | mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY)); |
| 715 | } finally { |
Christopher Tate | f01af75 | 2011-01-19 16:22:07 -0800 | [diff] [blame] | 716 | Surface.closeTransaction(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 717 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION notifyMoveLw"); |
| 718 | } |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 719 | |
| 720 | // Tell the affected window |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 721 | WindowState touchedWin = getTouchedWinAtPointLw(x, y); |
Christopher Tate | f01af75 | 2011-01-19 16:22:07 -0800 | [diff] [blame] | 722 | if (touchedWin == null) { |
| 723 | if (DEBUG_DRAG) Slog.d(TAG, "No touched win at x=" + x + " y=" + y); |
| 724 | return; |
| 725 | } |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 726 | if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) { |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 727 | final IBinder touchedBinder = touchedWin.mClient.asBinder(); |
| 728 | if (touchedBinder != mLocalWin) { |
| 729 | // This drag is pinned only to the originating window, but the drag |
| 730 | // point is outside that window. Pretend it's over empty space. |
| 731 | touchedWin = null; |
| 732 | } |
| 733 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 734 | try { |
| 735 | // have we dragged over a new window? |
| 736 | if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) { |
| 737 | if (DEBUG_DRAG) { |
| 738 | Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow); |
| 739 | } |
| 740 | // force DRAG_EXITED_EVENT if appropriate |
| 741 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED, |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 742 | x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top, |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 743 | null, null, null, false); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 744 | mTargetWindow.mClient.dispatchDragEvent(evt); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 745 | if (myPid != mTargetWindow.mSession.mPid) { |
| 746 | evt.recycle(); |
| 747 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 748 | } |
| 749 | if (touchedWin != null) { |
Chris Tate | 9d1ab88 | 2010-11-02 15:55:39 -0700 | [diff] [blame] | 750 | if (false && DEBUG_DRAG) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 751 | Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin); |
| 752 | } |
| 753 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION, |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 754 | x - touchedWin.mFrame.left, y - touchedWin.mFrame.top, |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 755 | null, null, null, false); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 756 | touchedWin.mClient.dispatchDragEvent(evt); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 757 | if (myPid != touchedWin.mSession.mPid) { |
| 758 | evt.recycle(); |
| 759 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 760 | } |
| 761 | } catch (RemoteException e) { |
| 762 | Slog.w(TAG, "can't send drag notification to windows"); |
| 763 | } |
| 764 | mTargetWindow = touchedWin; |
| 765 | } |
| 766 | |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 767 | // Tell the drop target about the data. Returns 'true' if we can immediately |
| 768 | // dispatch the global drag-ended message, 'false' if we need to wait for a |
| 769 | // result from the recipient. |
| 770 | boolean notifyDropLw(float x, float y) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 771 | WindowState touchedWin = getTouchedWinAtPointLw(x, y); |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 772 | if (touchedWin == null) { |
| 773 | // "drop" outside a valid window -- no recipient to apply a |
| 774 | // timeout to, and we can send the drag-ended message immediately. |
| 775 | mDragResult = false; |
| 776 | return true; |
| 777 | } |
| 778 | |
| 779 | if (DEBUG_DRAG) { |
| 780 | Slog.d(TAG, "sending DROP to " + touchedWin); |
| 781 | } |
| 782 | final int myPid = Process.myPid(); |
| 783 | final IBinder token = touchedWin.mClient.asBinder(); |
| 784 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP, |
| 785 | x - touchedWin.mFrame.left, y - touchedWin.mFrame.top, |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 786 | null, null, mData, false); |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 787 | try { |
| 788 | touchedWin.mClient.dispatchDragEvent(evt); |
| 789 | |
| 790 | // 5 second timeout for this window to respond to the drop |
| 791 | mH.removeMessages(H.DRAG_END_TIMEOUT, token); |
| 792 | Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token); |
| 793 | mH.sendMessageDelayed(msg, 5000); |
| 794 | } catch (RemoteException e) { |
| 795 | Slog.w(TAG, "can't send drop notification to win " + touchedWin); |
| 796 | return true; |
| 797 | } finally { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 798 | if (myPid != touchedWin.mSession.mPid) { |
| 799 | evt.recycle(); |
| 800 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 801 | } |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 802 | mToken = token; |
| 803 | return false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | // Find the visible, touch-deliverable window under the given point |
| 807 | private WindowState getTouchedWinAtPointLw(float xf, float yf) { |
| 808 | WindowState touchedWin = null; |
| 809 | final int x = (int) xf; |
| 810 | final int y = (int) yf; |
| 811 | final ArrayList<WindowState> windows = mWindows; |
| 812 | final int N = windows.size(); |
| 813 | for (int i = N - 1; i >= 0; i--) { |
| 814 | WindowState child = windows.get(i); |
| 815 | final int flags = child.mAttrs.flags; |
| 816 | if (!child.isVisibleLw()) { |
| 817 | // not visible == don't tell about drags |
| 818 | continue; |
| 819 | } |
| 820 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 821 | // not touchable == don't tell about drags |
| 822 | continue; |
| 823 | } |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 824 | |
| 825 | child.getTouchableRegion(mTmpRegion); |
| 826 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 827 | final int touchFlags = flags & |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 828 | (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 829 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
| 830 | if (mTmpRegion.contains(x, y) || touchFlags == 0) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 831 | // Found it |
| 832 | touchedWin = child; |
| 833 | break; |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | return touchedWin; |
| 838 | } |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 839 | |
| 840 | void setDeferredRotation(int rotation, int animFlags) { |
| 841 | mRotation = rotation; |
| 842 | mAnimFlags = animFlags; |
| 843 | mPerformDeferredRotation = true; |
| 844 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | DragState mDragState = null; |
| 848 | private final InputHandler mDragInputHandler = new BaseInputHandler() { |
| 849 | @Override |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 850 | public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) { |
| 851 | boolean handled = false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 852 | try { |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 853 | if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0 |
| 854 | && mDragState != null) { |
| 855 | boolean endDrag = false; |
| 856 | final float newX = event.getRawX(); |
| 857 | final float newY = event.getRawY(); |
| 858 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 859 | switch (event.getAction()) { |
| 860 | case MotionEvent.ACTION_DOWN: { |
| 861 | if (DEBUG_DRAG) { |
| 862 | Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer"); |
| 863 | } |
| 864 | } break; |
| 865 | |
| 866 | case MotionEvent.ACTION_MOVE: { |
| 867 | synchronized (mWindowMap) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 868 | // move the surface and tell the involved window(s) where we are |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 869 | mDragState.notifyMoveLw(newX, newY); |
| 870 | } |
| 871 | } break; |
| 872 | |
| 873 | case MotionEvent.ACTION_UP: { |
| 874 | if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at " |
| 875 | + newX + "," + newY); |
| 876 | synchronized (mWindowMap) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 877 | endDrag = mDragState.notifyDropLw(newX, newY); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 878 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 879 | } break; |
| 880 | |
| 881 | case MotionEvent.ACTION_CANCEL: { |
| 882 | if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!"); |
| 883 | endDrag = true; |
| 884 | } break; |
| 885 | } |
| 886 | |
| 887 | if (endDrag) { |
| 888 | if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state"); |
| 889 | // tell all the windows that the drag has ended |
Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 890 | synchronized (mWindowMap) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 891 | mDragState.endDragLw(); |
Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 892 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 893 | } |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 894 | |
| 895 | handled = true; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 896 | } |
| 897 | } catch (Exception e) { |
| 898 | Slog.e(TAG, "Exception caught by drag handleMotion", e); |
| 899 | } finally { |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 900 | finishedCallback.finished(handled); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 901 | } |
| 902 | } |
| 903 | }; |
| 904 | |
| 905 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 906 | * Whether the UI is currently running in touch mode (not showing |
| 907 | * navigational focus because the user is directly pressing the screen). |
| 908 | */ |
| 909 | boolean mInTouchMode = false; |
| 910 | |
| 911 | private ViewServer mViewServer; |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 912 | private ArrayList<WindowChangeListener> mWindowChangeListeners = |
| 913 | new ArrayList<WindowChangeListener>(); |
| 914 | private boolean mWindowsChanged = false; |
| 915 | |
| 916 | public interface WindowChangeListener { |
| 917 | public void windowsChanged(); |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 918 | public void focusChanged(); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 919 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 920 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 921 | final Configuration mTempConfiguration = new Configuration(); |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 922 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 923 | |
| 924 | // The frame use to limit the size of the app running in compatibility mode. |
| 925 | Rect mCompatibleScreenFrame = new Rect(); |
| 926 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 927 | Surface mBackgroundFillerSurface = null; |
| 928 | boolean mBackgroundFillerShown = false; |
| 929 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 930 | public static WindowManagerService main(Context context, |
| 931 | PowerManagerService pm, boolean haveInputMethods) { |
| 932 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 933 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 934 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 935 | synchronized (thr) { |
| 936 | while (thr.mService == null) { |
| 937 | try { |
| 938 | thr.wait(); |
| 939 | } catch (InterruptedException e) { |
| 940 | } |
| 941 | } |
| 942 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 943 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 944 | return thr.mService; |
| 945 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 946 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 947 | static class WMThread extends Thread { |
| 948 | WindowManagerService mService; |
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 | private final Context mContext; |
| 951 | private final PowerManagerService mPM; |
| 952 | private final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 953 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 954 | public WMThread(Context context, PowerManagerService pm, |
| 955 | boolean haveInputMethods) { |
| 956 | super("WindowManager"); |
| 957 | mContext = context; |
| 958 | mPM = pm; |
| 959 | mHaveInputMethods = haveInputMethods; |
| 960 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 961 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 962 | public void run() { |
| 963 | Looper.prepare(); |
| 964 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 965 | mHaveInputMethods); |
| 966 | android.os.Process.setThreadPriority( |
| 967 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 968 | android.os.Process.setCanSelfBackground(false); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 969 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 970 | synchronized (this) { |
| 971 | mService = s; |
| 972 | notifyAll(); |
| 973 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 974 | |
Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 975 | // For debug builds, log event loop stalls to dropbox for analysis. |
| 976 | if (StrictMode.conditionallyEnableDebugLogging()) { |
| 977 | Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper"); |
| 978 | } |
| 979 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 980 | Looper.loop(); |
| 981 | } |
| 982 | } |
| 983 | |
| 984 | static class PolicyThread extends Thread { |
| 985 | private final WindowManagerPolicy mPolicy; |
| 986 | private final WindowManagerService mService; |
| 987 | private final Context mContext; |
| 988 | private final PowerManagerService mPM; |
| 989 | boolean mRunning = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 990 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 991 | public PolicyThread(WindowManagerPolicy policy, |
| 992 | WindowManagerService service, Context context, |
| 993 | PowerManagerService pm) { |
| 994 | super("WindowManagerPolicy"); |
| 995 | mPolicy = policy; |
| 996 | mService = service; |
| 997 | mContext = context; |
| 998 | mPM = pm; |
| 999 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1000 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1001 | public void run() { |
| 1002 | Looper.prepare(); |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 1003 | WindowManagerPolicyThread.set(this, Looper.myLooper()); |
| 1004 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1005 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1006 | // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1007 | android.os.Process.setThreadPriority( |
| 1008 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 1009 | android.os.Process.setCanSelfBackground(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1010 | mPolicy.init(mContext, mService, mPM); |
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 (this) { |
| 1013 | mRunning = true; |
| 1014 | notifyAll(); |
| 1015 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1016 | |
Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 1017 | // For debug builds, log event loop stalls to dropbox for analysis. |
| 1018 | if (StrictMode.conditionallyEnableDebugLogging()) { |
| 1019 | Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper"); |
| 1020 | } |
| 1021 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1022 | Looper.loop(); |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | private WindowManagerService(Context context, PowerManagerService pm, |
| 1027 | boolean haveInputMethods) { |
| 1028 | mContext = context; |
| 1029 | mHaveInputMethods = haveInputMethods; |
| 1030 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 1031 | com.android.internal.R.bool.config_sf_limitedAlpha); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1032 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1033 | mPowerManager = pm; |
| 1034 | mPowerManager.setPolicy(mPolicy); |
| 1035 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 1036 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 1037 | "SCREEN_FROZEN"); |
| 1038 | mScreenFrozenLock.setReferenceCounted(false); |
| 1039 | |
| 1040 | mActivityManager = ActivityManagerNative.getDefault(); |
| 1041 | mBatteryStats = BatteryStatsService.getService(); |
| 1042 | |
| 1043 | // Get persisted window scale setting |
| 1044 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 1045 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 1046 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 1047 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1048 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1049 | // Track changes to DevicePolicyManager state so we can enable/disable keyguard. |
| 1050 | IntentFilter filter = new IntentFilter(); |
| 1051 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 1052 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 1053 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1054 | mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 1055 | "KEEP_SCREEN_ON_FLAG"); |
| 1056 | mHoldingScreenWakeLock.setReferenceCounted(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1057 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1058 | mInputManager = new InputManager(context, this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1059 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1060 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 1061 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1062 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1063 | synchronized (thr) { |
| 1064 | while (!thr.mRunning) { |
| 1065 | try { |
| 1066 | thr.wait(); |
| 1067 | } catch (InterruptedException e) { |
| 1068 | } |
| 1069 | } |
| 1070 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1071 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1072 | mInputManager.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1073 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1074 | // Add ourself to the Watchdog monitors. |
| 1075 | Watchdog.getInstance().addMonitor(this); |
| 1076 | } |
| 1077 | |
| 1078 | @Override |
| 1079 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 1080 | throws RemoteException { |
| 1081 | try { |
| 1082 | return super.onTransact(code, data, reply, flags); |
| 1083 | } catch (RuntimeException e) { |
| 1084 | // The window manager only throws security exceptions, so let's |
| 1085 | // log all others. |
| 1086 | if (!(e instanceof SecurityException)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1087 | Slog.e(TAG, "Window Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1088 | } |
| 1089 | throw e; |
| 1090 | } |
| 1091 | } |
| 1092 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1093 | private void placeWindowAfter(WindowState pos, WindowState window) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1094 | final int i = mWindows.indexOf(pos); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1095 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1096 | TAG, "Adding window " + window + " at " |
| 1097 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 1098 | mWindows.add(i+1, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1099 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1100 | } |
| 1101 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1102 | private void placeWindowBefore(WindowState pos, WindowState window) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1103 | final int i = mWindows.indexOf(pos); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1104 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1105 | TAG, "Adding window " + window + " at " |
| 1106 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 1107 | mWindows.add(i, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1108 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | //This method finds out the index of a window that has the same app token as |
| 1112 | //win. used for z ordering the windows in mWindows |
| 1113 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 1114 | //use a local variable to cache mWindows |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1115 | ArrayList<WindowState> localmWindows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1116 | int jmax = localmWindows.size(); |
| 1117 | if(jmax == 0) { |
| 1118 | return -1; |
| 1119 | } |
| 1120 | for(int j = (jmax-1); j >= 0; j--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1121 | WindowState wentry = localmWindows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1122 | if(wentry.mAppToken == win.mAppToken) { |
| 1123 | return j; |
| 1124 | } |
| 1125 | } |
| 1126 | return -1; |
| 1127 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1128 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1129 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 1130 | final IWindow client = win.mClient; |
| 1131 | final WindowToken token = win.mToken; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1132 | final ArrayList<WindowState> localmWindows = mWindows; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1133 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1134 | final int N = localmWindows.size(); |
| 1135 | final WindowState attached = win.mAttachedWindow; |
| 1136 | int i; |
| 1137 | if (attached == null) { |
| 1138 | int tokenWindowsPos = token.windows.size(); |
| 1139 | if (token.appWindowToken != null) { |
| 1140 | int index = tokenWindowsPos-1; |
| 1141 | if (index >= 0) { |
| 1142 | // If this application has existing windows, we |
| 1143 | // simply place the new window on top of them... but |
| 1144 | // keep the starting window on top. |
| 1145 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 1146 | // Base windows go behind everything else. |
| 1147 | placeWindowBefore(token.windows.get(0), win); |
| 1148 | tokenWindowsPos = 0; |
| 1149 | } else { |
| 1150 | AppWindowToken atoken = win.mAppToken; |
| 1151 | if (atoken != null && |
| 1152 | token.windows.get(index) == atoken.startingWindow) { |
| 1153 | placeWindowBefore(token.windows.get(index), win); |
| 1154 | tokenWindowsPos--; |
| 1155 | } else { |
| 1156 | int newIdx = findIdxBasedOnAppTokens(win); |
| 1157 | if(newIdx != -1) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1158 | //there is a window above this one associated with the same |
| 1159 | //apptoken note that the window could be a floating window |
| 1160 | //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] | 1161 | //windows associated with this token. |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1162 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 1163 | Slog.v(TAG, "Adding window " + win + " at " |
| 1164 | + (newIdx+1) + " of " + N); |
| 1165 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1166 | localmWindows.add(newIdx+1, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1167 | mWindowsChanged = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1168 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1169 | } |
| 1170 | } |
| 1171 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1172 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1173 | TAG, "Figuring out where to add app window " |
| 1174 | + client.asBinder() + " (token=" + token + ")"); |
| 1175 | // Figure out where the window should go, based on the |
| 1176 | // order of applications. |
| 1177 | final int NA = mAppTokens.size(); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1178 | WindowState pos = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1179 | for (i=NA-1; i>=0; i--) { |
| 1180 | AppWindowToken t = mAppTokens.get(i); |
| 1181 | if (t == token) { |
| 1182 | i--; |
| 1183 | break; |
| 1184 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1185 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1186 | // We haven't reached the token yet; if this token |
| 1187 | // is not going to the bottom and has windows, we can |
| 1188 | // use it as an anchor for when we do reach the token. |
| 1189 | if (!t.sendingToBottom && t.windows.size() > 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1190 | pos = t.windows.get(0); |
| 1191 | } |
| 1192 | } |
| 1193 | // We now know the index into the apps. If we found |
| 1194 | // an app window above, that gives us the position; else |
| 1195 | // we need to look some more. |
| 1196 | if (pos != null) { |
| 1197 | // Move behind any windows attached to this one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1198 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1199 | if (atoken != null) { |
| 1200 | final int NC = atoken.windows.size(); |
| 1201 | if (NC > 0) { |
| 1202 | WindowState bottom = atoken.windows.get(0); |
| 1203 | if (bottom.mSubLayer < 0) { |
| 1204 | pos = bottom; |
| 1205 | } |
| 1206 | } |
| 1207 | } |
| 1208 | placeWindowBefore(pos, win); |
| 1209 | } else { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1210 | // Continue looking down until we find the first |
| 1211 | // token that has windows. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1212 | while (i >= 0) { |
| 1213 | AppWindowToken t = mAppTokens.get(i); |
| 1214 | final int NW = t.windows.size(); |
| 1215 | if (NW > 0) { |
| 1216 | pos = t.windows.get(NW-1); |
| 1217 | break; |
| 1218 | } |
| 1219 | i--; |
| 1220 | } |
| 1221 | if (pos != null) { |
| 1222 | // Move in front of any windows attached to this |
| 1223 | // one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1224 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1225 | if (atoken != null) { |
| 1226 | final int NC = atoken.windows.size(); |
| 1227 | if (NC > 0) { |
| 1228 | WindowState top = atoken.windows.get(NC-1); |
| 1229 | if (top.mSubLayer >= 0) { |
| 1230 | pos = top; |
| 1231 | } |
| 1232 | } |
| 1233 | } |
| 1234 | placeWindowAfter(pos, win); |
| 1235 | } else { |
| 1236 | // Just search for the start of this layer. |
| 1237 | final int myLayer = win.mBaseLayer; |
| 1238 | for (i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1239 | WindowState w = localmWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1240 | if (w.mBaseLayer > myLayer) { |
| 1241 | break; |
| 1242 | } |
| 1243 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1244 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 1245 | Slog.v(TAG, "Adding window " + win + " at " |
| 1246 | + i + " of " + N); |
| 1247 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1248 | localmWindows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1249 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1250 | } |
| 1251 | } |
| 1252 | } |
| 1253 | } else { |
| 1254 | // Figure out where window should go, based on layer. |
| 1255 | final int myLayer = win.mBaseLayer; |
| 1256 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1257 | if (localmWindows.get(i).mBaseLayer <= myLayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1258 | i++; |
| 1259 | break; |
| 1260 | } |
| 1261 | } |
| 1262 | if (i < 0) i = 0; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1263 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1264 | TAG, "Adding window " + win + " at " |
| 1265 | + i + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1266 | localmWindows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1267 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1268 | } |
| 1269 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1270 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1271 | token.windows.add(tokenWindowsPos, win); |
| 1272 | } |
| 1273 | |
| 1274 | } else { |
| 1275 | // Figure out this window's ordering relative to the window |
| 1276 | // it is attached to. |
| 1277 | final int NA = token.windows.size(); |
| 1278 | final int sublayer = win.mSubLayer; |
| 1279 | int largestSublayer = Integer.MIN_VALUE; |
| 1280 | WindowState windowWithLargestSublayer = null; |
| 1281 | for (i=0; i<NA; i++) { |
| 1282 | WindowState w = token.windows.get(i); |
| 1283 | final int wSublayer = w.mSubLayer; |
| 1284 | if (wSublayer >= largestSublayer) { |
| 1285 | largestSublayer = wSublayer; |
| 1286 | windowWithLargestSublayer = w; |
| 1287 | } |
| 1288 | if (sublayer < 0) { |
| 1289 | // For negative sublayers, we go below all windows |
| 1290 | // in the same sublayer. |
| 1291 | if (wSublayer >= sublayer) { |
| 1292 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1293 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1294 | token.windows.add(i, win); |
| 1295 | } |
| 1296 | placeWindowBefore( |
| 1297 | wSublayer >= 0 ? attached : w, win); |
| 1298 | break; |
| 1299 | } |
| 1300 | } else { |
| 1301 | // For positive sublayers, we go above all windows |
| 1302 | // in the same sublayer. |
| 1303 | if (wSublayer > sublayer) { |
| 1304 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1305 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1306 | token.windows.add(i, win); |
| 1307 | } |
| 1308 | placeWindowBefore(w, win); |
| 1309 | break; |
| 1310 | } |
| 1311 | } |
| 1312 | } |
| 1313 | if (i >= NA) { |
| 1314 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1315 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1316 | token.windows.add(win); |
| 1317 | } |
| 1318 | if (sublayer < 0) { |
| 1319 | placeWindowBefore(attached, win); |
| 1320 | } else { |
| 1321 | placeWindowAfter(largestSublayer >= 0 |
| 1322 | ? windowWithLargestSublayer |
| 1323 | : attached, |
| 1324 | win); |
| 1325 | } |
| 1326 | } |
| 1327 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1328 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1329 | if (win.mAppToken != null && addToToken) { |
| 1330 | win.mAppToken.allAppWindows.add(win); |
| 1331 | } |
| 1332 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1333 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1334 | static boolean canBeImeTarget(WindowState w) { |
| 1335 | final int fl = w.mAttrs.flags |
| 1336 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 1337 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 1338 | return w.isVisibleOrAdding(); |
| 1339 | } |
| 1340 | return false; |
| 1341 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1342 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1343 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1344 | final ArrayList<WindowState> localmWindows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1345 | final int N = localmWindows.size(); |
| 1346 | WindowState w = null; |
| 1347 | int i = N; |
| 1348 | while (i > 0) { |
| 1349 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1350 | w = localmWindows.get(i); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1351 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1352 | //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1353 | // + Integer.toHexString(w.mAttrs.flags)); |
| 1354 | if (canBeImeTarget(w)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1355 | //Slog.i(TAG, "Putting input method here!"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1356 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1357 | // Yet more tricksyness! If this window is a "starting" |
| 1358 | // window, we do actually want to be on top of it, but |
| 1359 | // it is not -really- where input will go. So if the caller |
| 1360 | // is not actually looking to move the IME, look down below |
| 1361 | // for a real window to target... |
| 1362 | if (!willMove |
| 1363 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 1364 | && i > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1365 | WindowState wb = localmWindows.get(i-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1366 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 1367 | i--; |
| 1368 | w = wb; |
| 1369 | } |
| 1370 | } |
| 1371 | break; |
| 1372 | } |
| 1373 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1374 | |
Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1375 | // Now, a special case -- if the last target's window is in the |
| 1376 | // process of exiting, and is above the new target, keep on the |
| 1377 | // last target to avoid flicker. Consider for example a Dialog with |
| 1378 | // the IME shown: when the Dialog is dismissed, we want to keep |
| 1379 | // the IME above it until it is completely gone so it doesn't drop |
| 1380 | // behind the dialog or its full-screen scrim. |
| 1381 | if (mInputMethodTarget != null && w != null |
| 1382 | && mInputMethodTarget.isDisplayedLw() |
| 1383 | && mInputMethodTarget.mExiting) { |
| 1384 | if (mInputMethodTarget.mAnimLayer > w.mAnimLayer) { |
| 1385 | w = mInputMethodTarget; |
| 1386 | i = localmWindows.indexOf(w); |
| 1387 | } |
| 1388 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1389 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1390 | 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] | 1391 | + w + " willMove=" + willMove); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1392 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1393 | if (willMove && w != null) { |
| 1394 | final WindowState curTarget = mInputMethodTarget; |
| 1395 | if (curTarget != null && curTarget.mAppToken != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1396 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1397 | // Now some fun for dealing with window animations that |
| 1398 | // modify the Z order. We need to look at all windows below |
| 1399 | // the current target that are in this app, finding the highest |
| 1400 | // visible one in layering. |
| 1401 | AppWindowToken token = curTarget.mAppToken; |
| 1402 | WindowState highestTarget = null; |
| 1403 | int highestPos = 0; |
| 1404 | if (token.animating || token.animation != null) { |
| 1405 | int pos = 0; |
| 1406 | pos = localmWindows.indexOf(curTarget); |
| 1407 | while (pos >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1408 | WindowState win = localmWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1409 | if (win.mAppToken != token) { |
| 1410 | break; |
| 1411 | } |
| 1412 | if (!win.mRemoved) { |
| 1413 | if (highestTarget == null || win.mAnimLayer > |
| 1414 | highestTarget.mAnimLayer) { |
| 1415 | highestTarget = win; |
| 1416 | highestPos = pos; |
| 1417 | } |
| 1418 | } |
| 1419 | pos--; |
| 1420 | } |
| 1421 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1422 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1423 | if (highestTarget != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1424 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1425 | + mNextAppTransition + " " + highestTarget |
| 1426 | + " animating=" + highestTarget.isAnimating() |
| 1427 | + " layer=" + highestTarget.mAnimLayer |
| 1428 | + " new layer=" + w.mAnimLayer); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1429 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1430 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1431 | // If we are currently setting up for an animation, |
| 1432 | // hold everything until we can find out what will happen. |
| 1433 | mInputMethodTargetWaitingAnim = true; |
| 1434 | mInputMethodTarget = highestTarget; |
| 1435 | return highestPos + 1; |
| 1436 | } else if (highestTarget.isAnimating() && |
| 1437 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 1438 | // If the window we are currently targeting is involved |
| 1439 | // with an animation, and it is on top of the next target |
| 1440 | // we will be over, then hold off on moving until |
| 1441 | // that is done. |
| 1442 | mInputMethodTarget = highestTarget; |
| 1443 | return highestPos + 1; |
| 1444 | } |
| 1445 | } |
| 1446 | } |
| 1447 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1448 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1449 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1450 | if (w != null) { |
| 1451 | if (willMove) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1452 | if (DEBUG_INPUT_METHOD) { |
| 1453 | RuntimeException e = null; |
| 1454 | if (!HIDE_STACK_CRAWLS) { |
| 1455 | e = new RuntimeException(); |
| 1456 | e.fillInStackTrace(); |
| 1457 | } |
| 1458 | Slog.w(TAG, "Moving IM target from " |
| 1459 | + mInputMethodTarget + " to " + w, e); |
| 1460 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1461 | mInputMethodTarget = w; |
| 1462 | if (w.mAppToken != null) { |
| 1463 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 1464 | } else { |
| 1465 | setInputMethodAnimLayerAdjustment(0); |
| 1466 | } |
| 1467 | } |
| 1468 | return i+1; |
| 1469 | } |
| 1470 | if (willMove) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1471 | if (DEBUG_INPUT_METHOD) { |
| 1472 | RuntimeException e = null; |
| 1473 | if (!HIDE_STACK_CRAWLS) { |
| 1474 | e = new RuntimeException(); |
| 1475 | e.fillInStackTrace(); |
| 1476 | } |
| 1477 | Slog.w(TAG, "Moving IM target from " |
| 1478 | + mInputMethodTarget + " to null", e); |
| 1479 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1480 | mInputMethodTarget = null; |
| 1481 | setInputMethodAnimLayerAdjustment(0); |
| 1482 | } |
| 1483 | return -1; |
| 1484 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1485 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1486 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1487 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1488 | if (pos >= 0) { |
| 1489 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1490 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1491 | TAG, "Adding input method window " + win + " at " + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1492 | mWindows.add(pos, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1493 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1494 | moveInputMethodDialogsLocked(pos+1); |
| 1495 | return; |
| 1496 | } |
| 1497 | win.mTargetAppToken = null; |
| 1498 | addWindowToListInOrderLocked(win, true); |
| 1499 | moveInputMethodDialogsLocked(pos); |
| 1500 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1501 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1502 | void setInputMethodAnimLayerAdjustment(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1503 | 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] | 1504 | mInputMethodAnimLayerAdjustment = adj; |
| 1505 | WindowState imw = mInputMethodWindow; |
| 1506 | if (imw != null) { |
| 1507 | imw.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1508 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1509 | + " anim layer: " + imw.mAnimLayer); |
| 1510 | int wi = imw.mChildWindows.size(); |
| 1511 | while (wi > 0) { |
| 1512 | wi--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1513 | WindowState cw = imw.mChildWindows.get(wi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1514 | cw.mAnimLayer = cw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1515 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1516 | + " anim layer: " + cw.mAnimLayer); |
| 1517 | } |
| 1518 | } |
| 1519 | int di = mInputMethodDialogs.size(); |
| 1520 | while (di > 0) { |
| 1521 | di --; |
| 1522 | imw = mInputMethodDialogs.get(di); |
| 1523 | imw.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1524 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1525 | + " anim layer: " + imw.mAnimLayer); |
| 1526 | } |
| 1527 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1528 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1529 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1530 | int wpos = mWindows.indexOf(win); |
| 1531 | if (wpos >= 0) { |
| 1532 | if (wpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1533 | 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] | 1534 | mWindows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1535 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1536 | int NC = win.mChildWindows.size(); |
| 1537 | while (NC > 0) { |
| 1538 | NC--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1539 | WindowState cw = win.mChildWindows.get(NC); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1540 | int cpos = mWindows.indexOf(cw); |
| 1541 | if (cpos >= 0) { |
| 1542 | if (cpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1543 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1544 | + cpos + ": " + cw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1545 | mWindows.remove(cpos); |
| 1546 | } |
| 1547 | } |
| 1548 | } |
| 1549 | return interestingPos; |
| 1550 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1551 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1552 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1553 | addWindowToListInOrderLocked(win, false); |
| 1554 | // This is a hack to get all of the child windows added as well |
| 1555 | // at the right position. Child windows should be rare and |
| 1556 | // this case should be rare, so it shouldn't be that big a deal. |
| 1557 | int wpos = mWindows.indexOf(win); |
| 1558 | if (wpos >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1559 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1560 | + ": " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1561 | mWindows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1562 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1563 | reAddWindowLocked(wpos, win); |
| 1564 | } |
| 1565 | } |
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 | void logWindowList(String prefix) { |
| 1568 | int N = mWindows.size(); |
| 1569 | while (N > 0) { |
| 1570 | N--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1571 | Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1572 | } |
| 1573 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1574 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1575 | void moveInputMethodDialogsLocked(int pos) { |
| 1576 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1577 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1578 | final int N = dialogs.size(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1579 | 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] | 1580 | for (int i=0; i<N; i++) { |
| 1581 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1582 | } |
| 1583 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1584 | Slog.v(TAG, "Window list w/pos=" + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1585 | logWindowList(" "); |
| 1586 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1587 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1588 | if (pos >= 0) { |
| 1589 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1590 | if (pos < mWindows.size()) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1591 | WindowState wp = mWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1592 | if (wp == mInputMethodWindow) { |
| 1593 | pos++; |
| 1594 | } |
| 1595 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1596 | 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] | 1597 | for (int i=0; i<N; i++) { |
| 1598 | WindowState win = dialogs.get(i); |
| 1599 | win.mTargetAppToken = targetAppToken; |
| 1600 | pos = reAddWindowLocked(pos, win); |
| 1601 | } |
| 1602 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1603 | Slog.v(TAG, "Final window list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1604 | logWindowList(" "); |
| 1605 | } |
| 1606 | return; |
| 1607 | } |
| 1608 | for (int i=0; i<N; i++) { |
| 1609 | WindowState win = dialogs.get(i); |
| 1610 | win.mTargetAppToken = null; |
| 1611 | reAddWindowToListInOrderLocked(win); |
| 1612 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1613 | Slog.v(TAG, "No IM target, final list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1614 | logWindowList(" "); |
| 1615 | } |
| 1616 | } |
| 1617 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1618 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1619 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1620 | final WindowState imWin = mInputMethodWindow; |
| 1621 | final int DN = mInputMethodDialogs.size(); |
| 1622 | if (imWin == null && DN == 0) { |
| 1623 | return false; |
| 1624 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1625 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1626 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1627 | if (imPos >= 0) { |
| 1628 | // In this case, the input method windows are to be placed |
| 1629 | // immediately above the window they are targeting. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1630 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1631 | // First check to see if the input method windows are already |
| 1632 | // located here, and contiguous. |
| 1633 | final int N = mWindows.size(); |
| 1634 | WindowState firstImWin = imPos < N |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1635 | ? mWindows.get(imPos) : null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1636 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1637 | // Figure out the actual input method window that should be |
| 1638 | // at the bottom of their stack. |
| 1639 | WindowState baseImWin = imWin != null |
| 1640 | ? imWin : mInputMethodDialogs.get(0); |
| 1641 | if (baseImWin.mChildWindows.size() > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1642 | WindowState cw = baseImWin.mChildWindows.get(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1643 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1644 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1645 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1646 | if (firstImWin == baseImWin) { |
| 1647 | // The windows haven't moved... but are they still contiguous? |
| 1648 | // First find the top IM window. |
| 1649 | int pos = imPos+1; |
| 1650 | while (pos < N) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1651 | if (!(mWindows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1652 | break; |
| 1653 | } |
| 1654 | pos++; |
| 1655 | } |
| 1656 | pos++; |
| 1657 | // Now there should be no more input method windows above. |
| 1658 | while (pos < N) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1659 | if ((mWindows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1660 | break; |
| 1661 | } |
| 1662 | pos++; |
| 1663 | } |
| 1664 | if (pos >= N) { |
| 1665 | // All is good! |
| 1666 | return false; |
| 1667 | } |
| 1668 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1669 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1670 | if (imWin != null) { |
| 1671 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1672 | Slog.v(TAG, "Moving IM from " + imPos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1673 | logWindowList(" "); |
| 1674 | } |
| 1675 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1676 | if (DEBUG_INPUT_METHOD) { |
Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1677 | Slog.v(TAG, "List after removing with new pos " + imPos + ":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1678 | logWindowList(" "); |
| 1679 | } |
| 1680 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1681 | reAddWindowLocked(imPos, imWin); |
| 1682 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1683 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1684 | logWindowList(" "); |
| 1685 | } |
| 1686 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1687 | } else { |
| 1688 | moveInputMethodDialogsLocked(imPos); |
| 1689 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1690 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1691 | } else { |
| 1692 | // In this case, the input method windows go in a fixed layer, |
| 1693 | // because they aren't currently associated with a focus window. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1694 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1695 | if (imWin != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1696 | 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] | 1697 | tmpRemoveWindowLocked(0, imWin); |
| 1698 | imWin.mTargetAppToken = null; |
| 1699 | reAddWindowToListInOrderLocked(imWin); |
| 1700 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1701 | Slog.v(TAG, "List with no IM target:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1702 | logWindowList(" "); |
| 1703 | } |
| 1704 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1705 | } else { |
| 1706 | moveInputMethodDialogsLocked(-1);; |
| 1707 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1708 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1709 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1710 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1711 | if (needAssignLayers) { |
| 1712 | assignLayersLocked(); |
| 1713 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1714 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1715 | return true; |
| 1716 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1717 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1718 | void adjustInputMethodDialogsLocked() { |
| 1719 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1720 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1721 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1722 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1723 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured=" |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1724 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1725 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1726 | ? wallpaperTarget.mAppToken.animation : null) |
| 1727 | + " upper=" + mUpperWallpaperTarget |
| 1728 | + " lower=" + mLowerWallpaperTarget); |
| 1729 | return (wallpaperTarget != null |
| 1730 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1731 | && wallpaperTarget.mAppToken.animation != null))) |
| 1732 | || mUpperWallpaperTarget != null |
| 1733 | || mLowerWallpaperTarget != null; |
| 1734 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1735 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1736 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1737 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1738 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1739 | int adjustWallpaperWindowsLocked() { |
| 1740 | int changed = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1741 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1742 | final int dw = mDisplay.getWidth(); |
| 1743 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1744 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1745 | // First find top-most window that has asked to be on top of the |
| 1746 | // wallpaper; all wallpapers go behind it. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1747 | final ArrayList<WindowState> localmWindows = mWindows; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1748 | int N = localmWindows.size(); |
| 1749 | WindowState w = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1750 | WindowState foundW = null; |
| 1751 | int foundI = 0; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1752 | WindowState topCurW = null; |
| 1753 | int topCurI = 0; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1754 | int windowDetachedI = -1; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1755 | int i = N; |
| 1756 | while (i > 0) { |
| 1757 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1758 | w = localmWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1759 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1760 | if (topCurW == null) { |
| 1761 | topCurW = w; |
| 1762 | topCurI = i; |
| 1763 | } |
| 1764 | continue; |
| 1765 | } |
| 1766 | topCurW = null; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1767 | if (w != mWindowDetachedWallpaper && w.mAppToken != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1768 | // If this window's app token is hidden and not animating, |
| 1769 | // it is of no interest to us. |
| 1770 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1771 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1772 | "Skipping not hidden or animating token: " + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1773 | continue; |
| 1774 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1775 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1776 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay=" |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1777 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1778 | + " commitdrawpending=" + w.mCommitDrawPending); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1779 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1780 | && (mWallpaperTarget == w |
| 1781 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1782 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1783 | "Found wallpaper activity: #" + i + "=" + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1784 | foundW = w; |
| 1785 | foundI = i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1786 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1787 | && w.mAppToken.animation != null) |
| 1788 | || w.mAnimation != null)) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1789 | // The current wallpaper target is animating, so we'll |
| 1790 | // look behind it for another possible target and figure |
| 1791 | // out what is going on below. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1792 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1793 | + ": token animating, looking behind."); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1794 | continue; |
| 1795 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1796 | break; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1797 | } else if (w == mWindowDetachedWallpaper) { |
| 1798 | windowDetachedI = i; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1799 | } |
| 1800 | } |
| 1801 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1802 | if (foundW == null && windowDetachedI >= 0) { |
| 1803 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 1804 | "Found animating detached wallpaper activity: #" + i + "=" + w); |
| 1805 | foundW = w; |
| 1806 | foundI = windowDetachedI; |
| 1807 | } |
| 1808 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1809 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1810 | // If we are currently waiting for an app transition, and either |
| 1811 | // the current target or the next target are involved with it, |
| 1812 | // then hold off on doing anything with the wallpaper. |
| 1813 | // Note that we are checking here for just whether the target |
| 1814 | // is part of an app token... which is potentially overly aggressive |
| 1815 | // (the app token may not be involved in the transition), but good |
| 1816 | // enough (we'll just wait until whatever transition is pending |
| 1817 | // executes). |
| 1818 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1819 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1820 | "Wallpaper not changing: waiting for app anim in current target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1821 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1822 | } |
| 1823 | if (foundW != null && foundW.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1824 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1825 | "Wallpaper not changing: waiting for app anim in found target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1826 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1827 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1828 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1829 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1830 | if (mWallpaperTarget != foundW) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1831 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1832 | Slog.v(TAG, "New wallpaper target: " + foundW |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1833 | + " oldTarget: " + mWallpaperTarget); |
| 1834 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1835 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1836 | mLowerWallpaperTarget = null; |
| 1837 | mUpperWallpaperTarget = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1838 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1839 | WindowState oldW = mWallpaperTarget; |
| 1840 | mWallpaperTarget = foundW; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1841 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1842 | // Now what is happening... if the current and new targets are |
| 1843 | // animating, then we are in our super special mode! |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1844 | if (foundW != null && oldW != null) { |
| 1845 | boolean oldAnim = oldW.mAnimation != null |
| 1846 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1847 | boolean foundAnim = foundW.mAnimation != null |
| 1848 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1849 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1850 | Slog.v(TAG, "New animation: " + foundAnim |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1851 | + " old animation: " + oldAnim); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1852 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1853 | if (foundAnim && oldAnim) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1854 | int oldI = localmWindows.indexOf(oldW); |
| 1855 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1856 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1857 | } |
| 1858 | if (oldI >= 0) { |
| 1859 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1860 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1861 | + "=" + oldW + "; new#" + foundI |
| 1862 | + "=" + foundW); |
| 1863 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1864 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1865 | // Set the new target correctly. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1866 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1867 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1868 | Slog.v(TAG, "Old wallpaper still the target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1869 | } |
| 1870 | mWallpaperTarget = oldW; |
| 1871 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1872 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1873 | // Now set the upper and lower wallpaper targets |
| 1874 | // correctly, and make sure that we are positioning |
| 1875 | // the wallpaper below the lower. |
| 1876 | if (foundI > oldI) { |
| 1877 | // The new target is on top of the old one. |
| 1878 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1879 | Slog.v(TAG, "Found target above old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1880 | } |
| 1881 | mUpperWallpaperTarget = foundW; |
| 1882 | mLowerWallpaperTarget = oldW; |
| 1883 | foundW = oldW; |
| 1884 | foundI = oldI; |
| 1885 | } else { |
| 1886 | // The new target is below the old one. |
| 1887 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1888 | Slog.v(TAG, "Found target below old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1889 | } |
| 1890 | mUpperWallpaperTarget = oldW; |
| 1891 | mLowerWallpaperTarget = foundW; |
| 1892 | } |
| 1893 | } |
| 1894 | } |
| 1895 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1896 | |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1897 | } else if (mLowerWallpaperTarget != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1898 | // Is it time to stop animating? |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1899 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1900 | || (mLowerWallpaperTarget.mAppToken != null |
| 1901 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1902 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1903 | || (mUpperWallpaperTarget.mAppToken != null |
| 1904 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1905 | if (!lowerAnimating || !upperAnimating) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1906 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1907 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1908 | } |
| 1909 | mLowerWallpaperTarget = null; |
| 1910 | mUpperWallpaperTarget = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1911 | } |
| 1912 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1913 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1914 | boolean visible = foundW != null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1915 | if (visible) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1916 | // The window is visible to the compositor... but is it visible |
| 1917 | // to the user? That is what the wallpaper cares about. |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1918 | visible = isWallpaperVisible(foundW); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1919 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1920 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1921 | // If the wallpaper target is animating, we may need to copy |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1922 | // its layer adjustment. Only do this if we are not transfering |
| 1923 | // between two wallpaper targets. |
| 1924 | mWallpaperAnimLayerAdjustment = |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1925 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1926 | ? foundW.mAppToken.animLayerAdjustment : 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1927 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1928 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1929 | * TYPE_LAYER_MULTIPLIER |
| 1930 | + TYPE_LAYER_OFFSET; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1931 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1932 | // Now w is the window we are supposed to be behind... but we |
| 1933 | // 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] | 1934 | // AND any starting window associated with it, AND below the |
| 1935 | // maximum layer the policy allows for wallpapers. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1936 | while (foundI > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1937 | WindowState wb = localmWindows.get(foundI-1); |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1938 | if (wb.mBaseLayer < maxLayer && |
| 1939 | wb.mAttachedWindow != foundW && |
Pal Szasz | 73dc259 | 2010-09-03 11:46:26 +0200 | [diff] [blame] | 1940 | wb.mAttachedWindow != foundW.mAttachedWindow && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1941 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1942 | wb.mToken != foundW.mToken)) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1943 | // This window is not related to the previous one in any |
| 1944 | // interesting way, so stop here. |
| 1945 | break; |
| 1946 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1947 | foundW = wb; |
| 1948 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1949 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1950 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1951 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1952 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1953 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1954 | if (foundW == null && topCurW != null) { |
| 1955 | // There is no wallpaper target, so it goes at the bottom. |
| 1956 | // We will assume it is the same place as last time, if known. |
| 1957 | foundW = topCurW; |
| 1958 | foundI = topCurI+1; |
| 1959 | } else { |
| 1960 | // Okay i is the position immediately above the wallpaper. Look at |
| 1961 | // what is below it for later. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1962 | foundW = foundI > 0 ? localmWindows.get(foundI-1) : null; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1963 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1964 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1965 | if (visible) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1966 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1967 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1968 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1969 | } |
| 1970 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1971 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1972 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1973 | } |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1974 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1975 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1976 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1977 | // are correctly placed. |
| 1978 | int curTokenIndex = mWallpaperTokens.size(); |
| 1979 | while (curTokenIndex > 0) { |
| 1980 | curTokenIndex--; |
| 1981 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1982 | if (token.hidden == visible) { |
| 1983 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1984 | token.hidden = !visible; |
| 1985 | // Need to do a layout to ensure the wallpaper now has the |
| 1986 | // correct size. |
| 1987 | mLayoutNeeded = true; |
| 1988 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1989 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1990 | int curWallpaperIndex = token.windows.size(); |
| 1991 | while (curWallpaperIndex > 0) { |
| 1992 | curWallpaperIndex--; |
| 1993 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1994 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1995 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1996 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1997 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1998 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1999 | // First, make sure the client has the current visibility |
| 2000 | // state. |
| 2001 | if (wallpaper.mWallpaperVisible != visible) { |
| 2002 | wallpaper.mWallpaperVisible = visible; |
| 2003 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2004 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2005 | "Setting visibility of wallpaper " + wallpaper |
| 2006 | + ": " + visible); |
| 2007 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 2008 | } catch (RemoteException e) { |
| 2009 | } |
| 2010 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2011 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2012 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2013 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2014 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2015 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2016 | // First, if this window is at the current index, then all |
| 2017 | // is well. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2018 | if (wallpaper == foundW) { |
| 2019 | foundI--; |
| 2020 | foundW = foundI > 0 |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2021 | ? localmWindows.get(foundI-1) : null; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2022 | continue; |
| 2023 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2024 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2025 | // The window didn't match... the current wallpaper window, |
| 2026 | // wherever it is, is in the wrong place, so make sure it is |
| 2027 | // not in the list. |
| 2028 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 2029 | if (oldIndex >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2030 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 2031 | + oldIndex + ": " + wallpaper); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2032 | localmWindows.remove(oldIndex); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2033 | mWindowsChanged = true; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2034 | if (oldIndex < foundI) { |
| 2035 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2036 | } |
| 2037 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2038 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2039 | // Now stick it in. |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2040 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 2041 | Slog.v(TAG, "Moving wallpaper " + wallpaper |
| 2042 | + " from " + oldIndex + " to " + foundI); |
| 2043 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2044 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2045 | localmWindows.add(foundI, wallpaper); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2046 | mWindowsChanged = true; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2047 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2048 | } |
| 2049 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2050 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2051 | return changed; |
| 2052 | } |
| 2053 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2054 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2055 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2056 | "Setting wallpaper layer adj to " + adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2057 | mWallpaperAnimLayerAdjustment = adj; |
| 2058 | int curTokenIndex = mWallpaperTokens.size(); |
| 2059 | while (curTokenIndex > 0) { |
| 2060 | curTokenIndex--; |
| 2061 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2062 | int curWallpaperIndex = token.windows.size(); |
| 2063 | while (curWallpaperIndex > 0) { |
| 2064 | curWallpaperIndex--; |
| 2065 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2066 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2067 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2068 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2069 | } |
| 2070 | } |
| 2071 | } |
| 2072 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2073 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 2074 | boolean sync) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2075 | boolean changed = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2076 | boolean rawChanged = false; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2077 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2078 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2079 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 2080 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 2081 | changed = wallpaperWin.mXOffset != offset; |
| 2082 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2083 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2084 | + wallpaperWin + " x: " + offset); |
| 2085 | wallpaperWin.mXOffset = offset; |
| 2086 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2087 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2088 | wallpaperWin.mWallpaperX = wpx; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2089 | wallpaperWin.mWallpaperXStep = wpxs; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2090 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2091 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2092 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2093 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2094 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2095 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 2096 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 2097 | if (wallpaperWin.mYOffset != offset) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2098 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2099 | + wallpaperWin + " y: " + offset); |
| 2100 | changed = true; |
| 2101 | wallpaperWin.mYOffset = offset; |
| 2102 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2103 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2104 | wallpaperWin.mWallpaperY = wpy; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2105 | wallpaperWin.mWallpaperYStep = wpys; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2106 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2107 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2108 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2109 | if (rawChanged) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2110 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2111 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2112 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 2113 | + " y=" + wallpaperWin.mWallpaperY); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2114 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2115 | mWaitingOnWallpaper = wallpaperWin; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2116 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2117 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2118 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 2119 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2120 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2121 | if (mWaitingOnWallpaper != null) { |
| 2122 | long start = SystemClock.uptimeMillis(); |
| 2123 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 2124 | < start) { |
| 2125 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2126 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2127 | "Waiting for offset complete..."); |
| 2128 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 2129 | } catch (InterruptedException e) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2130 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2131 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2132 | if ((start+WALLPAPER_TIMEOUT) |
| 2133 | < SystemClock.uptimeMillis()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2134 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2135 | + wallpaperWin); |
| 2136 | mLastWallpaperTimeoutTime = start; |
| 2137 | } |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2138 | } |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2139 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2140 | } |
| 2141 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2142 | } catch (RemoteException e) { |
| 2143 | } |
| 2144 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2145 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2146 | return changed; |
| 2147 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2148 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2149 | void wallpaperOffsetsComplete(IBinder window) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2150 | synchronized (mWindowMap) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2151 | if (mWaitingOnWallpaper != null && |
| 2152 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2153 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2154 | mWindowMap.notifyAll(); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2155 | } |
| 2156 | } |
| 2157 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2158 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2159 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2160 | final int dw = mDisplay.getWidth(); |
| 2161 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2162 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2163 | boolean changed = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2164 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2165 | WindowState target = mWallpaperTarget; |
| 2166 | if (target != null) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2167 | if (target.mWallpaperX >= 0) { |
| 2168 | mLastWallpaperX = target.mWallpaperX; |
| 2169 | } else if (changingTarget.mWallpaperX >= 0) { |
| 2170 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 2171 | } |
| 2172 | if (target.mWallpaperY >= 0) { |
| 2173 | mLastWallpaperY = target.mWallpaperY; |
| 2174 | } else if (changingTarget.mWallpaperY >= 0) { |
| 2175 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 2176 | } |
| 2177 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2178 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2179 | int curTokenIndex = mWallpaperTokens.size(); |
| 2180 | while (curTokenIndex > 0) { |
| 2181 | curTokenIndex--; |
| 2182 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2183 | int curWallpaperIndex = token.windows.size(); |
| 2184 | while (curWallpaperIndex > 0) { |
| 2185 | curWallpaperIndex--; |
| 2186 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2187 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 2188 | wallpaper.computeShownFrameLocked(); |
| 2189 | changed = true; |
| 2190 | // We only want to be synchronous with one wallpaper. |
| 2191 | sync = false; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2192 | } |
| 2193 | } |
| 2194 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2195 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2196 | return changed; |
| 2197 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2198 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2199 | void updateWallpaperVisibilityLocked() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2200 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2201 | final int dw = mDisplay.getWidth(); |
| 2202 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2203 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2204 | int curTokenIndex = mWallpaperTokens.size(); |
| 2205 | while (curTokenIndex > 0) { |
| 2206 | curTokenIndex--; |
| 2207 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2208 | if (token.hidden == visible) { |
| 2209 | token.hidden = !visible; |
| 2210 | // Need to do a layout to ensure the wallpaper now has the |
| 2211 | // correct size. |
| 2212 | mLayoutNeeded = true; |
| 2213 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2214 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2215 | int curWallpaperIndex = token.windows.size(); |
| 2216 | while (curWallpaperIndex > 0) { |
| 2217 | curWallpaperIndex--; |
| 2218 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2219 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2220 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2221 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2222 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2223 | if (wallpaper.mWallpaperVisible != visible) { |
| 2224 | wallpaper.mWallpaperVisible = visible; |
| 2225 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2226 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2227 | "Updating visibility of wallpaper " + wallpaper |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2228 | + ": " + visible); |
| 2229 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 2230 | } catch (RemoteException e) { |
| 2231 | } |
| 2232 | } |
| 2233 | } |
| 2234 | } |
| 2235 | } |
Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 2236 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2237 | public int addWindow(Session session, IWindow client, |
| 2238 | WindowManager.LayoutParams attrs, int viewVisibility, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2239 | Rect outContentInsets, InputChannel outInputChannel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2240 | int res = mPolicy.checkAddPermission(attrs); |
| 2241 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2242 | return res; |
| 2243 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2244 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2245 | boolean reportNewConfig = false; |
| 2246 | WindowState attachedWindow = null; |
| 2247 | WindowState win = null; |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2248 | long origId; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2249 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2250 | synchronized(mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2251 | if (mDisplay == null) { |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2252 | throw new IllegalStateException("Display has not been initialialized"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2253 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2254 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2255 | if (mWindowMap.containsKey(client.asBinder())) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2256 | Slog.w(TAG, "Window " + client + " is already added"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2257 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 2258 | } |
| 2259 | |
| 2260 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2261 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2262 | if (attachedWindow == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2263 | 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] | 2264 | + attrs.token + ". Aborting."); |
| 2265 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2266 | } |
| 2267 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 2268 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2269 | 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] | 2270 | + attrs.token + ". Aborting."); |
| 2271 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2272 | } |
| 2273 | } |
| 2274 | |
| 2275 | boolean addToken = false; |
| 2276 | WindowToken token = mTokenMap.get(attrs.token); |
| 2277 | if (token == null) { |
| 2278 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2279 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2280 | 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] | 2281 | + attrs.token + ". Aborting."); |
| 2282 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2283 | } |
| 2284 | if (attrs.type == TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2285 | 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] | 2286 | + attrs.token + ". Aborting."); |
| 2287 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2288 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2289 | if (attrs.type == TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2290 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2291 | + attrs.token + ". Aborting."); |
| 2292 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2293 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2294 | token = new WindowToken(attrs.token, -1, false); |
| 2295 | addToken = true; |
| 2296 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2297 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 2298 | AppWindowToken atoken = token.appWindowToken; |
| 2299 | if (atoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2300 | 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] | 2301 | + token + ". Aborting."); |
| 2302 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 2303 | } else if (atoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2304 | 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] | 2305 | + token + ". Aborting."); |
| 2306 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2307 | } |
| 2308 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 2309 | // No need for this guy! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2310 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2311 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 2312 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 2313 | } |
| 2314 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 2315 | if (token.windowType != TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2316 | 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] | 2317 | + attrs.token + ". Aborting."); |
| 2318 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2319 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2320 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 2321 | if (token.windowType != TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2322 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2323 | + attrs.token + ". Aborting."); |
| 2324 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2325 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2326 | } |
| 2327 | |
| 2328 | win = new WindowState(session, client, token, |
| 2329 | attachedWindow, attrs, viewVisibility); |
| 2330 | if (win.mDeathRecipient == null) { |
| 2331 | // Client has apparently died, so there is no reason to |
| 2332 | // continue. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2333 | Slog.w(TAG, "Adding window client " + client.asBinder() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2334 | + " that is dead, aborting."); |
| 2335 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2336 | } |
| 2337 | |
| 2338 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
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 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 2341 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2342 | return res; |
| 2343 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2344 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2345 | if (outInputChannel != null) { |
| 2346 | String name = win.makeInputChannelName(); |
| 2347 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 2348 | win.mInputChannel = inputChannels[0]; |
| 2349 | inputChannels[1].transferToBinderOutParameter(outInputChannel); |
| 2350 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 2351 | mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2352 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2353 | |
| 2354 | // From now on, no exceptions or errors allowed! |
| 2355 | |
| 2356 | res = WindowManagerImpl.ADD_OKAY; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2357 | |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2358 | origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2359 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2360 | if (addToken) { |
| 2361 | mTokenMap.put(attrs.token, token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2362 | } |
| 2363 | win.attach(); |
| 2364 | mWindowMap.put(client.asBinder(), win); |
| 2365 | |
| 2366 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 2367 | token.appWindowToken != null) { |
| 2368 | token.appWindowToken.startingWindow = win; |
| 2369 | } |
| 2370 | |
| 2371 | boolean imMayMove = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2372 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2373 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 2374 | mInputMethodWindow = win; |
| 2375 | addInputMethodWindowToListLocked(win); |
| 2376 | imMayMove = false; |
| 2377 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2378 | mInputMethodDialogs.add(win); |
| 2379 | addWindowToListInOrderLocked(win, true); |
| 2380 | adjustInputMethodDialogsLocked(); |
| 2381 | imMayMove = false; |
| 2382 | } else { |
| 2383 | addWindowToListInOrderLocked(win, true); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2384 | if (attrs.type == TYPE_WALLPAPER) { |
| 2385 | mLastWallpaperTimeoutTime = 0; |
| 2386 | adjustWallpaperWindowsLocked(); |
| 2387 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2388 | adjustWallpaperWindowsLocked(); |
| 2389 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2390 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2391 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2392 | win.mEnterAnimationPending = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2393 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2394 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2395 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2396 | if (mInTouchMode) { |
| 2397 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 2398 | } |
| 2399 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 2400 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 2401 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2402 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2403 | boolean focusChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2404 | if (win.canReceiveKeys()) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 2405 | focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS, |
| 2406 | false /*updateInputWindows*/); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2407 | if (focusChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2408 | imMayMove = false; |
| 2409 | } |
| 2410 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2411 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2412 | if (imMayMove) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2413 | moveInputMethodWindowsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2414 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2415 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2416 | assignLayersLocked(); |
| 2417 | // Don't do layout here, the window must call |
| 2418 | // relayout to be displayed, so we'll do it there. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2419 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2420 | //dump(); |
| 2421 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2422 | if (focusChanged) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 2423 | finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2424 | } |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 2425 | mInputMonitor.updateInputWindowsLw(); |
| 2426 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2427 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2428 | TAG, "New client " + client.asBinder() |
| 2429 | + ": window=" + win); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2430 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2431 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2432 | reportNewConfig = true; |
| 2433 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2434 | } |
| 2435 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2436 | if (reportNewConfig) { |
| 2437 | sendNewConfiguration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2438 | } |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2439 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2440 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2441 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2442 | return res; |
| 2443 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2444 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2445 | public void removeWindow(Session session, IWindow client) { |
| 2446 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2447 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2448 | if (win == null) { |
| 2449 | return; |
| 2450 | } |
| 2451 | removeWindowLocked(session, win); |
| 2452 | } |
| 2453 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2454 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2455 | public void removeWindowLocked(Session session, WindowState win) { |
| 2456 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2457 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2458 | TAG, "Remove " + win + " client=" |
| 2459 | + Integer.toHexString(System.identityHashCode( |
| 2460 | win.mClient.asBinder())) |
| 2461 | + ", surface=" + win.mSurface); |
| 2462 | |
| 2463 | final long origId = Binder.clearCallingIdentity(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2464 | |
| 2465 | win.disposeInputChannel(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2466 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2467 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2468 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2469 | + " mExiting=" + win.mExiting |
| 2470 | + " isAnimating=" + win.isAnimating() |
| 2471 | + " app-animation=" |
| 2472 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2473 | + " inPendingTransaction=" |
| 2474 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2475 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2476 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2477 | boolean wasVisible = false; |
| 2478 | // First, see if we need to run an animation. If we do, we have |
| 2479 | // to hold off on removing the window until the animation is done. |
| 2480 | // If the display is frozen, just remove immediately, since the |
| 2481 | // animation wouldn't be seen. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2482 | if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2483 | // If we are not currently running the exit animation, we |
| 2484 | // need to see about starting one. |
| 2485 | if (wasVisible=win.isWinVisibleLw()) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2486 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2487 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2488 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2489 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2490 | } |
| 2491 | // Try starting an animation. |
| 2492 | if (applyAnimationLocked(win, transit, false)) { |
| 2493 | win.mExiting = true; |
| 2494 | } |
| 2495 | } |
| 2496 | if (win.mExiting || win.isAnimating()) { |
| 2497 | // The exit animation is running... wait for it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2498 | //Slog.i(TAG, "*** Running exit animation..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2499 | win.mExiting = true; |
| 2500 | win.mRemoveOnExit = true; |
| 2501 | mLayoutNeeded = true; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 2502 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 2503 | false /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2504 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 2505 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2506 | if (win.mAppToken != null) { |
| 2507 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2508 | } |
| 2509 | //dump(); |
| 2510 | Binder.restoreCallingIdentity(origId); |
| 2511 | return; |
| 2512 | } |
| 2513 | } |
| 2514 | |
| 2515 | removeWindowInnerLocked(session, win); |
| 2516 | // Removing a visible window will effect the computed orientation |
| 2517 | // So just update orientation if needed. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2518 | if (wasVisible && computeForcedAppOrientationLocked() |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2519 | != mForcedAppOrientation |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2520 | && updateOrientationFromAppTokensLocked(false)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2521 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2522 | } |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 2523 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2524 | Binder.restoreCallingIdentity(origId); |
| 2525 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2526 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2527 | private void removeWindowInnerLocked(Session session, WindowState win) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2528 | if (win.mRemoved) { |
| 2529 | // Nothing to do. |
| 2530 | return; |
| 2531 | } |
| 2532 | |
| 2533 | for (int i=win.mChildWindows.size()-1; i>=0; i--) { |
| 2534 | WindowState cwin = win.mChildWindows.get(i); |
| 2535 | Slog.w(TAG, "Force-removing child win " + cwin + " from container " |
| 2536 | + win); |
| 2537 | removeWindowInnerLocked(cwin.mSession, cwin); |
| 2538 | } |
| 2539 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2540 | win.mRemoved = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2541 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2542 | if (mInputMethodTarget == win) { |
| 2543 | moveInputMethodWindowsIfNeededLocked(false); |
| 2544 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2545 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2546 | if (false) { |
| 2547 | RuntimeException e = new RuntimeException("here"); |
| 2548 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2549 | Slog.w(TAG, "Removing window " + win, e); |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2550 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2551 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2552 | mPolicy.removeWindowLw(win); |
| 2553 | win.removeLocked(); |
| 2554 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2555 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2556 | mWindowMap.remove(win.mClient.asBinder()); |
| 2557 | mWindows.remove(win); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2558 | mPendingRemove.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2559 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2560 | 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] | 2561 | |
| 2562 | if (mInputMethodWindow == win) { |
| 2563 | mInputMethodWindow = null; |
| 2564 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2565 | mInputMethodDialogs.remove(win); |
| 2566 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2567 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2568 | final WindowToken token = win.mToken; |
| 2569 | final AppWindowToken atoken = win.mAppToken; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2570 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + win + " from " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2571 | token.windows.remove(win); |
| 2572 | if (atoken != null) { |
| 2573 | atoken.allAppWindows.remove(win); |
| 2574 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2575 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2576 | TAG, "**** Removing window " + win + ": count=" |
| 2577 | + token.windows.size()); |
| 2578 | if (token.windows.size() == 0) { |
| 2579 | if (!token.explicit) { |
| 2580 | mTokenMap.remove(token.token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2581 | } else if (atoken != null) { |
| 2582 | atoken.firstWindowDrawn = false; |
| 2583 | } |
| 2584 | } |
| 2585 | |
| 2586 | if (atoken != null) { |
| 2587 | if (atoken.startingWindow == win) { |
| 2588 | atoken.startingWindow = null; |
| 2589 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2590 | // If this is the last window and we had requested a starting |
| 2591 | // transition window, well there is no point now. |
| 2592 | atoken.startingData = null; |
| 2593 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2594 | // If this is the last window except for a starting transition |
| 2595 | // window, we need to get rid of the starting transition. |
| 2596 | if (DEBUG_STARTING_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2597 | Slog.v(TAG, "Schedule remove starting " + token |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2598 | + ": no more real windows"); |
| 2599 | } |
| 2600 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2601 | mH.sendMessage(m); |
| 2602 | } |
| 2603 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2604 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2605 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2606 | mLastWallpaperTimeoutTime = 0; |
| 2607 | adjustWallpaperWindowsLocked(); |
| 2608 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2609 | adjustWallpaperWindowsLocked(); |
| 2610 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2611 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2612 | if (!mInLayout) { |
| 2613 | assignLayersLocked(); |
| 2614 | mLayoutNeeded = true; |
| 2615 | performLayoutAndPlaceSurfacesLocked(); |
| 2616 | if (win.mAppToken != null) { |
| 2617 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2618 | } |
| 2619 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2620 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 2621 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2622 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2623 | } |
| 2624 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2625 | private static void logSurface(WindowState w, String msg, RuntimeException where) { |
| 2626 | String str = " SURFACE " + Integer.toHexString(w.hashCode()) |
| 2627 | + ": " + msg + " / " + w.mAttrs.getTitle(); |
| 2628 | if (where != null) { |
| 2629 | Slog.i(TAG, str, where); |
| 2630 | } else { |
| 2631 | Slog.i(TAG, str); |
| 2632 | } |
| 2633 | } |
| 2634 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2635 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 2636 | long origId = Binder.clearCallingIdentity(); |
| 2637 | try { |
| 2638 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2639 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2640 | if ((w != null) && (w.mSurface != null)) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2641 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 2642 | ">>> OPEN TRANSACTION setTransparentRegion"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2643 | Surface.openTransaction(); |
| 2644 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2645 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 2646 | "transparentRegionHint=" + region, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2647 | w.mSurface.setTransparentRegionHint(region); |
| 2648 | } finally { |
| 2649 | Surface.closeTransaction(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2650 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 2651 | "<<< CLOSE TRANSACTION setTransparentRegion"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2652 | } |
| 2653 | } |
| 2654 | } |
| 2655 | } finally { |
| 2656 | Binder.restoreCallingIdentity(origId); |
| 2657 | } |
| 2658 | } |
| 2659 | |
| 2660 | void setInsetsWindow(Session session, IWindow client, |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2661 | int touchableInsets, Rect contentInsets, |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2662 | Rect visibleInsets, Region touchableRegion) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2663 | long origId = Binder.clearCallingIdentity(); |
| 2664 | try { |
| 2665 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2666 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2667 | if (w != null) { |
| 2668 | w.mGivenInsetsPending = false; |
| 2669 | w.mGivenContentInsets.set(contentInsets); |
| 2670 | w.mGivenVisibleInsets.set(visibleInsets); |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2671 | w.mGivenTouchableRegion.set(touchableRegion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2672 | w.mTouchableInsets = touchableInsets; |
| 2673 | mLayoutNeeded = true; |
| 2674 | performLayoutAndPlaceSurfacesLocked(); |
| 2675 | } |
| 2676 | } |
| 2677 | } finally { |
| 2678 | Binder.restoreCallingIdentity(origId); |
| 2679 | } |
| 2680 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2681 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2682 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2683 | Rect outDisplayFrame) { |
| 2684 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2685 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2686 | if (win == null) { |
| 2687 | outDisplayFrame.setEmpty(); |
| 2688 | return; |
| 2689 | } |
| 2690 | outDisplayFrame.set(win.mDisplayFrame); |
| 2691 | } |
| 2692 | } |
| 2693 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2694 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2695 | float xStep, float yStep) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2696 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2697 | window.mWallpaperX = x; |
| 2698 | window.mWallpaperY = y; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2699 | window.mWallpaperXStep = xStep; |
| 2700 | window.mWallpaperYStep = yStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2701 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2702 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2703 | } |
| 2704 | } |
| 2705 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2706 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2707 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2708 | synchronized (mWindowMap) { |
| 2709 | if (mWaitingOnWallpaper != null && |
| 2710 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2711 | mWaitingOnWallpaper = null; |
| 2712 | mWindowMap.notifyAll(); |
| 2713 | } |
| 2714 | } |
| 2715 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2716 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2717 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2718 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2719 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2720 | || window == mUpperWallpaperTarget) { |
| 2721 | boolean doWait = sync; |
| 2722 | int curTokenIndex = mWallpaperTokens.size(); |
| 2723 | while (curTokenIndex > 0) { |
| 2724 | curTokenIndex--; |
| 2725 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2726 | int curWallpaperIndex = token.windows.size(); |
| 2727 | while (curWallpaperIndex > 0) { |
| 2728 | curWallpaperIndex--; |
| 2729 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2730 | try { |
| 2731 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2732 | x, y, z, extras, sync); |
| 2733 | // We only want to be synchronous with one wallpaper. |
| 2734 | sync = false; |
| 2735 | } catch (RemoteException e) { |
| 2736 | } |
| 2737 | } |
| 2738 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2739 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2740 | if (doWait) { |
| 2741 | // XXX Need to wait for result. |
| 2742 | } |
| 2743 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2744 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2745 | return null; |
| 2746 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2747 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2748 | public int relayoutWindow(Session session, IWindow client, |
| 2749 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2750 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2751 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2752 | Configuration outConfig, Surface outSurface) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2753 | boolean displayed = false; |
| 2754 | boolean inTouchMode; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2755 | boolean configChanged; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2756 | long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2757 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2758 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2759 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2760 | if (win == null) { |
| 2761 | return 0; |
| 2762 | } |
| 2763 | win.mRequestedWidth = requestedWidth; |
| 2764 | win.mRequestedHeight = requestedHeight; |
| 2765 | |
| 2766 | if (attrs != null) { |
| 2767 | mPolicy.adjustWindowParamsLw(attrs); |
| 2768 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2769 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2770 | int attrChanges = 0; |
| 2771 | int flagChanges = 0; |
| 2772 | if (attrs != null) { |
| 2773 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2774 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2775 | } |
| 2776 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2777 | 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] | 2778 | |
| 2779 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2780 | win.mAlpha = attrs.alpha; |
| 2781 | } |
| 2782 | |
| 2783 | final boolean scaledWindow = |
| 2784 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2785 | |
| 2786 | if (scaledWindow) { |
| 2787 | // requested{Width|Height} Surface's physical size |
| 2788 | // attrs.{width|height} Size on screen |
| 2789 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2790 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2791 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2792 | (attrs.height / (float)requestedHeight) : 1.0f; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2793 | } else { |
| 2794 | win.mHScale = win.mVScale = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2795 | } |
| 2796 | |
| 2797 | boolean imMayMove = (flagChanges&( |
| 2798 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2799 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2800 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2801 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2802 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2803 | || (!win.mRelayoutCalled); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2804 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2805 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2806 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2807 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2808 | win.mRelayoutCalled = true; |
| 2809 | final int oldVisibility = win.mViewVisibility; |
| 2810 | win.mViewVisibility = viewVisibility; |
| 2811 | if (viewVisibility == View.VISIBLE && |
| 2812 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2813 | displayed = !win.isVisibleLw(); |
| 2814 | if (win.mExiting) { |
| 2815 | win.mExiting = false; |
Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 2816 | if (win.mAnimation != null) { |
| 2817 | win.mAnimation.cancel(); |
| 2818 | win.mAnimation = null; |
| 2819 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2820 | } |
| 2821 | if (win.mDestroying) { |
| 2822 | win.mDestroying = false; |
| 2823 | mDestroySurface.remove(win); |
| 2824 | } |
| 2825 | if (oldVisibility == View.GONE) { |
| 2826 | win.mEnterAnimationPending = true; |
| 2827 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2828 | if (displayed) { |
| 2829 | if (win.mSurface != null && !win.mDrawPending |
| 2830 | && !win.mCommitDrawPending && !mDisplayFrozen |
| 2831 | && mPolicy.isScreenOn()) { |
| 2832 | applyEnterAnimationLocked(win); |
| 2833 | } |
| 2834 | if ((win.mAttrs.flags |
| 2835 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2836 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2837 | "Relayout window turning screen on: " + win); |
| 2838 | win.mTurnOnScreen = true; |
| 2839 | } |
| 2840 | int diff = 0; |
| 2841 | if (win.mConfiguration != mCurConfiguration |
| 2842 | && (win.mConfiguration == null |
| 2843 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2844 | win.mConfiguration = mCurConfiguration; |
| 2845 | if (DEBUG_CONFIGURATION) { |
| 2846 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2847 | + win.mConfiguration + " / 0x" |
| 2848 | + Integer.toHexString(diff)); |
| 2849 | } |
| 2850 | outConfig.setTo(mCurConfiguration); |
| 2851 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2852 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2853 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2854 | // To change the format, we need to re-build the surface. |
| 2855 | win.destroySurfaceLocked(); |
| 2856 | displayed = true; |
| 2857 | } |
| 2858 | try { |
| 2859 | Surface surface = win.createSurfaceLocked(); |
| 2860 | if (surface != null) { |
| 2861 | outSurface.copyFrom(surface); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2862 | win.mReportDestroySurface = false; |
| 2863 | win.mSurfacePendingDestroy = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2864 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2865 | " OUT SURFACE " + outSurface + ": copied"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2866 | } else { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2867 | // For some reason there isn't a surface. Clear the |
| 2868 | // caller's object so they see the same state. |
| 2869 | outSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2870 | } |
| 2871 | } catch (Exception e) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 2872 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2873 | mInputMonitor.updateInputWindowsLw(); |
| 2874 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2875 | Slog.w(TAG, "Exception thrown when creating surface for client " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2876 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2877 | e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2878 | Binder.restoreCallingIdentity(origId); |
| 2879 | return 0; |
| 2880 | } |
| 2881 | if (displayed) { |
| 2882 | focusMayChange = true; |
| 2883 | } |
| 2884 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2885 | && mInputMethodWindow == null) { |
| 2886 | mInputMethodWindow = win; |
| 2887 | imMayMove = true; |
| 2888 | } |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2889 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2890 | && win.mAppToken != null |
| 2891 | && win.mAppToken.startingWindow != null) { |
| 2892 | // Special handling of starting window over the base |
| 2893 | // window of the app: propagate lock screen flags to it, |
| 2894 | // to provide the correct semantics while starting. |
| 2895 | final int mask = |
| 2896 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2897 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2898 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2899 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2900 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2901 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2902 | } else { |
| 2903 | win.mEnterAnimationPending = false; |
| 2904 | if (win.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2905 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2906 | + ": mExiting=" + win.mExiting |
| 2907 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2908 | // If we are not currently running the exit animation, we |
| 2909 | // need to see about starting one. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2910 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2911 | // Try starting an animation; if there isn't one, we |
| 2912 | // can destroy the surface right away. |
| 2913 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2914 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2915 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2916 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2917 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2918 | applyAnimationLocked(win, transit, false)) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2919 | focusMayChange = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2920 | win.mExiting = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2921 | } else if (win.isAnimating()) { |
| 2922 | // Currently in a hide animation... turn this into |
| 2923 | // an exit. |
| 2924 | win.mExiting = true; |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2925 | } else if (win == mWallpaperTarget) { |
| 2926 | // If the wallpaper is currently behind this |
| 2927 | // window, we need to change both of them inside |
| 2928 | // of a transaction to avoid artifacts. |
| 2929 | win.mExiting = true; |
| 2930 | win.mAnimating = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2931 | } else { |
| 2932 | if (mInputMethodWindow == win) { |
| 2933 | mInputMethodWindow = null; |
| 2934 | } |
| 2935 | win.destroySurfaceLocked(); |
| 2936 | } |
| 2937 | } |
| 2938 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2939 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2940 | if (win.mSurface == null || (win.getAttrs().flags |
| 2941 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2942 | || win.mSurfacePendingDestroy) { |
| 2943 | // We are being called from a local process, which |
| 2944 | // means outSurface holds its current surface. Ensure the |
| 2945 | // surface object is cleared, but we don't want it actually |
| 2946 | // destroyed at this point. |
| 2947 | win.mSurfacePendingDestroy = false; |
| 2948 | outSurface.release(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2949 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2950 | } else if (win.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2951 | if (DEBUG_VISIBILITY) Slog.i(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2952 | "Keeping surface, will report destroy: " + win); |
| 2953 | win.mReportDestroySurface = true; |
| 2954 | outSurface.copyFrom(win.mSurface); |
| 2955 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2956 | } |
| 2957 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2958 | if (focusMayChange) { |
| 2959 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 2960 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 2961 | false /*updateInputWindows*/)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2962 | imMayMove = false; |
| 2963 | } |
| 2964 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2965 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2966 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2967 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2968 | // reassign them at this point if the IM window state gets shuffled |
| 2969 | boolean assignLayers = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2970 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2971 | if (imMayMove) { |
Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2972 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2973 | // Little hack here -- we -should- be able to rely on the |
| 2974 | // function to return true if the IME has moved and needs |
| 2975 | // its layer recomputed. However, if the IME was hidden |
| 2976 | // and isn't actually moved in the list, its layer may be |
| 2977 | // 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] | 2978 | assignLayers = true; |
| 2979 | } |
| 2980 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2981 | if (wallpaperMayMove) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2982 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2983 | assignLayers = true; |
| 2984 | } |
| 2985 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2986 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2987 | mLayoutNeeded = true; |
| 2988 | win.mGivenInsetsPending = insetsPending; |
| 2989 | if (assignLayers) { |
| 2990 | assignLayersLocked(); |
| 2991 | } |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2992 | configChanged = updateOrientationFromAppTokensLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2993 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2994 | if (displayed && win.mIsWallpaper) { |
| 2995 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2996 | mDisplay.getHeight(), false); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2997 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2998 | if (win.mAppToken != null) { |
| 2999 | win.mAppToken.updateReportedVisibilityLocked(); |
| 3000 | } |
| 3001 | outFrame.set(win.mFrame); |
| 3002 | outContentInsets.set(win.mContentInsets); |
| 3003 | outVisibleInsets.set(win.mVisibleInsets); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3004 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3005 | TAG, "Relayout given client " + client.asBinder() |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3006 | + ", requestedWidth=" + requestedWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3007 | + ", requestedHeight=" + requestedHeight |
| 3008 | + ", viewVisibility=" + viewVisibility |
| 3009 | + "\nRelayout returning frame=" + outFrame |
| 3010 | + ", surface=" + outSurface); |
| 3011 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3012 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3013 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 3014 | |
| 3015 | inTouchMode = mInTouchMode; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3016 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 3017 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3018 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3019 | } |
| 3020 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3021 | if (configChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3022 | sendNewConfiguration(); |
| 3023 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3024 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3025 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3026 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3027 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 3028 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 3029 | } |
| 3030 | |
| 3031 | public void finishDrawingWindow(Session session, IWindow client) { |
| 3032 | final long origId = Binder.clearCallingIdentity(); |
| 3033 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3034 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3035 | if (win != null && win.finishDrawingLocked()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 3036 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 3037 | adjustWallpaperWindowsLocked(); |
| 3038 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3039 | mLayoutNeeded = true; |
| 3040 | performLayoutAndPlaceSurfacesLocked(); |
| 3041 | } |
| 3042 | } |
| 3043 | Binder.restoreCallingIdentity(origId); |
| 3044 | } |
| 3045 | |
| 3046 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 3047 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3048 | + (lp != null ? lp.packageName : null) |
| 3049 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 3050 | if (lp != null && lp.windowAnimations != 0) { |
| 3051 | // If this is a system resource, don't try to load it from the |
| 3052 | // application resources. It is nice to avoid loading application |
| 3053 | // resources if we can. |
| 3054 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 3055 | int resId = lp.windowAnimations; |
| 3056 | if ((resId&0xFF000000) == 0x01000000) { |
| 3057 | packageName = "android"; |
| 3058 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3059 | 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] | 3060 | + packageName); |
| 3061 | return AttributeCache.instance().get(packageName, resId, |
| 3062 | com.android.internal.R.styleable.WindowAnimation); |
| 3063 | } |
| 3064 | return null; |
| 3065 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3066 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3067 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 3068 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3069 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 3070 | if (packageName != null) { |
| 3071 | if ((resId&0xFF000000) == 0x01000000) { |
| 3072 | packageName = "android"; |
| 3073 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3074 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3075 | + packageName); |
| 3076 | return AttributeCache.instance().get(packageName, resId, |
| 3077 | com.android.internal.R.styleable.WindowAnimation); |
| 3078 | } |
| 3079 | return null; |
| 3080 | } |
| 3081 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3082 | private void applyEnterAnimationLocked(WindowState win) { |
| 3083 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 3084 | if (win.mEnterAnimationPending) { |
| 3085 | win.mEnterAnimationPending = false; |
| 3086 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 3087 | } |
| 3088 | |
| 3089 | applyAnimationLocked(win, transit, true); |
| 3090 | } |
| 3091 | |
| 3092 | private boolean applyAnimationLocked(WindowState win, |
| 3093 | int transit, boolean isEntrance) { |
| 3094 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 3095 | // If we are trying to apply an animation, but already running |
| 3096 | // an animation of the same type, then just leave that one alone. |
| 3097 | return true; |
| 3098 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3099 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3100 | // Only apply an animation if the display isn't frozen. If it is |
| 3101 | // frozen, there is no reason to animate and it can cause strange |
| 3102 | // artifacts when we unfreeze the display if some different animation |
| 3103 | // is running. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3104 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3105 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 3106 | int attr = -1; |
| 3107 | Animation a = null; |
| 3108 | if (anim != 0) { |
| 3109 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 3110 | } else { |
| 3111 | switch (transit) { |
| 3112 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 3113 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 3114 | break; |
| 3115 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 3116 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 3117 | break; |
| 3118 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 3119 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 3120 | break; |
| 3121 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 3122 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 3123 | break; |
| 3124 | } |
| 3125 | if (attr >= 0) { |
| 3126 | a = loadAnimation(win.mAttrs, attr); |
| 3127 | } |
| 3128 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3129 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3130 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 3131 | + " mAnimation=" + win.mAnimation |
| 3132 | + " isEntrance=" + isEntrance); |
| 3133 | if (a != null) { |
| 3134 | if (DEBUG_ANIM) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3135 | RuntimeException e = null; |
| 3136 | if (!HIDE_STACK_CRAWLS) { |
| 3137 | e = new RuntimeException(); |
| 3138 | e.fillInStackTrace(); |
| 3139 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3140 | Slog.v(TAG, "Loaded animation " + a + " for " + win, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3141 | } |
| 3142 | win.setAnimation(a); |
| 3143 | win.mAnimationIsEntrance = isEntrance; |
| 3144 | } |
| 3145 | } else { |
| 3146 | win.clearAnimation(); |
| 3147 | } |
| 3148 | |
| 3149 | return win.mAnimation != null; |
| 3150 | } |
| 3151 | |
| 3152 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 3153 | int anim = 0; |
| 3154 | Context context = mContext; |
| 3155 | if (animAttr >= 0) { |
| 3156 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 3157 | if (ent != null) { |
| 3158 | context = ent.context; |
| 3159 | anim = ent.array.getResourceId(animAttr, 0); |
| 3160 | } |
| 3161 | } |
| 3162 | if (anim != 0) { |
| 3163 | return AnimationUtils.loadAnimation(context, anim); |
| 3164 | } |
| 3165 | return null; |
| 3166 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3167 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3168 | private Animation loadAnimation(String packageName, int resId) { |
| 3169 | int anim = 0; |
| 3170 | Context context = mContext; |
| 3171 | if (resId >= 0) { |
| 3172 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 3173 | if (ent != null) { |
| 3174 | context = ent.context; |
| 3175 | anim = resId; |
| 3176 | } |
| 3177 | } |
| 3178 | if (anim != 0) { |
| 3179 | return AnimationUtils.loadAnimation(context, anim); |
| 3180 | } |
| 3181 | return null; |
| 3182 | } |
| 3183 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3184 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 3185 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 3186 | // Only apply an animation if the display isn't frozen. If it is |
| 3187 | // frozen, there is no reason to animate and it can cause strange |
| 3188 | // artifacts when we unfreeze the display if some different animation |
| 3189 | // is running. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3190 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3191 | Animation a; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 3192 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3193 | a = new FadeInOutAnimation(enter); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3194 | if (DEBUG_ANIM) Slog.v(TAG, |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3195 | "applying FadeInOutAnimation for a window in compatibility mode"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3196 | } else if (mNextAppTransitionPackage != null) { |
| 3197 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 3198 | mNextAppTransitionEnter : mNextAppTransitionExit); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3199 | } else { |
| 3200 | int animAttr = 0; |
| 3201 | switch (transit) { |
| 3202 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 3203 | animAttr = enter |
| 3204 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 3205 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 3206 | break; |
| 3207 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 3208 | animAttr = enter |
| 3209 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 3210 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 3211 | break; |
| 3212 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 3213 | animAttr = enter |
| 3214 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 3215 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 3216 | break; |
| 3217 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 3218 | animAttr = enter |
| 3219 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 3220 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 3221 | break; |
| 3222 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 3223 | animAttr = enter |
| 3224 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 3225 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 3226 | break; |
| 3227 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 3228 | animAttr = enter |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 3229 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3230 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 3231 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3232 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3233 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3234 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 3235 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3236 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3237 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3238 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3239 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 3240 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 3241 | break; |
| 3242 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 3243 | animAttr = enter |
| 3244 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 3245 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 3246 | break; |
| 3247 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 3248 | animAttr = enter |
| 3249 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 3250 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3251 | break; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3252 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3253 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3254 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3255 | + " anim=" + a |
| 3256 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 3257 | + " transit=" + transit); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3258 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3259 | if (a != null) { |
| 3260 | if (DEBUG_ANIM) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3261 | RuntimeException e = null; |
| 3262 | if (!HIDE_STACK_CRAWLS) { |
| 3263 | e = new RuntimeException(); |
| 3264 | e.fillInStackTrace(); |
| 3265 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3266 | Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3267 | } |
| 3268 | wtoken.setAnimation(a); |
| 3269 | } |
| 3270 | } else { |
| 3271 | wtoken.clearAnimation(); |
| 3272 | } |
| 3273 | |
| 3274 | return wtoken.animation != null; |
| 3275 | } |
| 3276 | |
| 3277 | // ------------------------------------------------------------- |
| 3278 | // Application Window Tokens |
| 3279 | // ------------------------------------------------------------- |
| 3280 | |
| 3281 | public void validateAppTokens(List tokens) { |
| 3282 | int v = tokens.size()-1; |
| 3283 | int m = mAppTokens.size()-1; |
| 3284 | while (v >= 0 && m >= 0) { |
| 3285 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3286 | if (wtoken.removed) { |
| 3287 | m--; |
| 3288 | continue; |
| 3289 | } |
| 3290 | if (tokens.get(v) != wtoken.token) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3291 | 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] | 3292 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 3293 | } |
| 3294 | v--; |
| 3295 | m--; |
| 3296 | } |
| 3297 | while (v >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3298 | 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] | 3299 | v--; |
| 3300 | } |
| 3301 | while (m >= 0) { |
| 3302 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3303 | if (!wtoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3304 | Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3305 | } |
| 3306 | m--; |
| 3307 | } |
| 3308 | } |
| 3309 | |
| 3310 | boolean checkCallingPermission(String permission, String func) { |
| 3311 | // Quick check: if the calling permission is me, it's all okay. |
| 3312 | if (Binder.getCallingPid() == Process.myPid()) { |
| 3313 | return true; |
| 3314 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3315 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3316 | if (mContext.checkCallingPermission(permission) |
| 3317 | == PackageManager.PERMISSION_GRANTED) { |
| 3318 | return true; |
| 3319 | } |
| 3320 | String msg = "Permission Denial: " + func + " from pid=" |
| 3321 | + Binder.getCallingPid() |
| 3322 | + ", uid=" + Binder.getCallingUid() |
| 3323 | + " requires " + permission; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3324 | Slog.w(TAG, msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3325 | return false; |
| 3326 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3327 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3328 | AppWindowToken findAppWindowToken(IBinder token) { |
| 3329 | WindowToken wtoken = mTokenMap.get(token); |
| 3330 | if (wtoken == null) { |
| 3331 | return null; |
| 3332 | } |
| 3333 | return wtoken.appWindowToken; |
| 3334 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3335 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3336 | public void addWindowToken(IBinder token, int type) { |
| 3337 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3338 | "addWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3339 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3340 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3341 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3342 | synchronized(mWindowMap) { |
| 3343 | WindowToken wtoken = mTokenMap.get(token); |
| 3344 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3345 | 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] | 3346 | return; |
| 3347 | } |
| 3348 | wtoken = new WindowToken(token, type, true); |
| 3349 | mTokenMap.put(token, wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3350 | if (type == TYPE_WALLPAPER) { |
| 3351 | mWallpaperTokens.add(wtoken); |
| 3352 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3353 | } |
| 3354 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3355 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3356 | public void removeWindowToken(IBinder token) { |
| 3357 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3358 | "removeWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3359 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3360 | } |
| 3361 | |
| 3362 | final long origId = Binder.clearCallingIdentity(); |
| 3363 | synchronized(mWindowMap) { |
| 3364 | WindowToken wtoken = mTokenMap.remove(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3365 | if (wtoken != null) { |
| 3366 | boolean delayed = false; |
| 3367 | if (!wtoken.hidden) { |
| 3368 | wtoken.hidden = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3369 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3370 | final int N = wtoken.windows.size(); |
| 3371 | boolean changed = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3372 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3373 | for (int i=0; i<N; i++) { |
| 3374 | WindowState win = wtoken.windows.get(i); |
| 3375 | |
| 3376 | if (win.isAnimating()) { |
| 3377 | delayed = true; |
| 3378 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3379 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3380 | if (win.isVisibleNow()) { |
| 3381 | applyAnimationLocked(win, |
| 3382 | WindowManagerPolicy.TRANSIT_EXIT, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3383 | changed = true; |
| 3384 | } |
| 3385 | } |
| 3386 | |
| 3387 | if (changed) { |
| 3388 | mLayoutNeeded = true; |
| 3389 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 3390 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, |
| 3391 | false /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3392 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3393 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3394 | if (delayed) { |
| 3395 | mExitingTokens.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3396 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 3397 | mWallpaperTokens.remove(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3398 | } |
| 3399 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3400 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 3401 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3402 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3403 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3404 | 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] | 3405 | } |
| 3406 | } |
| 3407 | Binder.restoreCallingIdentity(origId); |
| 3408 | } |
| 3409 | |
| 3410 | public void addAppToken(int addPos, IApplicationToken token, |
| 3411 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 3412 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3413 | "addAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3414 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3415 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3416 | |
| 3417 | // Get the dispatching timeout here while we are not holding any locks so that it |
| 3418 | // can be cached by the AppWindowToken. The timeout value is used later by the |
| 3419 | // input dispatcher in code that does hold locks. If we did not cache the value |
| 3420 | // here we would run the chance of introducing a deadlock between the window manager |
| 3421 | // (which holds locks while updating the input dispatcher state) and the activity manager |
| 3422 | // (which holds locks while querying the application token). |
| 3423 | long inputDispatchingTimeoutNanos; |
| 3424 | try { |
| 3425 | inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L; |
| 3426 | } catch (RemoteException ex) { |
| 3427 | Slog.w(TAG, "Could not get dispatching timeout.", ex); |
| 3428 | inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 3429 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3430 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3431 | synchronized(mWindowMap) { |
| 3432 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3433 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3434 | 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] | 3435 | return; |
| 3436 | } |
| 3437 | wtoken = new AppWindowToken(token); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3438 | wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3439 | wtoken.groupId = groupId; |
| 3440 | wtoken.appFullscreen = fullscreen; |
| 3441 | wtoken.requestedOrientation = requestedOrientation; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3442 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, "addAppToken: " + wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3443 | mAppTokens.add(addPos, wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3444 | mTokenMap.put(token.asBinder(), wtoken); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3445 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3446 | // Application tokens start out hidden. |
| 3447 | wtoken.hidden = true; |
| 3448 | wtoken.hiddenRequested = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3449 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3450 | //dump(); |
| 3451 | } |
| 3452 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3453 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3454 | public void setAppGroupId(IBinder token, int groupId) { |
| 3455 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3456 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3457 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3458 | } |
| 3459 | |
| 3460 | synchronized(mWindowMap) { |
| 3461 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3462 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3463 | 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] | 3464 | return; |
| 3465 | } |
| 3466 | wtoken.groupId = groupId; |
| 3467 | } |
| 3468 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3469 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3470 | public int getOrientationFromWindowsLocked() { |
| 3471 | int pos = mWindows.size() - 1; |
| 3472 | while (pos >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3473 | WindowState wtoken = mWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3474 | pos--; |
| 3475 | if (wtoken.mAppToken != null) { |
| 3476 | // We hit an application window. so the orientation will be determined by the |
| 3477 | // app window. No point in continuing further. |
| 3478 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3479 | } |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3480 | if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3481 | continue; |
| 3482 | } |
| 3483 | int req = wtoken.mAttrs.screenOrientation; |
| 3484 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 3485 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 3486 | continue; |
| 3487 | } else { |
| 3488 | return req; |
| 3489 | } |
| 3490 | } |
| 3491 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3492 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3493 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3494 | public int getOrientationFromAppTokensLocked() { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3495 | int pos = mAppTokens.size() - 1; |
| 3496 | int curGroup = 0; |
| 3497 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3498 | boolean findingBehind = false; |
| 3499 | boolean haveGroup = false; |
| 3500 | boolean lastFullscreen = false; |
| 3501 | while (pos >= 0) { |
| 3502 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 3503 | pos--; |
| 3504 | // if we're about to tear down this window and not seek for |
| 3505 | // the behind activity, don't use it for orientation |
| 3506 | if (!findingBehind |
| 3507 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| 3508 | continue; |
| 3509 | } |
| 3510 | |
| 3511 | if (!haveGroup) { |
| 3512 | // We ignore any hidden applications on the top. |
| 3513 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3514 | continue; |
| 3515 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3516 | haveGroup = true; |
| 3517 | curGroup = wtoken.groupId; |
| 3518 | lastOrientation = wtoken.requestedOrientation; |
| 3519 | } else if (curGroup != wtoken.groupId) { |
| 3520 | // If we have hit a new application group, and the bottom |
| 3521 | // of the previous group didn't explicitly say to use |
| 3522 | // the orientation behind it, and the last app was |
| 3523 | // full screen, then we'll stick with the |
| 3524 | // user's orientation. |
| 3525 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3526 | && lastFullscreen) { |
| 3527 | return lastOrientation; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3528 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3529 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3530 | int or = wtoken.requestedOrientation; |
| 3531 | // If this application is fullscreen, and didn't explicitly say |
| 3532 | // to use the orientation behind it, then just take whatever |
| 3533 | // orientation it has and ignores whatever is under it. |
| 3534 | lastFullscreen = wtoken.appFullscreen; |
| 3535 | if (lastFullscreen |
| 3536 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| 3537 | return or; |
| 3538 | } |
| 3539 | // If this application has requested an explicit orientation, |
| 3540 | // then use it. |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 3541 | if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 3542 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3543 | return or; |
| 3544 | } |
| 3545 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| 3546 | } |
| 3547 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3548 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3549 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3550 | public Configuration updateOrientationFromAppTokens( |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3551 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3552 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3553 | "updateOrientationFromAppTokens()")) { |
| 3554 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3555 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3556 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3557 | Configuration config = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3558 | long ident = Binder.clearCallingIdentity(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3559 | |
| 3560 | synchronized(mWindowMap) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3561 | if (updateOrientationFromAppTokensLocked(false)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3562 | if (freezeThisOneIfNeeded != null) { |
| 3563 | AppWindowToken wtoken = findAppWindowToken( |
| 3564 | freezeThisOneIfNeeded); |
| 3565 | if (wtoken != null) { |
| 3566 | startAppFreezingScreenLocked(wtoken, |
| 3567 | ActivityInfo.CONFIG_ORIENTATION); |
| 3568 | } |
| 3569 | } |
| 3570 | config = computeNewConfigurationLocked(); |
| 3571 | |
| 3572 | } else if (currentConfig != null) { |
| 3573 | // No obvious action we need to take, but if our current |
Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3574 | // state mismatches the activity manager's, update it, |
| 3575 | // disregarding font scale, which should remain set to |
| 3576 | // the value of the previous configuration. |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3577 | mTempConfiguration.setToDefaults(); |
Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3578 | mTempConfiguration.fontScale = currentConfig.fontScale; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3579 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3580 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3581 | mWaitingForConfig = true; |
| 3582 | mLayoutNeeded = true; |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3583 | startFreezingDisplayLocked(false); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3584 | config = new Configuration(mTempConfiguration); |
| 3585 | } |
| 3586 | } |
| 3587 | } |
| 3588 | } |
| 3589 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3590 | Binder.restoreCallingIdentity(ident); |
| 3591 | return config; |
| 3592 | } |
| 3593 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3594 | /* |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3595 | * Determine the new desired orientation of the display, returning |
| 3596 | * a non-null new Configuration if it has changed from the current |
| 3597 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3598 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3599 | * SCREEN. This will typically be done for you if you call |
| 3600 | * sendNewConfiguration(). |
| 3601 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3602 | * The orientation is computed from non-application windows first. If none of |
| 3603 | * the non-application windows specify orientation, the orientation is computed from |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3604 | * application tokens. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3605 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3606 | * android.os.IBinder) |
| 3607 | */ |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3608 | boolean updateOrientationFromAppTokensLocked(boolean inTransaction) { |
| 3609 | if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) { |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3610 | // If the display is frozen, some activities may be in the middle |
| 3611 | // of restarting, and thus have removed their old window. If the |
| 3612 | // window has the flag to hide the lock screen, then the lock screen |
| 3613 | // can re-appear and inflict its own orientation on us. Keep the |
| 3614 | // orientation stable until this all settles down. |
| 3615 | return false; |
| 3616 | } |
| 3617 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3618 | boolean changed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3619 | long ident = Binder.clearCallingIdentity(); |
| 3620 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3621 | int req = computeForcedAppOrientationLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3622 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3623 | if (req != mForcedAppOrientation) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3624 | mForcedAppOrientation = req; |
| 3625 | //send a message to Policy indicating orientation change to take |
| 3626 | //action like disabling/enabling sensors etc., |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3627 | mPolicy.setCurrentOrientationLw(req); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3628 | if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION, |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3629 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE, |
| 3630 | inTransaction)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3631 | changed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3632 | } |
| 3633 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3634 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3635 | return changed; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3636 | } finally { |
| 3637 | Binder.restoreCallingIdentity(ident); |
| 3638 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3639 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3640 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3641 | int computeForcedAppOrientationLocked() { |
| 3642 | int req = getOrientationFromWindowsLocked(); |
| 3643 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3644 | req = getOrientationFromAppTokensLocked(); |
| 3645 | } |
| 3646 | return req; |
| 3647 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3648 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3649 | public void setNewConfiguration(Configuration config) { |
| 3650 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3651 | "setNewConfiguration()")) { |
| 3652 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3653 | } |
| 3654 | |
| 3655 | synchronized(mWindowMap) { |
| 3656 | mCurConfiguration = new Configuration(config); |
| 3657 | mWaitingForConfig = false; |
| 3658 | performLayoutAndPlaceSurfacesLocked(); |
| 3659 | } |
| 3660 | } |
| 3661 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3662 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3663 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3664 | "setAppOrientation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3665 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3666 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3667 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3668 | synchronized(mWindowMap) { |
| 3669 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3670 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3671 | 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] | 3672 | return; |
| 3673 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3674 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3675 | wtoken.requestedOrientation = requestedOrientation; |
| 3676 | } |
| 3677 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3678 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3679 | public int getAppOrientation(IApplicationToken token) { |
| 3680 | synchronized(mWindowMap) { |
| 3681 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3682 | if (wtoken == null) { |
| 3683 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3684 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3685 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3686 | return wtoken.requestedOrientation; |
| 3687 | } |
| 3688 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3689 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3690 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3691 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3692 | "setFocusedApp()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3693 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3694 | } |
| 3695 | |
| 3696 | synchronized(mWindowMap) { |
| 3697 | boolean changed = false; |
| 3698 | if (token == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3699 | 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] | 3700 | changed = mFocusedApp != null; |
| 3701 | mFocusedApp = null; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3702 | if (changed) { |
| 3703 | mInputMonitor.setFocusedAppLw(null); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3704 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3705 | } else { |
| 3706 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3707 | if (newFocus == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3708 | 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] | 3709 | return; |
| 3710 | } |
| 3711 | changed = mFocusedApp != newFocus; |
| 3712 | mFocusedApp = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3713 | if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3714 | if (changed) { |
| 3715 | mInputMonitor.setFocusedAppLw(newFocus); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3716 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3717 | } |
| 3718 | |
| 3719 | if (moveFocusNow && changed) { |
| 3720 | final long origId = Binder.clearCallingIdentity(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 3721 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3722 | Binder.restoreCallingIdentity(origId); |
| 3723 | } |
| 3724 | } |
| 3725 | } |
| 3726 | |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 3727 | public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3728 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3729 | "prepareAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3730 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3731 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3732 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3733 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3734 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3735 | TAG, "Prepare app transition: transit=" + transit |
| 3736 | + " mNextAppTransition=" + mNextAppTransition); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3737 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3738 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3739 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3740 | mNextAppTransition = transit; |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 3741 | } else if (!alwaysKeepCurrent) { |
| 3742 | if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3743 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3744 | // Opening a new task always supersedes a close for the anim. |
| 3745 | mNextAppTransition = transit; |
| 3746 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3747 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3748 | // Opening a new activity always supersedes a close for the anim. |
| 3749 | mNextAppTransition = transit; |
| 3750 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3751 | } |
| 3752 | mAppTransitionReady = false; |
| 3753 | mAppTransitionTimeout = false; |
| 3754 | mStartingIconInTransition = false; |
| 3755 | mSkipAppTransitionAnimation = false; |
| 3756 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3757 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3758 | 5000); |
| 3759 | } |
| 3760 | } |
| 3761 | } |
| 3762 | |
| 3763 | public int getPendingAppTransition() { |
| 3764 | return mNextAppTransition; |
| 3765 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3766 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3767 | public void overridePendingAppTransition(String packageName, |
| 3768 | int enterAnim, int exitAnim) { |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3769 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3770 | mNextAppTransitionPackage = packageName; |
| 3771 | mNextAppTransitionEnter = enterAnim; |
| 3772 | mNextAppTransitionExit = exitAnim; |
| 3773 | } |
| 3774 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3775 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3776 | public void executeAppTransition() { |
| 3777 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3778 | "executeAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3779 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3780 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3781 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3782 | synchronized(mWindowMap) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3783 | if (DEBUG_APP_TRANSITIONS) { |
| 3784 | RuntimeException e = new RuntimeException("here"); |
| 3785 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3786 | Slog.w(TAG, "Execute app transition: mNextAppTransition=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3787 | + mNextAppTransition, e); |
| 3788 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3789 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3790 | mAppTransitionReady = true; |
| 3791 | final long origId = Binder.clearCallingIdentity(); |
| 3792 | performLayoutAndPlaceSurfacesLocked(); |
| 3793 | Binder.restoreCallingIdentity(origId); |
| 3794 | } |
| 3795 | } |
| 3796 | } |
| 3797 | |
| 3798 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3799 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 3800 | int windowFlags, IBinder transferFrom, boolean createIfNeeded) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3801 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3802 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3803 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3804 | } |
| 3805 | |
| 3806 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3807 | if (DEBUG_STARTING_WINDOW) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3808 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3809 | + " transferFrom=" + transferFrom); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3810 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3811 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3812 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3813 | 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] | 3814 | return; |
| 3815 | } |
| 3816 | |
| 3817 | // If the display is frozen, we won't do anything until the |
| 3818 | // actual window is displayed so there is no reason to put in |
| 3819 | // the starting window. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3820 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3821 | return; |
| 3822 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3823 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3824 | if (wtoken.startingData != null) { |
| 3825 | return; |
| 3826 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3827 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3828 | if (transferFrom != null) { |
| 3829 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3830 | if (ttoken != null) { |
| 3831 | WindowState startingWindow = ttoken.startingWindow; |
| 3832 | if (startingWindow != null) { |
| 3833 | if (mStartingIconInTransition) { |
| 3834 | // In this case, the starting icon has already |
| 3835 | // been displayed, so start letting windows get |
| 3836 | // shown immediately without any more transitions. |
| 3837 | mSkipAppTransitionAnimation = true; |
| 3838 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3839 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3840 | "Moving existing starting from " + ttoken |
| 3841 | + " to " + wtoken); |
| 3842 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3843 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3844 | // Transfer the starting window over to the new |
| 3845 | // token. |
| 3846 | wtoken.startingData = ttoken.startingData; |
| 3847 | wtoken.startingView = ttoken.startingView; |
| 3848 | wtoken.startingWindow = startingWindow; |
| 3849 | ttoken.startingData = null; |
| 3850 | ttoken.startingView = null; |
| 3851 | ttoken.startingWindow = null; |
| 3852 | ttoken.startingMoved = true; |
| 3853 | startingWindow.mToken = wtoken; |
Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3854 | startingWindow.mRootToken = wtoken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3855 | startingWindow.mAppToken = wtoken; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3856 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3857 | "Removing starting window: " + startingWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3858 | mWindows.remove(startingWindow); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3859 | mWindowsChanged = true; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3860 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing starting " + startingWindow |
| 3861 | + " from " + ttoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3862 | ttoken.windows.remove(startingWindow); |
| 3863 | ttoken.allAppWindows.remove(startingWindow); |
| 3864 | addWindowToListInOrderLocked(startingWindow, true); |
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 | // Propagate other interesting state between the |
| 3867 | // tokens. If the old token is displayed, we should |
| 3868 | // immediately force the new one to be displayed. If |
| 3869 | // it is animating, we need to move that animation to |
| 3870 | // the new one. |
| 3871 | if (ttoken.allDrawn) { |
| 3872 | wtoken.allDrawn = true; |
| 3873 | } |
| 3874 | if (ttoken.firstWindowDrawn) { |
| 3875 | wtoken.firstWindowDrawn = true; |
| 3876 | } |
| 3877 | if (!ttoken.hidden) { |
| 3878 | wtoken.hidden = false; |
| 3879 | wtoken.hiddenRequested = false; |
| 3880 | wtoken.willBeHidden = false; |
| 3881 | } |
| 3882 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3883 | wtoken.clientHidden = ttoken.clientHidden; |
| 3884 | wtoken.sendAppVisibilityToClients(); |
| 3885 | } |
| 3886 | if (ttoken.animation != null) { |
| 3887 | wtoken.animation = ttoken.animation; |
| 3888 | wtoken.animating = ttoken.animating; |
| 3889 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3890 | ttoken.animation = null; |
| 3891 | ttoken.animLayerAdjustment = 0; |
| 3892 | wtoken.updateLayers(); |
| 3893 | ttoken.updateLayers(); |
| 3894 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3895 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 3896 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 3897 | true /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3898 | mLayoutNeeded = true; |
| 3899 | performLayoutAndPlaceSurfacesLocked(); |
| 3900 | Binder.restoreCallingIdentity(origId); |
| 3901 | return; |
| 3902 | } else if (ttoken.startingData != null) { |
| 3903 | // The previous app was getting ready to show a |
| 3904 | // starting window, but hasn't yet done so. Steal it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3905 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3906 | "Moving pending starting from " + ttoken |
| 3907 | + " to " + wtoken); |
| 3908 | wtoken.startingData = ttoken.startingData; |
| 3909 | ttoken.startingData = null; |
| 3910 | ttoken.startingMoved = true; |
| 3911 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3912 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3913 | // want to process the message ASAP, before any other queued |
| 3914 | // messages. |
| 3915 | mH.sendMessageAtFrontOfQueue(m); |
| 3916 | return; |
| 3917 | } |
| 3918 | } |
| 3919 | } |
| 3920 | |
| 3921 | // There is no existing starting window, and the caller doesn't |
| 3922 | // want us to create one, so that's it! |
| 3923 | if (!createIfNeeded) { |
| 3924 | return; |
| 3925 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3926 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3927 | // If this is a translucent or wallpaper window, then don't |
| 3928 | // show a starting window -- the current effect (a full-screen |
| 3929 | // opaque starting window that fades away to the real contents |
| 3930 | // when it is ready) does not work for this. |
| 3931 | if (theme != 0) { |
| 3932 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3933 | com.android.internal.R.styleable.Window); |
| 3934 | if (ent.array.getBoolean( |
| 3935 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3936 | return; |
| 3937 | } |
| 3938 | if (ent.array.getBoolean( |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3939 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3940 | return; |
| 3941 | } |
| 3942 | if (ent.array.getBoolean( |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3943 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3944 | return; |
| 3945 | } |
| 3946 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3947 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3948 | mStartingIconInTransition = true; |
| 3949 | wtoken.startingData = new StartingData( |
| 3950 | pkg, theme, nonLocalizedLabel, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 3951 | labelRes, icon, windowFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3952 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3953 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3954 | // want to process the message ASAP, before any other queued |
| 3955 | // messages. |
| 3956 | mH.sendMessageAtFrontOfQueue(m); |
| 3957 | } |
| 3958 | } |
| 3959 | |
| 3960 | public void setAppWillBeHidden(IBinder token) { |
| 3961 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3962 | "setAppWillBeHidden()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3963 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3964 | } |
| 3965 | |
| 3966 | AppWindowToken wtoken; |
| 3967 | |
| 3968 | synchronized(mWindowMap) { |
| 3969 | wtoken = findAppWindowToken(token); |
| 3970 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3971 | 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] | 3972 | return; |
| 3973 | } |
| 3974 | wtoken.willBeHidden = true; |
| 3975 | } |
| 3976 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3977 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3978 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3979 | boolean visible, int transit, boolean performLayout) { |
| 3980 | boolean delayed = false; |
| 3981 | |
| 3982 | if (wtoken.clientHidden == visible) { |
| 3983 | wtoken.clientHidden = !visible; |
| 3984 | wtoken.sendAppVisibilityToClients(); |
| 3985 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3986 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3987 | wtoken.willBeHidden = false; |
| 3988 | if (wtoken.hidden == visible) { |
| 3989 | final int N = wtoken.allAppWindows.size(); |
| 3990 | boolean changed = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3991 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3992 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3993 | + " performLayout=" + performLayout); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3994 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3995 | boolean runningAppAnimation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3996 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3997 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3998 | if (wtoken.animation == sDummyAnimation) { |
| 3999 | wtoken.animation = null; |
| 4000 | } |
| 4001 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 4002 | changed = true; |
| 4003 | if (wtoken.animation != null) { |
| 4004 | delayed = runningAppAnimation = true; |
| 4005 | } |
| 4006 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4007 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4008 | for (int i=0; i<N; i++) { |
| 4009 | WindowState win = wtoken.allAppWindows.get(i); |
| 4010 | if (win == wtoken.startingWindow) { |
| 4011 | continue; |
| 4012 | } |
| 4013 | |
| 4014 | if (win.isAnimating()) { |
| 4015 | delayed = true; |
| 4016 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4017 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4018 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4019 | //win.dump(" "); |
| 4020 | if (visible) { |
| 4021 | if (!win.isVisibleNow()) { |
| 4022 | if (!runningAppAnimation) { |
| 4023 | applyAnimationLocked(win, |
| 4024 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 4025 | } |
| 4026 | changed = true; |
| 4027 | } |
| 4028 | } else if (win.isVisibleNow()) { |
| 4029 | if (!runningAppAnimation) { |
| 4030 | applyAnimationLocked(win, |
| 4031 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 4032 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4033 | changed = true; |
| 4034 | } |
| 4035 | } |
| 4036 | |
| 4037 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 4038 | if (!visible) { |
| 4039 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 4040 | } else { |
| 4041 | // If we are being set visible, and the starting window is |
| 4042 | // not yet displayed, then make sure it doesn't get displayed. |
| 4043 | WindowState swin = wtoken.startingWindow; |
| 4044 | if (swin != null && (swin.mDrawPending |
| 4045 | || swin.mCommitDrawPending)) { |
| 4046 | swin.mPolicyVisibility = false; |
| 4047 | swin.mPolicyVisibilityAfterAnim = false; |
| 4048 | } |
| 4049 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4050 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4051 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4052 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 4053 | + wtoken.hiddenRequested); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4054 | |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 4055 | if (changed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4056 | mLayoutNeeded = true; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 4057 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 4058 | if (performLayout) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 4059 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4060 | false /*updateInputWindows*/); |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 4061 | performLayoutAndPlaceSurfacesLocked(); |
| 4062 | } |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 4063 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4064 | } |
| 4065 | } |
| 4066 | |
| 4067 | if (wtoken.animation != null) { |
| 4068 | delayed = true; |
| 4069 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4070 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4071 | return delayed; |
| 4072 | } |
| 4073 | |
| 4074 | public void setAppVisibility(IBinder token, boolean visible) { |
| 4075 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4076 | "setAppVisibility()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4077 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4078 | } |
| 4079 | |
| 4080 | AppWindowToken wtoken; |
| 4081 | |
| 4082 | synchronized(mWindowMap) { |
| 4083 | wtoken = findAppWindowToken(token); |
| 4084 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4085 | 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] | 4086 | return; |
| 4087 | } |
| 4088 | |
| 4089 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 4090 | RuntimeException e = null; |
| 4091 | if (!HIDE_STACK_CRAWLS) { |
| 4092 | e = new RuntimeException(); |
| 4093 | e.fillInStackTrace(); |
| 4094 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4095 | Slog.v(TAG, "setAppVisibility(" + token + ", " + visible |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4096 | + "): mNextAppTransition=" + mNextAppTransition |
| 4097 | + " hidden=" + wtoken.hidden |
| 4098 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 4099 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4100 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4101 | // If we are preparing an app transition, then delay changing |
| 4102 | // the visibility of this token until we execute that transition. |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 4103 | if (!mDisplayFrozen && mPolicy.isScreenOn() |
| 4104 | && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4105 | // Already in requested state, don't do anything more. |
| 4106 | if (wtoken.hiddenRequested != visible) { |
| 4107 | return; |
| 4108 | } |
| 4109 | wtoken.hiddenRequested = !visible; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4110 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4111 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4112 | TAG, "Setting dummy animation on: " + wtoken); |
| 4113 | wtoken.setDummyAnimation(); |
| 4114 | mOpeningApps.remove(wtoken); |
| 4115 | mClosingApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4116 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4117 | wtoken.inPendingTransaction = true; |
| 4118 | if (visible) { |
| 4119 | mOpeningApps.add(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4120 | wtoken.startingDisplayed = false; |
| 4121 | wtoken.startingMoved = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4122 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4123 | // If the token is currently hidden (should be the |
| 4124 | // common case), then we need to set up to wait for |
| 4125 | // its windows to be ready. |
| 4126 | if (wtoken.hidden) { |
| 4127 | wtoken.allDrawn = false; |
| 4128 | wtoken.waitingToShow = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4129 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4130 | if (wtoken.clientHidden) { |
| 4131 | // In the case where we are making an app visible |
| 4132 | // but holding off for a transition, we still need |
| 4133 | // to tell the client to make its windows visible so |
| 4134 | // they get drawn. Otherwise, we will wait on |
| 4135 | // performing the transition until all windows have |
| 4136 | // been drawn, they never will be, and we are sad. |
| 4137 | wtoken.clientHidden = false; |
| 4138 | wtoken.sendAppVisibilityToClients(); |
| 4139 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4140 | } |
| 4141 | } else { |
| 4142 | mClosingApps.add(wtoken); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4143 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4144 | // If the token is currently visible (should be the |
| 4145 | // common case), then set up to wait for it to be hidden. |
| 4146 | if (!wtoken.hidden) { |
| 4147 | wtoken.waitingToHide = true; |
| 4148 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4149 | } |
| 4150 | return; |
| 4151 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4152 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4153 | final long origId = Binder.clearCallingIdentity(); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4154 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4155 | wtoken.updateReportedVisibilityLocked(); |
| 4156 | Binder.restoreCallingIdentity(origId); |
| 4157 | } |
| 4158 | } |
| 4159 | |
| 4160 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4161 | boolean unfreezeSurfaceNow, boolean force) { |
| 4162 | if (wtoken.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4163 | 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] | 4164 | + " force=" + force); |
| 4165 | final int N = wtoken.allAppWindows.size(); |
| 4166 | boolean unfrozeWindows = false; |
| 4167 | for (int i=0; i<N; i++) { |
| 4168 | WindowState w = wtoken.allAppWindows.get(i); |
| 4169 | if (w.mAppFreezing) { |
| 4170 | w.mAppFreezing = false; |
| 4171 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 4172 | w.mOrientationChanging = true; |
| 4173 | } |
| 4174 | unfrozeWindows = true; |
| 4175 | } |
| 4176 | } |
| 4177 | if (force || unfrozeWindows) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4178 | 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] | 4179 | wtoken.freezingScreen = false; |
| 4180 | mAppsFreezingScreen--; |
| 4181 | } |
| 4182 | if (unfreezeSurfaceNow) { |
| 4183 | if (unfrozeWindows) { |
| 4184 | mLayoutNeeded = true; |
| 4185 | performLayoutAndPlaceSurfacesLocked(); |
| 4186 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4187 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4188 | } |
| 4189 | } |
| 4190 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4191 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4192 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4193 | int configChanges) { |
| 4194 | if (DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 4195 | RuntimeException e = null; |
| 4196 | if (!HIDE_STACK_CRAWLS) { |
| 4197 | e = new RuntimeException(); |
| 4198 | e.fillInStackTrace(); |
| 4199 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4200 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4201 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 4202 | + wtoken.freezingScreen, e); |
| 4203 | } |
| 4204 | if (!wtoken.hiddenRequested) { |
| 4205 | if (!wtoken.freezingScreen) { |
| 4206 | wtoken.freezingScreen = true; |
| 4207 | mAppsFreezingScreen++; |
| 4208 | if (mAppsFreezingScreen == 1) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4209 | startFreezingDisplayLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4210 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 4211 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 4212 | 5000); |
| 4213 | } |
| 4214 | } |
| 4215 | final int N = wtoken.allAppWindows.size(); |
| 4216 | for (int i=0; i<N; i++) { |
| 4217 | WindowState w = wtoken.allAppWindows.get(i); |
| 4218 | w.mAppFreezing = true; |
| 4219 | } |
| 4220 | } |
| 4221 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4222 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4223 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 4224 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4225 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4226 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4227 | } |
| 4228 | |
| 4229 | synchronized(mWindowMap) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 4230 | if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4231 | 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] | 4232 | return; |
| 4233 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4234 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4235 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4236 | if (wtoken == null || wtoken.appToken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4237 | 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] | 4238 | return; |
| 4239 | } |
| 4240 | final long origId = Binder.clearCallingIdentity(); |
| 4241 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 4242 | Binder.restoreCallingIdentity(origId); |
| 4243 | } |
| 4244 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4245 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4246 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 4247 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4248 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4249 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4250 | } |
| 4251 | |
| 4252 | synchronized(mWindowMap) { |
| 4253 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4254 | if (wtoken == null || wtoken.appToken == null) { |
| 4255 | return; |
| 4256 | } |
| 4257 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4258 | 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] | 4259 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 4260 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 4261 | Binder.restoreCallingIdentity(origId); |
| 4262 | } |
| 4263 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4264 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4265 | public void removeAppToken(IBinder token) { |
| 4266 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4267 | "removeAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4268 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4269 | } |
| 4270 | |
| 4271 | AppWindowToken wtoken = null; |
| 4272 | AppWindowToken startingToken = null; |
| 4273 | boolean delayed = false; |
| 4274 | |
| 4275 | final long origId = Binder.clearCallingIdentity(); |
| 4276 | synchronized(mWindowMap) { |
| 4277 | WindowToken basewtoken = mTokenMap.remove(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4278 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4279 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4280 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4281 | wtoken.inPendingTransaction = false; |
| 4282 | mOpeningApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4283 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4284 | if (mClosingApps.contains(wtoken)) { |
| 4285 | delayed = true; |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4286 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4287 | mClosingApps.add(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4288 | wtoken.waitingToHide = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4289 | delayed = true; |
| 4290 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4291 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4292 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 4293 | + " animation=" + wtoken.animation |
| 4294 | + " animating=" + wtoken.animating); |
| 4295 | if (delayed) { |
| 4296 | // set the token aside because it has an active animation to be finished |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4297 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4298 | "removeAppToken make exiting: " + wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4299 | mExitingAppTokens.add(wtoken); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 4300 | } else { |
| 4301 | // Make sure there is no animation running on this token, |
| 4302 | // so any windows associated with it will be removed as |
| 4303 | // soon as their animations are complete |
| 4304 | wtoken.animation = null; |
| 4305 | wtoken.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4306 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4307 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4308 | "removeAppToken: " + wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4309 | mAppTokens.remove(wtoken); |
| 4310 | wtoken.removed = true; |
| 4311 | if (wtoken.startingData != null) { |
| 4312 | startingToken = wtoken; |
| 4313 | } |
| 4314 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 4315 | if (mFocusedApp == wtoken) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4316 | 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] | 4317 | mFocusedApp = null; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 4318 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4319 | mInputMonitor.setFocusedAppLw(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4320 | } |
| 4321 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4322 | 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] | 4323 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4324 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4325 | if (!delayed && wtoken != null) { |
| 4326 | wtoken.updateReportedVisibilityLocked(); |
| 4327 | } |
| 4328 | } |
| 4329 | Binder.restoreCallingIdentity(origId); |
| 4330 | |
| 4331 | if (startingToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4332 | 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] | 4333 | + startingToken + ": app token removed"); |
| 4334 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 4335 | mH.sendMessage(m); |
| 4336 | } |
| 4337 | } |
| 4338 | |
| 4339 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 4340 | final int NW = token.windows.size(); |
| 4341 | for (int i=0; i<NW; i++) { |
| 4342 | WindowState win = token.windows.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4343 | 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] | 4344 | mWindows.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4345 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4346 | int j = win.mChildWindows.size(); |
| 4347 | while (j > 0) { |
| 4348 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4349 | WindowState cwin = win.mChildWindows.get(j); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4350 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4351 | "Tmp removing child window " + cwin); |
| 4352 | mWindows.remove(cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4353 | } |
| 4354 | } |
| 4355 | return NW > 0; |
| 4356 | } |
| 4357 | |
| 4358 | void dumpAppTokensLocked() { |
| 4359 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4360 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4361 | } |
| 4362 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4363 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4364 | void dumpWindowsLocked() { |
| 4365 | for (int i=mWindows.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4366 | Slog.v(TAG, " #" + i + ": " + mWindows.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4367 | } |
| 4368 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4369 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4370 | private int findWindowOffsetLocked(int tokenPos) { |
| 4371 | final int NW = mWindows.size(); |
| 4372 | |
| 4373 | if (tokenPos >= mAppTokens.size()) { |
| 4374 | int i = NW; |
| 4375 | while (i > 0) { |
| 4376 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4377 | WindowState win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4378 | if (win.getAppToken() != null) { |
| 4379 | return i+1; |
| 4380 | } |
| 4381 | } |
| 4382 | } |
| 4383 | |
| 4384 | while (tokenPos > 0) { |
| 4385 | // Find the first app token below the new position that has |
| 4386 | // a window displayed. |
| 4387 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4388 | 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] | 4389 | + tokenPos + " -- " + wtoken.token); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4390 | if (wtoken.sendingToBottom) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4391 | if (DEBUG_REORDER) Slog.v(TAG, |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4392 | "Skipping token -- currently sending to bottom"); |
| 4393 | tokenPos--; |
| 4394 | continue; |
| 4395 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4396 | int i = wtoken.windows.size(); |
| 4397 | while (i > 0) { |
| 4398 | i--; |
| 4399 | WindowState win = wtoken.windows.get(i); |
| 4400 | int j = win.mChildWindows.size(); |
| 4401 | while (j > 0) { |
| 4402 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4403 | WindowState cwin = win.mChildWindows.get(j); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4404 | if (cwin.mSubLayer >= 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4405 | for (int pos=NW-1; pos>=0; pos--) { |
| 4406 | if (mWindows.get(pos) == cwin) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4407 | if (DEBUG_REORDER) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4408 | "Found child win @" + (pos+1)); |
| 4409 | return pos+1; |
| 4410 | } |
| 4411 | } |
| 4412 | } |
| 4413 | } |
| 4414 | for (int pos=NW-1; pos>=0; pos--) { |
| 4415 | if (mWindows.get(pos) == win) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4416 | 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] | 4417 | return pos+1; |
| 4418 | } |
| 4419 | } |
| 4420 | } |
| 4421 | tokenPos--; |
| 4422 | } |
| 4423 | |
| 4424 | return 0; |
| 4425 | } |
| 4426 | |
| 4427 | private final int reAddWindowLocked(int index, WindowState win) { |
| 4428 | final int NCW = win.mChildWindows.size(); |
| 4429 | boolean added = false; |
| 4430 | for (int j=0; j<NCW; j++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4431 | WindowState cwin = win.mChildWindows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4432 | if (!added && cwin.mSubLayer >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4433 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4434 | + index + ": " + cwin); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4435 | win.mRebuilding = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4436 | mWindows.add(index, win); |
| 4437 | index++; |
| 4438 | added = true; |
| 4439 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4440 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4441 | + index + ": " + cwin); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4442 | cwin.mRebuilding = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4443 | mWindows.add(index, cwin); |
| 4444 | index++; |
| 4445 | } |
| 4446 | if (!added) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4447 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4448 | + index + ": " + win); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4449 | win.mRebuilding = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4450 | mWindows.add(index, win); |
| 4451 | index++; |
| 4452 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4453 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4454 | return index; |
| 4455 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4456 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4457 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 4458 | final int NW = token.windows.size(); |
| 4459 | for (int i=0; i<NW; i++) { |
| 4460 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 4461 | } |
| 4462 | return index; |
| 4463 | } |
| 4464 | |
| 4465 | public void moveAppToken(int index, IBinder token) { |
| 4466 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4467 | "moveAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4468 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4469 | } |
| 4470 | |
| 4471 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4472 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4473 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 4474 | final AppWindowToken wtoken = findAppWindowToken(token); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4475 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG, |
| 4476 | "Start moving token " + wtoken + " initially at " |
| 4477 | + mAppTokens.indexOf(wtoken)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4478 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4479 | 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] | 4480 | + token + " (" + wtoken + ")"); |
| 4481 | return; |
| 4482 | } |
| 4483 | mAppTokens.add(index, wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4484 | if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4485 | else if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, "Moved " + token + " to " + index); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4486 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4487 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4488 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4489 | 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] | 4490 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4491 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4492 | 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] | 4493 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4494 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4495 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4496 | if (DEBUG_REORDER) dumpWindowsLocked(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 4497 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4498 | false /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4499 | mLayoutNeeded = true; |
| 4500 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 4501 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4502 | } |
| 4503 | Binder.restoreCallingIdentity(origId); |
| 4504 | } |
| 4505 | } |
| 4506 | |
| 4507 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 4508 | // XXX This should be done more efficiently! |
| 4509 | // (take advantage of the fact that both lists should be |
| 4510 | // ordered in the same way.) |
| 4511 | int N = tokens.size(); |
| 4512 | for (int i=0; i<N; i++) { |
| 4513 | IBinder token = tokens.get(i); |
| 4514 | final AppWindowToken wtoken = findAppWindowToken(token); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4515 | if (DEBUG_REORDER || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4516 | "Temporarily removing " + wtoken + " from " + mAppTokens.indexOf(wtoken)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4517 | if (!mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4518 | 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] | 4519 | + token + " (" + wtoken + ")"); |
| 4520 | i--; |
| 4521 | N--; |
| 4522 | } |
| 4523 | } |
| 4524 | } |
| 4525 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4526 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 4527 | boolean updateFocusAndLayout) { |
| 4528 | // First remove all of the windows from the list. |
| 4529 | tmpRemoveAppWindowsLocked(wtoken); |
| 4530 | |
| 4531 | // Where to start adding? |
| 4532 | int pos = findWindowOffsetLocked(tokenPos); |
| 4533 | |
| 4534 | // And now add them back at the correct place. |
| 4535 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 4536 | |
| 4537 | if (updateFocusAndLayout) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 4538 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4539 | false /*updateInputWindows*/)) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4540 | assignLayersLocked(); |
| 4541 | } |
| 4542 | mLayoutNeeded = true; |
| 4543 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 4544 | mInputMonitor.updateInputWindowsLw(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4545 | } |
| 4546 | } |
| 4547 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4548 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 4549 | // First remove all of the windows from the list. |
| 4550 | final int N = tokens.size(); |
| 4551 | int i; |
| 4552 | for (i=0; i<N; i++) { |
| 4553 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4554 | if (token != null) { |
| 4555 | tmpRemoveAppWindowsLocked(token); |
| 4556 | } |
| 4557 | } |
| 4558 | |
| 4559 | // Where to start adding? |
| 4560 | int pos = findWindowOffsetLocked(tokenPos); |
| 4561 | |
| 4562 | // And now add them back at the correct place. |
| 4563 | for (i=0; i<N; i++) { |
| 4564 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4565 | if (token != null) { |
| 4566 | pos = reAddAppWindowsLocked(pos, token); |
| 4567 | } |
| 4568 | } |
| 4569 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 4570 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4571 | false /*updateInputWindows*/)) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4572 | assignLayersLocked(); |
| 4573 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4574 | mLayoutNeeded = true; |
| 4575 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 4576 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4577 | |
| 4578 | //dump(); |
| 4579 | } |
| 4580 | |
| 4581 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4582 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4583 | "moveAppTokensToTop()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4584 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4585 | } |
| 4586 | |
| 4587 | final long origId = Binder.clearCallingIdentity(); |
| 4588 | synchronized(mWindowMap) { |
| 4589 | removeAppTokensLocked(tokens); |
| 4590 | final int N = tokens.size(); |
| 4591 | for (int i=0; i<N; i++) { |
| 4592 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4593 | if (wt != null) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4594 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG, |
| 4595 | "Adding next to top: " + wt); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4596 | mAppTokens.add(wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4597 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4598 | mToTopApps.remove(wt); |
| 4599 | mToBottomApps.remove(wt); |
| 4600 | mToTopApps.add(wt); |
| 4601 | wt.sendingToBottom = false; |
| 4602 | wt.sendingToTop = true; |
| 4603 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4604 | } |
| 4605 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4606 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4607 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4608 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4609 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4610 | } |
| 4611 | Binder.restoreCallingIdentity(origId); |
| 4612 | } |
| 4613 | |
| 4614 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4615 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4616 | "moveAppTokensToBottom()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4617 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4618 | } |
| 4619 | |
| 4620 | final long origId = Binder.clearCallingIdentity(); |
| 4621 | synchronized(mWindowMap) { |
| 4622 | removeAppTokensLocked(tokens); |
| 4623 | final int N = tokens.size(); |
| 4624 | int pos = 0; |
| 4625 | for (int i=0; i<N; i++) { |
| 4626 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4627 | if (wt != null) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4628 | if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4629 | "Adding next to bottom: " + wt + " at " + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4630 | mAppTokens.add(pos, wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4631 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4632 | mToTopApps.remove(wt); |
| 4633 | mToBottomApps.remove(wt); |
| 4634 | mToBottomApps.add(i, wt); |
| 4635 | wt.sendingToTop = false; |
| 4636 | wt.sendingToBottom = true; |
| 4637 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4638 | pos++; |
| 4639 | } |
| 4640 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4641 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4642 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4643 | moveAppWindowsLocked(tokens, 0); |
| 4644 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4645 | } |
| 4646 | Binder.restoreCallingIdentity(origId); |
| 4647 | } |
| 4648 | |
| 4649 | // ------------------------------------------------------------- |
| 4650 | // Misc IWindowSession methods |
| 4651 | // ------------------------------------------------------------- |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4652 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4653 | private boolean shouldAllowDisableKeyguard() |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4654 | { |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4655 | // We fail safe and prevent disabling keyguard in the unlikely event this gets |
| 4656 | // called before DevicePolicyManagerService has started. |
| 4657 | if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { |
| 4658 | DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( |
| 4659 | Context.DEVICE_POLICY_SERVICE); |
| 4660 | if (dpm != null) { |
| 4661 | mAllowDisableKeyguard = dpm.getPasswordQuality(null) |
| 4662 | == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? |
| 4663 | ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; |
| 4664 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4665 | } |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4666 | return mAllowDisableKeyguard == ALLOW_DISABLE_YES; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4667 | } |
| 4668 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4669 | public void disableKeyguard(IBinder token, String tag) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4670 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4671 | != PackageManager.PERMISSION_GRANTED) { |
| 4672 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4673 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4674 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4675 | synchronized (mKeyguardTokenWatcher) { |
| 4676 | mKeyguardTokenWatcher.acquire(token, tag); |
Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4677 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4678 | } |
| 4679 | |
| 4680 | public void reenableKeyguard(IBinder token) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4681 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4682 | != PackageManager.PERMISSION_GRANTED) { |
| 4683 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4684 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4685 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4686 | synchronized (mKeyguardTokenWatcher) { |
| 4687 | mKeyguardTokenWatcher.release(token); |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4688 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4689 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4690 | // If we are the last one to reenable the keyguard wait until |
| 4691 | // we have actually finished reenabling until returning. |
| 4692 | // It is possible that reenableKeyguard() can be called before |
| 4693 | // the previous disableKeyguard() is handled, in which case |
| 4694 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4695 | // be called. In that case mKeyguardDisabled will be false here |
| 4696 | // and we have nothing to wait for. |
| 4697 | while (mKeyguardDisabled) { |
| 4698 | try { |
| 4699 | mKeyguardTokenWatcher.wait(); |
| 4700 | } catch (InterruptedException e) { |
| 4701 | Thread.currentThread().interrupt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4702 | } |
| 4703 | } |
| 4704 | } |
| 4705 | } |
| 4706 | } |
| 4707 | |
| 4708 | /** |
| 4709 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4710 | */ |
| 4711 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4712 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4713 | != PackageManager.PERMISSION_GRANTED) { |
| 4714 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4715 | } |
| 4716 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4717 | public void onKeyguardExitResult(boolean success) { |
| 4718 | try { |
| 4719 | callback.onKeyguardExitResult(success); |
| 4720 | } catch (RemoteException e) { |
| 4721 | // Client has died, we don't care. |
| 4722 | } |
| 4723 | } |
| 4724 | }); |
| 4725 | } |
| 4726 | |
| 4727 | public boolean inKeyguardRestrictedInputMode() { |
| 4728 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4729 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4730 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4731 | public void closeSystemDialogs(String reason) { |
| 4732 | synchronized(mWindowMap) { |
| 4733 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4734 | WindowState w = mWindows.get(i); |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4735 | if (w.mSurface != null) { |
| 4736 | try { |
| 4737 | w.mClient.closeSystemDialogs(reason); |
| 4738 | } catch (RemoteException e) { |
| 4739 | } |
| 4740 | } |
| 4741 | } |
| 4742 | } |
| 4743 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4744 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4745 | static float fixScale(float scale) { |
| 4746 | if (scale < 0) scale = 0; |
| 4747 | else if (scale > 20) scale = 20; |
| 4748 | return Math.abs(scale); |
| 4749 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4750 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4751 | public void setAnimationScale(int which, float scale) { |
| 4752 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4753 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4754 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4755 | } |
| 4756 | |
| 4757 | if (scale < 0) scale = 0; |
| 4758 | else if (scale > 20) scale = 20; |
| 4759 | scale = Math.abs(scale); |
| 4760 | switch (which) { |
| 4761 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4762 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4763 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4764 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4765 | // Persist setting |
| 4766 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4767 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4768 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4769 | public void setAnimationScales(float[] scales) { |
| 4770 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4771 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4772 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4773 | } |
| 4774 | |
| 4775 | if (scales != null) { |
| 4776 | if (scales.length >= 1) { |
| 4777 | mWindowAnimationScale = fixScale(scales[0]); |
| 4778 | } |
| 4779 | if (scales.length >= 2) { |
| 4780 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4781 | } |
| 4782 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4783 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4784 | // Persist setting |
| 4785 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4786 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4787 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4788 | public float getAnimationScale(int which) { |
| 4789 | switch (which) { |
| 4790 | case 0: return mWindowAnimationScale; |
| 4791 | case 1: return mTransitionAnimationScale; |
| 4792 | } |
| 4793 | return 0; |
| 4794 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4795 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4796 | public float[] getAnimationScales() { |
| 4797 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4798 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4799 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4800 | public int getSwitchState(int sw) { |
| 4801 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4802 | "getSwitchState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4803 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4804 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4805 | return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4806 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4807 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4808 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4809 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4810 | "getSwitchStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4811 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4812 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4813 | return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4814 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4815 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4816 | public int getScancodeState(int sw) { |
| 4817 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4818 | "getScancodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4819 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4820 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4821 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4822 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4823 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4824 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4825 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4826 | "getScancodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4827 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4828 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4829 | return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4830 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4831 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4832 | public int getTrackballScancodeState(int sw) { |
| 4833 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4834 | "getTrackballScancodeState()")) { |
| 4835 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4836 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4837 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4838 | } |
| 4839 | |
| 4840 | public int getDPadScancodeState(int sw) { |
| 4841 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4842 | "getDPadScancodeState()")) { |
| 4843 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4844 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4845 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4846 | } |
| 4847 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4848 | public int getKeycodeState(int sw) { |
| 4849 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4850 | "getKeycodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4851 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4852 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4853 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4854 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4855 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4856 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4857 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4858 | "getKeycodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4859 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4860 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4861 | return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4862 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4863 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4864 | public int getTrackballKeycodeState(int sw) { |
| 4865 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4866 | "getTrackballKeycodeState()")) { |
| 4867 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4868 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4869 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4870 | } |
| 4871 | |
| 4872 | public int getDPadKeycodeState(int sw) { |
| 4873 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4874 | "getDPadKeycodeState()")) { |
| 4875 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4876 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4877 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4878 | } |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4879 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4880 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4881 | return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4882 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4883 | |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4884 | public InputChannel monitorInput(String inputChannelName) { |
| 4885 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4886 | "monitorInput()")) { |
| 4887 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4888 | } |
| 4889 | return mInputManager.monitorInput(inputChannelName); |
| 4890 | } |
| 4891 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 4892 | public InputDevice getInputDevice(int deviceId) { |
| 4893 | return mInputManager.getInputDevice(deviceId); |
| 4894 | } |
| 4895 | |
| 4896 | public int[] getInputDeviceIds() { |
| 4897 | return mInputManager.getInputDeviceIds(); |
| 4898 | } |
| 4899 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4900 | public void enableScreenAfterBoot() { |
| 4901 | synchronized(mWindowMap) { |
| 4902 | if (mSystemBooted) { |
| 4903 | return; |
| 4904 | } |
| 4905 | mSystemBooted = true; |
| 4906 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4907 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4908 | performEnableScreen(); |
| 4909 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4910 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4911 | public void enableScreenIfNeededLocked() { |
| 4912 | if (mDisplayEnabled) { |
| 4913 | return; |
| 4914 | } |
| 4915 | if (!mSystemBooted) { |
| 4916 | return; |
| 4917 | } |
| 4918 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4919 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4920 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4921 | public void performEnableScreen() { |
| 4922 | synchronized(mWindowMap) { |
| 4923 | if (mDisplayEnabled) { |
| 4924 | return; |
| 4925 | } |
| 4926 | if (!mSystemBooted) { |
| 4927 | return; |
| 4928 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4929 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4930 | // Don't enable the screen until all existing windows |
| 4931 | // have been drawn. |
| 4932 | final int N = mWindows.size(); |
| 4933 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4934 | WindowState w = mWindows.get(i); |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 4935 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4936 | return; |
| 4937 | } |
| 4938 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4939 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4940 | mDisplayEnabled = true; |
| 4941 | if (false) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4942 | Slog.i(TAG, "ENABLING SCREEN!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4943 | StringWriter sw = new StringWriter(); |
| 4944 | PrintWriter pw = new PrintWriter(sw); |
| 4945 | this.dump(null, pw, null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4946 | Slog.i(TAG, sw.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4947 | } |
| 4948 | try { |
| 4949 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4950 | if (surfaceFlinger != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4951 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4952 | Parcel data = Parcel.obtain(); |
| 4953 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4954 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4955 | data, null, 0); |
| 4956 | data.recycle(); |
| 4957 | } |
| 4958 | } catch (RemoteException ex) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4959 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4960 | } |
| 4961 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4962 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4963 | mPolicy.enableScreenAfterBoot(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4964 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4965 | // Make sure the last requested orientation has been applied. |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4966 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4967 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4968 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4969 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4970 | public void setInTouchMode(boolean mode) { |
| 4971 | synchronized(mWindowMap) { |
| 4972 | mInTouchMode = mode; |
| 4973 | } |
| 4974 | } |
| 4975 | |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 4976 | // TODO: more accounting of which pid(s) turned it on, keep count, |
| 4977 | // only allow disables from pids which have count on, etc. |
| 4978 | public void showStrictModeViolation(boolean on) { |
| 4979 | int pid = Binder.getCallingPid(); |
| 4980 | synchronized(mWindowMap) { |
| 4981 | // Ignoring requests to enable the red border from clients |
| 4982 | // which aren't on screen. (e.g. Broadcast Receivers in |
| 4983 | // the background..) |
| 4984 | if (on) { |
| 4985 | boolean isVisible = false; |
| 4986 | for (WindowState ws : mWindows) { |
| 4987 | if (ws.mSession.mPid == pid && ws.isVisibleLw()) { |
| 4988 | isVisible = true; |
| 4989 | break; |
| 4990 | } |
| 4991 | } |
| 4992 | if (!isVisible) { |
| 4993 | return; |
| 4994 | } |
| 4995 | } |
| 4996 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4997 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION showStrictModeViolation"); |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 4998 | Surface.openTransaction(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4999 | try { |
| 5000 | if (mStrictModeFlash == null) { |
| 5001 | mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession); |
| 5002 | } |
| 5003 | mStrictModeFlash.setVisibility(on); |
| 5004 | } finally { |
| 5005 | Surface.closeTransaction(); |
| 5006 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION showStrictModeViolation"); |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5007 | } |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5008 | } |
| 5009 | } |
| 5010 | |
Brad Fitzpatrick | c1a968a | 2010-11-24 08:56:40 -0800 | [diff] [blame] | 5011 | public void setStrictModeVisualIndicatorPreference(String value) { |
| 5012 | SystemProperties.set(StrictMode.VISUAL_PROPERTY, value); |
| 5013 | } |
| 5014 | |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5015 | public Bitmap screenshotApplications(IBinder appToken, int maxWidth, int maxHeight) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5016 | if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER, |
| 5017 | "screenshotApplications()")) { |
| 5018 | throw new SecurityException("Requires READ_FRAME_BUFFER permission"); |
| 5019 | } |
| 5020 | |
| 5021 | Bitmap rawss; |
| 5022 | |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5023 | int maxLayer = 0; |
| 5024 | boolean foundApp; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5025 | final Rect frame = new Rect(); |
| 5026 | |
| 5027 | float scale; |
| 5028 | int sw, sh, dw, dh; |
| 5029 | int rot; |
| 5030 | |
| 5031 | synchronized(mWindowMap) { |
| 5032 | long ident = Binder.clearCallingIdentity(); |
| 5033 | |
| 5034 | int aboveAppLayer = mPolicy.windowTypeToLayerLw( |
| 5035 | WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER |
| 5036 | + TYPE_LAYER_OFFSET; |
| 5037 | aboveAppLayer += TYPE_LAYER_MULTIPLIER; |
| 5038 | |
| 5039 | // Figure out the part of the screen that is actually the app. |
| 5040 | for (int i=0; i<mWindows.size(); i++) { |
| 5041 | WindowState ws = mWindows.get(i); |
| 5042 | if (ws.mSurface == null) { |
| 5043 | continue; |
| 5044 | } |
| 5045 | if (ws.mLayer >= aboveAppLayer) { |
| 5046 | break; |
| 5047 | } |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5048 | if (appToken != null && (ws.mAppToken == null |
| 5049 | || ws.mAppToken.token != appToken)) { |
| 5050 | continue; |
| 5051 | } |
| 5052 | if (maxLayer < ws.mAnimLayer) { |
| 5053 | maxLayer = ws.mAnimLayer; |
| 5054 | } |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5055 | final Rect wf = ws.mFrame; |
| 5056 | final Rect cr = ws.mContentInsets; |
| 5057 | int left = wf.left + cr.left; |
| 5058 | int top = wf.top + cr.top; |
| 5059 | int right = wf.right - cr.right; |
| 5060 | int bottom = wf.bottom - cr.bottom; |
| 5061 | frame.union(left, top, right, bottom); |
| 5062 | } |
| 5063 | Binder.restoreCallingIdentity(ident); |
| 5064 | |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5065 | if (frame.isEmpty() || maxLayer == 0) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5066 | return null; |
| 5067 | } |
| 5068 | |
| 5069 | // The screenshot API does not apply the current screen rotation. |
| 5070 | rot = mDisplay.getRotation(); |
| 5071 | int fw = frame.width(); |
| 5072 | int fh = frame.height(); |
| 5073 | |
| 5074 | // First try reducing to fit in x dimension. |
| 5075 | scale = maxWidth/(float)fw; |
| 5076 | sw = maxWidth; |
| 5077 | sh = (int)(fh*scale); |
| 5078 | if (sh > maxHeight) { |
| 5079 | // y dimension became too long; constrain by that. |
| 5080 | scale = maxHeight/(float)fh; |
| 5081 | sw = (int)(fw*scale); |
| 5082 | sh = maxHeight; |
| 5083 | } |
| 5084 | |
| 5085 | // The screen shot will contain the entire screen. |
| 5086 | dw = (int)(mDisplay.getWidth()*scale); |
| 5087 | dh = (int)(mDisplay.getHeight()*scale); |
| 5088 | if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) { |
| 5089 | int tmp = dw; |
| 5090 | dw = dh; |
| 5091 | dh = tmp; |
| 5092 | rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90; |
| 5093 | } |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5094 | rawss = Surface.screenshot(dw, dh, 0, maxLayer); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5095 | } |
| 5096 | |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5097 | if (rawss == null) { |
Dianne Hackborn | 88b03bd | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5098 | Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh |
| 5099 | + ") to layer " + maxLayer); |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5100 | return null; |
| 5101 | } |
| 5102 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5103 | Bitmap bm = Bitmap.createBitmap(sw, sh, rawss.getConfig()); |
| 5104 | Matrix matrix = new Matrix(); |
| 5105 | ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix); |
| 5106 | matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale)); |
| 5107 | Canvas canvas = new Canvas(bm); |
| 5108 | canvas.drawBitmap(rawss, matrix, null); |
| 5109 | |
| 5110 | rawss.recycle(); |
| 5111 | return bm; |
| 5112 | } |
| 5113 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5114 | public void freezeRotation() { |
| 5115 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| 5116 | "setRotation()")) { |
| 5117 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 5118 | } |
| 5119 | |
| 5120 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation); |
| 5121 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0); |
| 5122 | } |
| 5123 | |
| 5124 | public void thawRotation() { |
| 5125 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| 5126 | "setRotation()")) { |
| 5127 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 5128 | } |
| 5129 | |
| 5130 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0); |
| 5131 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0); |
| 5132 | } |
| 5133 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5134 | public void setRotation(int rotation, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 5135 | boolean alwaysSendConfiguration, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5136 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 5137 | "setRotation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5138 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5139 | } |
| 5140 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 5141 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5142 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5143 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 5144 | public void setRotationUnchecked(int rotation, |
| 5145 | boolean alwaysSendConfiguration, int animFlags) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5146 | if(DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5147 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5148 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5149 | long origId = Binder.clearCallingIdentity(); |
| 5150 | boolean changed; |
| 5151 | synchronized(mWindowMap) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5152 | changed = setRotationUncheckedLocked(rotation, animFlags, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5153 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5154 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5155 | if (changed || alwaysSendConfiguration) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5156 | sendNewConfiguration(); |
| 5157 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5158 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5159 | Binder.restoreCallingIdentity(origId); |
| 5160 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5161 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5162 | /** |
| 5163 | * Apply a new rotation to the screen, respecting the requests of |
| 5164 | * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply |
| 5165 | * re-evaluate the desired rotation. |
| 5166 | * |
| 5167 | * Returns null if the rotation has been changed. In this case YOU |
| 5168 | * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN. |
| 5169 | */ |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5170 | public boolean setRotationUncheckedLocked(int rotation, int animFlags, boolean inTransaction) { |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 5171 | if (mDragState != null) { |
| 5172 | // Potential rotation during a drag. Don't do the rotation now, but make |
| 5173 | // a note to perform the rotation later. |
| 5174 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation during drag"); |
| 5175 | mDragState.setDeferredRotation(rotation, animFlags); |
| 5176 | return false; |
| 5177 | } |
| 5178 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5179 | boolean changed; |
| 5180 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| 5181 | rotation = mRequestedRotation; |
| 5182 | } else { |
| 5183 | mRequestedRotation = rotation; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 5184 | mLastRotationFlags = animFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5185 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5186 | 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] | 5187 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5188 | mRotation, mDisplayEnabled); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5189 | 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] | 5190 | changed = mDisplayEnabled && mRotation != rotation; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5191 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5192 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5193 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5194 | "Rotation changed to " + rotation |
| 5195 | + " from " + mRotation |
| 5196 | + " (forceApp=" + mForcedAppOrientation |
| 5197 | + ", req=" + mRequestedRotation + ")"); |
| 5198 | mRotation = rotation; |
| 5199 | mWindowsFreezingScreen = true; |
| 5200 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 5201 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 5202 | 2000); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5203 | mWaitingForConfig = true; |
| 5204 | mLayoutNeeded = true; |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5205 | startFreezingDisplayLocked(inTransaction); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5206 | Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5207 | mInputManager.setDisplayOrientation(0, rotation); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5208 | if (mDisplayEnabled) { |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 5209 | if (CUSTOM_SCREEN_ROTATION) { |
| 5210 | Surface.freezeDisplay(0); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5211 | if (!inTransaction) { |
| 5212 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 5213 | ">>> OPEN TRANSACTION setRotationUnchecked"); |
| 5214 | Surface.openTransaction(); |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 5215 | } |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5216 | try { |
| 5217 | if (mScreenRotationAnimation != null) { |
| 5218 | mScreenRotationAnimation.setRotation(rotation); |
| 5219 | } |
| 5220 | } finally { |
| 5221 | if (!inTransaction) { |
| 5222 | Surface.closeTransaction(); |
| 5223 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 5224 | "<<< CLOSE TRANSACTION setRotationUnchecked"); |
| 5225 | } |
| 5226 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 5227 | Surface.setOrientation(0, rotation, animFlags); |
| 5228 | Surface.unfreezeDisplay(0); |
| 5229 | } else { |
| 5230 | Surface.setOrientation(0, rotation, animFlags); |
| 5231 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5232 | } |
| 5233 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5234 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5235 | if (w.mSurface != null) { |
| 5236 | w.mOrientationChanging = true; |
| 5237 | } |
| 5238 | } |
| 5239 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 5240 | try { |
| 5241 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 5242 | } catch (RemoteException e) { |
| 5243 | } |
| 5244 | } |
| 5245 | } //end if changed |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5246 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5247 | return changed; |
| 5248 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5249 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5250 | public int getRotation() { |
| 5251 | return mRotation; |
| 5252 | } |
| 5253 | |
| 5254 | public int watchRotation(IRotationWatcher watcher) { |
| 5255 | final IBinder watcherBinder = watcher.asBinder(); |
| 5256 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 5257 | public void binderDied() { |
| 5258 | synchronized (mWindowMap) { |
| 5259 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 5260 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 5261 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 5262 | if (removed != null) { |
| 5263 | removed.asBinder().unlinkToDeath(this, 0); |
| 5264 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5265 | i--; |
| 5266 | } |
| 5267 | } |
| 5268 | } |
| 5269 | } |
| 5270 | }; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5271 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5272 | synchronized (mWindowMap) { |
| 5273 | try { |
| 5274 | watcher.asBinder().linkToDeath(dr, 0); |
| 5275 | mRotationWatchers.add(watcher); |
| 5276 | } catch (RemoteException e) { |
| 5277 | // Client died, no cleanup needed. |
| 5278 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5279 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5280 | return mRotation; |
| 5281 | } |
| 5282 | } |
| 5283 | |
| 5284 | /** |
| 5285 | * Starts the view server on the specified port. |
| 5286 | * |
| 5287 | * @param port The port to listener to. |
| 5288 | * |
| 5289 | * @return True if the server was successfully started, false otherwise. |
| 5290 | * |
| 5291 | * @see com.android.server.ViewServer |
| 5292 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 5293 | */ |
| 5294 | public boolean startViewServer(int port) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5295 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5296 | return false; |
| 5297 | } |
| 5298 | |
| 5299 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 5300 | return false; |
| 5301 | } |
| 5302 | |
| 5303 | if (port < 1024) { |
| 5304 | return false; |
| 5305 | } |
| 5306 | |
| 5307 | if (mViewServer != null) { |
| 5308 | if (!mViewServer.isRunning()) { |
| 5309 | try { |
| 5310 | return mViewServer.start(); |
| 5311 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5312 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5313 | } |
| 5314 | } |
| 5315 | return false; |
| 5316 | } |
| 5317 | |
| 5318 | try { |
| 5319 | mViewServer = new ViewServer(this, port); |
| 5320 | return mViewServer.start(); |
| 5321 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5322 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5323 | } |
| 5324 | return false; |
| 5325 | } |
| 5326 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5327 | private boolean isSystemSecure() { |
| 5328 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 5329 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 5330 | } |
| 5331 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5332 | /** |
| 5333 | * Stops the view server if it exists. |
| 5334 | * |
| 5335 | * @return True if the server stopped, false if it wasn't started or |
| 5336 | * couldn't be stopped. |
| 5337 | * |
| 5338 | * @see com.android.server.ViewServer |
| 5339 | */ |
| 5340 | public boolean stopViewServer() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5341 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5342 | return false; |
| 5343 | } |
| 5344 | |
| 5345 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 5346 | return false; |
| 5347 | } |
| 5348 | |
| 5349 | if (mViewServer != null) { |
| 5350 | return mViewServer.stop(); |
| 5351 | } |
| 5352 | return false; |
| 5353 | } |
| 5354 | |
| 5355 | /** |
| 5356 | * Indicates whether the view server is running. |
| 5357 | * |
| 5358 | * @return True if the server is running, false otherwise. |
| 5359 | * |
| 5360 | * @see com.android.server.ViewServer |
| 5361 | */ |
| 5362 | public boolean isViewServerRunning() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5363 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5364 | return false; |
| 5365 | } |
| 5366 | |
| 5367 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 5368 | return false; |
| 5369 | } |
| 5370 | |
| 5371 | return mViewServer != null && mViewServer.isRunning(); |
| 5372 | } |
| 5373 | |
| 5374 | /** |
| 5375 | * Lists all availble windows in the system. The listing is written in the |
| 5376 | * specified Socket's output stream with the following syntax: |
| 5377 | * windowHashCodeInHexadecimal windowName |
| 5378 | * Each line of the ouput represents a different window. |
| 5379 | * |
| 5380 | * @param client The remote client to send the listing to. |
| 5381 | * @return False if an error occured, true otherwise. |
| 5382 | */ |
| 5383 | boolean viewServerListWindows(Socket client) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5384 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5385 | return false; |
| 5386 | } |
| 5387 | |
| 5388 | boolean result = true; |
| 5389 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5390 | WindowState[] windows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5391 | synchronized (mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5392 | //noinspection unchecked |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5393 | windows = mWindows.toArray(new WindowState[mWindows.size()]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5394 | } |
| 5395 | |
| 5396 | BufferedWriter out = null; |
| 5397 | |
| 5398 | // Any uncaught exception will crash the system process |
| 5399 | try { |
| 5400 | OutputStream clientStream = client.getOutputStream(); |
| 5401 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5402 | |
| 5403 | final int count = windows.length; |
| 5404 | for (int i = 0; i < count; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5405 | final WindowState w = windows[i]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5406 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 5407 | out.write(' '); |
| 5408 | out.append(w.mAttrs.getTitle()); |
| 5409 | out.write('\n'); |
| 5410 | } |
| 5411 | |
| 5412 | out.write("DONE.\n"); |
| 5413 | out.flush(); |
| 5414 | } catch (Exception e) { |
| 5415 | result = false; |
| 5416 | } finally { |
| 5417 | if (out != null) { |
| 5418 | try { |
| 5419 | out.close(); |
| 5420 | } catch (IOException e) { |
| 5421 | result = false; |
| 5422 | } |
| 5423 | } |
| 5424 | } |
| 5425 | |
| 5426 | return result; |
| 5427 | } |
| 5428 | |
| 5429 | /** |
Konstantin Lopyrev | f962476 | 2010-07-14 17:02:37 -0700 | [diff] [blame] | 5430 | * Returns the focused window in the following format: |
| 5431 | * windowHashCodeInHexadecimal windowName |
| 5432 | * |
| 5433 | * @param client The remote client to send the listing to. |
| 5434 | * @return False if an error occurred, true otherwise. |
| 5435 | */ |
| 5436 | boolean viewServerGetFocusedWindow(Socket client) { |
| 5437 | if (isSystemSecure()) { |
| 5438 | return false; |
| 5439 | } |
| 5440 | |
| 5441 | boolean result = true; |
| 5442 | |
| 5443 | WindowState focusedWindow = getFocusedWindow(); |
| 5444 | |
| 5445 | BufferedWriter out = null; |
| 5446 | |
| 5447 | // Any uncaught exception will crash the system process |
| 5448 | try { |
| 5449 | OutputStream clientStream = client.getOutputStream(); |
| 5450 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5451 | |
| 5452 | if(focusedWindow != null) { |
| 5453 | out.write(Integer.toHexString(System.identityHashCode(focusedWindow))); |
| 5454 | out.write(' '); |
| 5455 | out.append(focusedWindow.mAttrs.getTitle()); |
| 5456 | } |
| 5457 | out.write('\n'); |
| 5458 | out.flush(); |
| 5459 | } catch (Exception e) { |
| 5460 | result = false; |
| 5461 | } finally { |
| 5462 | if (out != null) { |
| 5463 | try { |
| 5464 | out.close(); |
| 5465 | } catch (IOException e) { |
| 5466 | result = false; |
| 5467 | } |
| 5468 | } |
| 5469 | } |
| 5470 | |
| 5471 | return result; |
| 5472 | } |
| 5473 | |
| 5474 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5475 | * Sends a command to a target window. The result of the command, if any, will be |
| 5476 | * written in the output stream of the specified socket. |
| 5477 | * |
| 5478 | * The parameters must follow this syntax: |
| 5479 | * windowHashcode extra |
| 5480 | * |
| 5481 | * Where XX is the length in characeters of the windowTitle. |
| 5482 | * |
| 5483 | * The first parameter is the target window. The window with the specified hashcode |
| 5484 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 5485 | * will be delivered to the target window and as parameters to the command itself. |
| 5486 | * |
| 5487 | * @param client The remote client to sent the result, if any, to. |
| 5488 | * @param command The command to execute. |
| 5489 | * @param parameters The command parameters. |
| 5490 | * |
| 5491 | * @return True if the command was successfully delivered, false otherwise. This does |
| 5492 | * not indicate whether the command itself was successful. |
| 5493 | */ |
| 5494 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5495 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5496 | return false; |
| 5497 | } |
| 5498 | |
| 5499 | boolean success = true; |
| 5500 | Parcel data = null; |
| 5501 | Parcel reply = null; |
| 5502 | |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5503 | BufferedWriter out = null; |
| 5504 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5505 | // Any uncaught exception will crash the system process |
| 5506 | try { |
| 5507 | // Find the hashcode of the window |
| 5508 | int index = parameters.indexOf(' '); |
| 5509 | if (index == -1) { |
| 5510 | index = parameters.length(); |
| 5511 | } |
| 5512 | final String code = parameters.substring(0, index); |
Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 5513 | int hashCode = (int) Long.parseLong(code, 16); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5514 | |
| 5515 | // Extract the command's parameter after the window description |
| 5516 | if (index < parameters.length()) { |
| 5517 | parameters = parameters.substring(index + 1); |
| 5518 | } else { |
| 5519 | parameters = ""; |
| 5520 | } |
| 5521 | |
| 5522 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 5523 | if (window == null) { |
| 5524 | return false; |
| 5525 | } |
| 5526 | |
| 5527 | data = Parcel.obtain(); |
| 5528 | data.writeInterfaceToken("android.view.IWindow"); |
| 5529 | data.writeString(command); |
| 5530 | data.writeString(parameters); |
| 5531 | data.writeInt(1); |
| 5532 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 5533 | |
| 5534 | reply = Parcel.obtain(); |
| 5535 | |
| 5536 | final IBinder binder = window.mClient.asBinder(); |
| 5537 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 5538 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 5539 | |
| 5540 | reply.readException(); |
| 5541 | |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5542 | if (!client.isOutputShutdown()) { |
| 5543 | out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream())); |
| 5544 | out.write("DONE\n"); |
| 5545 | out.flush(); |
| 5546 | } |
| 5547 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5548 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5549 | 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] | 5550 | success = false; |
| 5551 | } finally { |
| 5552 | if (data != null) { |
| 5553 | data.recycle(); |
| 5554 | } |
| 5555 | if (reply != null) { |
| 5556 | reply.recycle(); |
| 5557 | } |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5558 | if (out != null) { |
| 5559 | try { |
| 5560 | out.close(); |
| 5561 | } catch (IOException e) { |
| 5562 | |
| 5563 | } |
| 5564 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5565 | } |
| 5566 | |
| 5567 | return success; |
| 5568 | } |
| 5569 | |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 5570 | public void addWindowChangeListener(WindowChangeListener listener) { |
| 5571 | synchronized(mWindowMap) { |
| 5572 | mWindowChangeListeners.add(listener); |
| 5573 | } |
| 5574 | } |
| 5575 | |
| 5576 | public void removeWindowChangeListener(WindowChangeListener listener) { |
| 5577 | synchronized(mWindowMap) { |
| 5578 | mWindowChangeListeners.remove(listener); |
| 5579 | } |
| 5580 | } |
| 5581 | |
| 5582 | private void notifyWindowsChanged() { |
| 5583 | WindowChangeListener[] windowChangeListeners; |
| 5584 | synchronized(mWindowMap) { |
| 5585 | if(mWindowChangeListeners.isEmpty()) { |
| 5586 | return; |
| 5587 | } |
| 5588 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5589 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5590 | } |
| 5591 | int N = windowChangeListeners.length; |
| 5592 | for(int i = 0; i < N; i++) { |
| 5593 | windowChangeListeners[i].windowsChanged(); |
| 5594 | } |
| 5595 | } |
| 5596 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 5597 | private void notifyFocusChanged() { |
| 5598 | WindowChangeListener[] windowChangeListeners; |
| 5599 | synchronized(mWindowMap) { |
| 5600 | if(mWindowChangeListeners.isEmpty()) { |
| 5601 | return; |
| 5602 | } |
| 5603 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5604 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5605 | } |
| 5606 | int N = windowChangeListeners.length; |
| 5607 | for(int i = 0; i < N; i++) { |
| 5608 | windowChangeListeners[i].focusChanged(); |
| 5609 | } |
| 5610 | } |
| 5611 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5612 | private WindowState findWindow(int hashCode) { |
| 5613 | if (hashCode == -1) { |
| 5614 | return getFocusedWindow(); |
| 5615 | } |
| 5616 | |
| 5617 | synchronized (mWindowMap) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5618 | final ArrayList<WindowState> windows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5619 | final int count = windows.size(); |
| 5620 | |
| 5621 | for (int i = 0; i < count; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5622 | WindowState w = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5623 | if (System.identityHashCode(w) == hashCode) { |
| 5624 | return w; |
| 5625 | } |
| 5626 | } |
| 5627 | } |
| 5628 | |
| 5629 | return null; |
| 5630 | } |
| 5631 | |
| 5632 | /* |
| 5633 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 5634 | * that to config-changed listeners if appropriate. |
| 5635 | */ |
| 5636 | void sendNewConfiguration() { |
| 5637 | try { |
| 5638 | mActivityManager.updateConfiguration(null); |
| 5639 | } catch (RemoteException e) { |
| 5640 | } |
| 5641 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5642 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5643 | public Configuration computeNewConfiguration() { |
| 5644 | synchronized (mWindowMap) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5645 | Configuration config = computeNewConfigurationLocked(); |
| 5646 | if (config == null && mWaitingForConfig) { |
| 5647 | // Nothing changed but we are waiting for something... stop that! |
| 5648 | mWaitingForConfig = false; |
| 5649 | performLayoutAndPlaceSurfacesLocked(); |
| 5650 | } |
| 5651 | return config; |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5652 | } |
| 5653 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5654 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5655 | Configuration computeNewConfigurationLocked() { |
| 5656 | Configuration config = new Configuration(); |
| 5657 | if (!computeNewConfigurationLocked(config)) { |
| 5658 | return null; |
| 5659 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5660 | return config; |
| 5661 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5662 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5663 | boolean computeNewConfigurationLocked(Configuration config) { |
| 5664 | if (mDisplay == null) { |
| 5665 | return false; |
| 5666 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5667 | |
| 5668 | mInputManager.getInputConfiguration(config); |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 5669 | |
| 5670 | // Use the effective "visual" dimensions based on current rotation |
| 5671 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 5672 | || mRotation == Surface.ROTATION_270); |
| 5673 | final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; |
| 5674 | final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; |
| 5675 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5676 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 5677 | if (dw < dh) { |
| 5678 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 5679 | } else if (dw > dh) { |
| 5680 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 5681 | } |
| 5682 | config.orientation = orientation; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5683 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5684 | DisplayMetrics dm = new DisplayMetrics(); |
| 5685 | mDisplay.getMetrics(dm); |
| 5686 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 5687 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5688 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5689 | // Note we only do this once because at this point we don't |
| 5690 | // expect the screen to change in this way at runtime, and want |
| 5691 | // to avoid all of this computation for every config change. |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5692 | int longSize = dw; |
| 5693 | int shortSize = dh; |
| 5694 | if (longSize < shortSize) { |
| 5695 | int tmp = longSize; |
| 5696 | longSize = shortSize; |
| 5697 | shortSize = tmp; |
| 5698 | } |
| 5699 | longSize = (int)(longSize/dm.density); |
| 5700 | shortSize = (int)(shortSize/dm.density); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5701 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5702 | // These semi-magic numbers define our compatibility modes for |
| 5703 | // applications with different screens. Don't change unless you |
| 5704 | // make sure to test lots and lots of apps! |
| 5705 | if (longSize < 470) { |
| 5706 | // This is shorter than an HVGA normal density screen (which |
| 5707 | // is 480 pixels on its long side). |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5708 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 5709 | | Configuration.SCREENLAYOUT_LONG_NO; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5710 | } else { |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 5711 | // What size is this screen screen? |
| 5712 | if (longSize >= 800 && shortSize >= 600) { |
| 5713 | // SVGA or larger screens at medium density are the point |
| 5714 | // at which we consider it to be an extra large screen. |
| 5715 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE; |
Dianne Hackborn | b51dc0f | 2010-10-21 15:34:47 -0700 | [diff] [blame] | 5716 | } else if (longSize >= 530 && shortSize >= 400) { |
| 5717 | // SVGA or larger screens at high density are the point |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5718 | // at which we consider it to be a large screen. |
| 5719 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 5720 | } else { |
| 5721 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5722 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5723 | // If this screen is wider than normal HVGA, or taller |
| 5724 | // than FWVGA, then for old apps we want to run in size |
| 5725 | // compatibility mode. |
| 5726 | if (shortSize > 321 || longSize > 570) { |
| 5727 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 5728 | } |
| 5729 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5730 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5731 | // Is this a long screen? |
| 5732 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 5733 | // Anything wider than WVGA (5:3) is considering to be long. |
| 5734 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 5735 | } else { |
| 5736 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 5737 | } |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5738 | } |
| 5739 | } |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5740 | config.screenLayout = mScreenLayout; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5741 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5742 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 5743 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 5744 | mPolicy.adjustConfigurationLw(config); |
| 5745 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5746 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5747 | |
| 5748 | // ------------------------------------------------------------- |
| 5749 | // Drag and drop |
| 5750 | // ------------------------------------------------------------- |
| 5751 | |
| 5752 | IBinder prepareDragSurface(IWindow window, SurfaceSession session, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 5753 | int flags, int width, int height, Surface outSurface) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5754 | if (DEBUG_DRAG) { |
| 5755 | Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 5756 | + " flags=" + Integer.toHexString(flags) + " win=" + window |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5757 | + " asbinder=" + window.asBinder()); |
| 5758 | } |
| 5759 | |
| 5760 | final int callerPid = Binder.getCallingPid(); |
| 5761 | final long origId = Binder.clearCallingIdentity(); |
| 5762 | IBinder token = null; |
| 5763 | |
| 5764 | try { |
| 5765 | synchronized (mWindowMap) { |
| 5766 | try { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5767 | if (mDragState == null) { |
| 5768 | Surface surface = new Surface(session, callerPid, "drag surface", 0, |
| 5769 | width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN); |
| 5770 | outSurface.copyFrom(surface); |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 5771 | final IBinder winBinder = window.asBinder(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5772 | token = new Binder(); |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 5773 | // TODO: preserve flags param in DragState |
| 5774 | mDragState = new DragState(token, surface, 0, winBinder); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5775 | mDragState.mSurface = surface; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5776 | token = mDragState.mToken = new Binder(); |
| 5777 | |
| 5778 | // 5 second timeout for this window to actually begin the drag |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 5779 | mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder); |
| 5780 | Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5781 | mH.sendMessageDelayed(msg, 5000); |
| 5782 | } else { |
| 5783 | Slog.w(TAG, "Drag already in progress"); |
| 5784 | } |
| 5785 | } catch (Surface.OutOfResourcesException e) { |
| 5786 | Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e); |
| 5787 | if (mDragState != null) { |
| 5788 | mDragState.reset(); |
| 5789 | mDragState = null; |
| 5790 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5791 | } |
| 5792 | } |
| 5793 | } finally { |
| 5794 | Binder.restoreCallingIdentity(origId); |
| 5795 | } |
| 5796 | |
| 5797 | return token; |
| 5798 | } |
| 5799 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5800 | // ------------------------------------------------------------- |
| 5801 | // Input Events and Focus Management |
| 5802 | // ------------------------------------------------------------- |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5803 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5804 | InputMonitor mInputMonitor = new InputMonitor(); |
| 5805 | |
| 5806 | /* Tracks the progress of input dispatch and ensures that input dispatch state |
| 5807 | * is kept in sync with changes in window focus, visibility, registration, and |
| 5808 | * other relevant Window Manager state transitions. */ |
| 5809 | final class InputMonitor { |
| 5810 | // Current window with input focus for keys and other non-touch events. May be null. |
| 5811 | private WindowState mInputFocus; |
| 5812 | |
| 5813 | // When true, prevents input dispatch from proceeding until set to false again. |
| 5814 | private boolean mInputDispatchFrozen; |
| 5815 | |
| 5816 | // When true, input dispatch proceeds normally. Otherwise all events are dropped. |
| 5817 | private boolean mInputDispatchEnabled = true; |
| 5818 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 5819 | // When true, need to call updateInputWindowsLw(). |
| 5820 | private boolean mUpdateInputWindowsNeeded = true; |
| 5821 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5822 | // Temporary list of windows information to provide to the input dispatcher. |
| 5823 | private InputWindowList mTempInputWindows = new InputWindowList(); |
| 5824 | |
| 5825 | // Temporary input application object to provide to the input dispatcher. |
| 5826 | private InputApplication mTempInputApplication = new InputApplication(); |
| 5827 | |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 5828 | // Set to true when the first input device configuration change notification |
| 5829 | // is received to indicate that the input devices are ready. |
| 5830 | private final Object mInputDevicesReadyMonitor = new Object(); |
| 5831 | private boolean mInputDevicesReady; |
| 5832 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5833 | /* Notifies the window manager about a broken input channel. |
| 5834 | * |
| 5835 | * Called by the InputManager. |
| 5836 | */ |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5837 | public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) { |
| 5838 | if (inputWindowHandle == null) { |
| 5839 | return; |
| 5840 | } |
| 5841 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5842 | synchronized (mWindowMap) { |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5843 | WindowState windowState = (WindowState) inputWindowHandle.windowState; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5844 | Slog.i(TAG, "WINDOW DIED " + windowState); |
| 5845 | removeWindowLocked(windowState.mSession, windowState); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5846 | } |
| 5847 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5848 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5849 | /* Notifies the window manager about an application that is not responding. |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5850 | * 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] | 5851 | * |
| 5852 | * Called by the InputManager. |
| 5853 | */ |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5854 | public long notifyANR(InputApplicationHandle inputApplicationHandle, |
| 5855 | InputWindowHandle inputWindowHandle) { |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5856 | AppWindowToken appWindowToken = null; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5857 | if (inputWindowHandle != null) { |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5858 | synchronized (mWindowMap) { |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5859 | WindowState windowState = (WindowState) inputWindowHandle.windowState; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5860 | if (windowState != null) { |
| 5861 | Slog.i(TAG, "Input event dispatching timed out sending to " |
| 5862 | + windowState.mAttrs.getTitle()); |
| 5863 | appWindowToken = windowState.mAppToken; |
| 5864 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5865 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5866 | } |
| 5867 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5868 | if (appWindowToken == null && inputApplicationHandle != null) { |
| 5869 | appWindowToken = inputApplicationHandle.appWindowToken; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5870 | Slog.i(TAG, "Input event dispatching timed out sending to application " |
| 5871 | + appWindowToken.stringName); |
| 5872 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5873 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5874 | if (appWindowToken != null && appWindowToken.appToken != null) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5875 | try { |
| 5876 | // Notify the activity manager about the timeout and let it decide whether |
| 5877 | // to abort dispatching or keep waiting. |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5878 | boolean abort = appWindowToken.appToken.keyDispatchingTimedOut(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5879 | if (! abort) { |
| 5880 | // The activity manager declined to abort dispatching. |
| 5881 | // Wait a bit longer and timeout again later. |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5882 | return appWindowToken.inputDispatchingTimeoutNanos; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5883 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5884 | } catch (RemoteException ex) { |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5885 | } |
| 5886 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5887 | return 0; // abort dispatching |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5888 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5889 | |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 5890 | private void addDragInputWindowLw(InputWindowList windowList) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5891 | final InputWindow inputWindow = windowList.add(); |
| 5892 | inputWindow.inputChannel = mDragState.mServerChannel; |
| 5893 | inputWindow.name = "drag"; |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 5894 | inputWindow.layoutParamsFlags = WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5895 | inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG; |
| 5896 | inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 5897 | inputWindow.visible = true; |
| 5898 | inputWindow.canReceiveKeys = false; |
| 5899 | inputWindow.hasFocus = true; |
| 5900 | inputWindow.hasWallpaper = false; |
| 5901 | inputWindow.paused = false; |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 5902 | inputWindow.layer = mDragState.getDragLayerLw(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5903 | inputWindow.ownerPid = Process.myPid(); |
| 5904 | inputWindow.ownerUid = Process.myUid(); |
| 5905 | |
| 5906 | // The drag window covers the entire display |
| 5907 | inputWindow.frameLeft = 0; |
| 5908 | inputWindow.frameTop = 0; |
| 5909 | inputWindow.frameRight = mDisplay.getWidth(); |
| 5910 | inputWindow.frameBottom = mDisplay.getHeight(); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 5911 | |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 5912 | // The drag window cannot receive new touches. |
| 5913 | inputWindow.touchableRegion.setEmpty(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5914 | } |
| 5915 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 5916 | public void setUpdateInputWindowsNeededLw() { |
| 5917 | mUpdateInputWindowsNeeded = true; |
| 5918 | } |
| 5919 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5920 | /* Updates the cached window information provided to the input dispatcher. */ |
| 5921 | public void updateInputWindowsLw() { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 5922 | if (!mUpdateInputWindowsNeeded) { |
| 5923 | return; |
| 5924 | } |
| 5925 | mUpdateInputWindowsNeeded = false; |
| 5926 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5927 | // Populate the input window list with information about all of the windows that |
| 5928 | // could potentially receive input. |
| 5929 | // As an optimization, we could try to prune the list of windows but this turns |
| 5930 | // out to be difficult because only the native code knows for sure which window |
| 5931 | // currently has touch focus. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5932 | final ArrayList<WindowState> windows = mWindows; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5933 | |
| 5934 | // If there's a drag in flight, provide a pseudowindow to catch drag input |
| 5935 | final boolean inDrag = (mDragState != null); |
| 5936 | if (inDrag) { |
| 5937 | if (DEBUG_DRAG) { |
| 5938 | Log.d(TAG, "Inserting drag window"); |
| 5939 | } |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 5940 | addDragInputWindowLw(mTempInputWindows); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5941 | } |
| 5942 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5943 | final int N = windows.size(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5944 | for (int i = N - 1; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5945 | final WindowState child = windows.get(i); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5946 | if (child.mInputChannel == null || child.mRemoved) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5947 | // Skip this window because it cannot possibly receive input. |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5948 | continue; |
| 5949 | } |
| 5950 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5951 | final int flags = child.mAttrs.flags; |
| 5952 | final int type = child.mAttrs.type; |
| 5953 | |
| 5954 | final boolean hasFocus = (child == mInputFocus); |
| 5955 | final boolean isVisible = child.isVisibleLw(); |
| 5956 | final boolean hasWallpaper = (child == mWallpaperTarget) |
| 5957 | && (type != WindowManager.LayoutParams.TYPE_KEYGUARD); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5958 | |
| 5959 | // If there's a drag in progress and 'child' is a potential drop target, |
| 5960 | // make sure it's been told about the drag |
| 5961 | if (inDrag && isVisible) { |
| 5962 | mDragState.sendDragStartedIfNeededLw(child); |
| 5963 | } |
| 5964 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5965 | // Add a window to our list of input windows. |
| 5966 | final InputWindow inputWindow = mTempInputWindows.add(); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5967 | inputWindow.inputWindowHandle = child.mInputWindowHandle; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5968 | inputWindow.inputChannel = child.mInputChannel; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5969 | inputWindow.name = child.toString(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5970 | inputWindow.layoutParamsFlags = flags; |
| 5971 | inputWindow.layoutParamsType = type; |
| 5972 | inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos(); |
| 5973 | inputWindow.visible = isVisible; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5974 | inputWindow.canReceiveKeys = child.canReceiveKeys(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5975 | inputWindow.hasFocus = hasFocus; |
| 5976 | inputWindow.hasWallpaper = hasWallpaper; |
| 5977 | inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5978 | inputWindow.layer = child.mLayer; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5979 | inputWindow.ownerPid = child.mSession.mPid; |
| 5980 | inputWindow.ownerUid = child.mSession.mUid; |
| 5981 | |
| 5982 | final Rect frame = child.mFrame; |
| 5983 | inputWindow.frameLeft = frame.left; |
| 5984 | inputWindow.frameTop = frame.top; |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5985 | inputWindow.frameRight = frame.right; |
| 5986 | inputWindow.frameBottom = frame.bottom; |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 5987 | |
| 5988 | child.getTouchableRegion(inputWindow.touchableRegion); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5989 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5990 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5991 | // Send windows to native code. |
| 5992 | mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray()); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5993 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5994 | // Clear the list in preparation for the next round. |
| 5995 | // Also avoids keeping InputChannel objects referenced unnecessarily. |
| 5996 | mTempInputWindows.clear(); |
| 5997 | } |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 5998 | |
| 5999 | /* Notifies that the input device configuration has changed. */ |
| 6000 | public void notifyConfigurationChanged() { |
| 6001 | sendNewConfiguration(); |
| 6002 | |
| 6003 | synchronized (mInputDevicesReadyMonitor) { |
| 6004 | if (!mInputDevicesReady) { |
| 6005 | mInputDevicesReady = true; |
| 6006 | mInputDevicesReadyMonitor.notifyAll(); |
| 6007 | } |
| 6008 | } |
| 6009 | } |
| 6010 | |
| 6011 | /* Waits until the built-in input devices have been configured. */ |
| 6012 | public boolean waitForInputDevicesReady(long timeoutMillis) { |
| 6013 | synchronized (mInputDevicesReadyMonitor) { |
| 6014 | if (!mInputDevicesReady) { |
| 6015 | try { |
| 6016 | mInputDevicesReadyMonitor.wait(timeoutMillis); |
| 6017 | } catch (InterruptedException ex) { |
| 6018 | } |
| 6019 | } |
| 6020 | return mInputDevicesReady; |
| 6021 | } |
| 6022 | } |
| 6023 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6024 | /* Notifies that the lid switch changed state. */ |
| 6025 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 6026 | mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen); |
| 6027 | } |
| 6028 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6029 | /* Provides an opportunity for the window manager policy to intercept early key |
| 6030 | * processing as soon as the key has been read from the device. */ |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 6031 | public int interceptKeyBeforeQueueing( |
| 6032 | KeyEvent event, int policyFlags, boolean isScreenOn) { |
| 6033 | return mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6034 | } |
| 6035 | |
| 6036 | /* Provides an opportunity for the window manager policy to process a key before |
| 6037 | * ordinary dispatch. */ |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 6038 | public boolean interceptKeyBeforeDispatching( |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6039 | InputWindowHandle focus, KeyEvent event, int policyFlags) { |
Jeff Brown | 00ae87d | 2011-01-13 19:58:24 -0800 | [diff] [blame] | 6040 | WindowState windowState = focus != null ? (WindowState) focus.windowState : null; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 6041 | return mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6042 | } |
| 6043 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 6044 | /* Provides an opportunity for the window manager policy to process a key that |
| 6045 | * the application did not handle. */ |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 6046 | public KeyEvent dispatchUnhandledKey( |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6047 | InputWindowHandle focus, KeyEvent event, int policyFlags) { |
Jeff Brown | 00ae87d | 2011-01-13 19:58:24 -0800 | [diff] [blame] | 6048 | WindowState windowState = focus != null ? (WindowState) focus.windowState : null; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 6049 | return mPolicy.dispatchUnhandledKey(windowState, event, policyFlags); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 6050 | } |
| 6051 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6052 | /* Called when the current input focus changes. |
| 6053 | * Layer assignment is assumed to be complete by the time this is called. |
| 6054 | */ |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 6055 | public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6056 | if (DEBUG_INPUT) { |
| 6057 | Slog.d(TAG, "Input focus has changed to " + newWindow); |
| 6058 | } |
| 6059 | |
| 6060 | if (newWindow != mInputFocus) { |
| 6061 | if (newWindow != null && newWindow.canReceiveKeys()) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6062 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 6063 | // This is to protect against bugs if someone pauses dispatching but |
| 6064 | // forgets to resume. |
| 6065 | newWindow.mToken.paused = false; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6066 | } |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 6067 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6068 | mInputFocus = newWindow; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 6069 | setUpdateInputWindowsNeededLw(); |
| 6070 | |
| 6071 | if (updateInputWindows) { |
| 6072 | updateInputWindowsLw(); |
| 6073 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6074 | } |
| 6075 | } |
| 6076 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6077 | public void setFocusedAppLw(AppWindowToken newApp) { |
| 6078 | // Focused app has changed. |
| 6079 | if (newApp == null) { |
| 6080 | mInputManager.setFocusedApplication(null); |
| 6081 | } else { |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6082 | mTempInputApplication.inputApplicationHandle = newApp.mInputApplicationHandle; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6083 | mTempInputApplication.name = newApp.toString(); |
| 6084 | mTempInputApplication.dispatchingTimeoutNanos = |
| 6085 | newApp.inputDispatchingTimeoutNanos; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6086 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6087 | mInputManager.setFocusedApplication(mTempInputApplication); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6088 | |
| 6089 | mTempInputApplication.recycle(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6090 | } |
| 6091 | } |
| 6092 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6093 | public void pauseDispatchingLw(WindowToken window) { |
| 6094 | if (! window.paused) { |
| 6095 | if (DEBUG_INPUT) { |
| 6096 | Slog.v(TAG, "Pausing WindowToken " + window); |
| 6097 | } |
| 6098 | |
| 6099 | window.paused = true; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 6100 | setUpdateInputWindowsNeededLw(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6101 | updateInputWindowsLw(); |
| 6102 | } |
| 6103 | } |
| 6104 | |
| 6105 | public void resumeDispatchingLw(WindowToken window) { |
| 6106 | if (window.paused) { |
| 6107 | if (DEBUG_INPUT) { |
| 6108 | Slog.v(TAG, "Resuming WindowToken " + window); |
| 6109 | } |
| 6110 | |
| 6111 | window.paused = false; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 6112 | setUpdateInputWindowsNeededLw(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6113 | updateInputWindowsLw(); |
| 6114 | } |
| 6115 | } |
| 6116 | |
| 6117 | public void freezeInputDispatchingLw() { |
| 6118 | if (! mInputDispatchFrozen) { |
| 6119 | if (DEBUG_INPUT) { |
| 6120 | Slog.v(TAG, "Freezing input dispatching"); |
| 6121 | } |
| 6122 | |
| 6123 | mInputDispatchFrozen = true; |
| 6124 | updateInputDispatchModeLw(); |
| 6125 | } |
| 6126 | } |
| 6127 | |
| 6128 | public void thawInputDispatchingLw() { |
| 6129 | if (mInputDispatchFrozen) { |
| 6130 | if (DEBUG_INPUT) { |
| 6131 | Slog.v(TAG, "Thawing input dispatching"); |
| 6132 | } |
| 6133 | |
| 6134 | mInputDispatchFrozen = false; |
| 6135 | updateInputDispatchModeLw(); |
| 6136 | } |
| 6137 | } |
| 6138 | |
| 6139 | public void setEventDispatchingLw(boolean enabled) { |
| 6140 | if (mInputDispatchEnabled != enabled) { |
| 6141 | if (DEBUG_INPUT) { |
| 6142 | Slog.v(TAG, "Setting event dispatching to " + enabled); |
| 6143 | } |
| 6144 | |
| 6145 | mInputDispatchEnabled = enabled; |
| 6146 | updateInputDispatchModeLw(); |
| 6147 | } |
| 6148 | } |
| 6149 | |
| 6150 | private void updateInputDispatchModeLw() { |
| 6151 | mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen); |
| 6152 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6153 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6154 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6155 | public void pauseKeyDispatching(IBinder _token) { |
| 6156 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 6157 | "pauseKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6158 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6159 | } |
| 6160 | |
| 6161 | synchronized (mWindowMap) { |
| 6162 | WindowToken token = mTokenMap.get(_token); |
| 6163 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6164 | mInputMonitor.pauseDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6165 | } |
| 6166 | } |
| 6167 | } |
| 6168 | |
| 6169 | public void resumeKeyDispatching(IBinder _token) { |
| 6170 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 6171 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6172 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6173 | } |
| 6174 | |
| 6175 | synchronized (mWindowMap) { |
| 6176 | WindowToken token = mTokenMap.get(_token); |
| 6177 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6178 | mInputMonitor.resumeDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6179 | } |
| 6180 | } |
| 6181 | } |
| 6182 | |
| 6183 | public void setEventDispatching(boolean enabled) { |
| 6184 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 6185 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6186 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6187 | } |
| 6188 | |
| 6189 | synchronized (mWindowMap) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6190 | mInputMonitor.setEventDispatchingLw(enabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6191 | } |
| 6192 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6193 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6194 | /** |
| 6195 | * Injects a keystroke event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6196 | * Even when sync is false, this method may block while waiting for current |
| 6197 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6198 | * |
| 6199 | * @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] | 6200 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 6201 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 6202 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6203 | */ |
| 6204 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 6205 | long downTime = ev.getDownTime(); |
| 6206 | long eventTime = ev.getEventTime(); |
| 6207 | |
| 6208 | int action = ev.getAction(); |
| 6209 | int code = ev.getKeyCode(); |
| 6210 | int repeatCount = ev.getRepeatCount(); |
| 6211 | int metaState = ev.getMetaState(); |
| 6212 | int deviceId = ev.getDeviceId(); |
| 6213 | int scancode = ev.getScanCode(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6214 | int source = ev.getSource(); |
Mike Playle | c6ded10 | 2010-11-29 16:01:03 +0000 | [diff] [blame] | 6215 | int flags = ev.getFlags(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6216 | |
| 6217 | if (source == InputDevice.SOURCE_UNKNOWN) { |
| 6218 | source = InputDevice.SOURCE_KEYBOARD; |
| 6219 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6220 | |
| 6221 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 6222 | if (downTime == 0) downTime = eventTime; |
| 6223 | |
| 6224 | KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, |
Jean-Baptiste Queru | 4a88013 | 2010-12-02 15:16:53 -0800 | [diff] [blame] | 6225 | deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6226 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6227 | final int pid = Binder.getCallingPid(); |
| 6228 | final int uid = Binder.getCallingUid(); |
| 6229 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6230 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6231 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 6232 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 6233 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 6234 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6235 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6236 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6237 | return reportInjectionResult(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6238 | } |
| 6239 | |
| 6240 | /** |
| 6241 | * Inject a pointer (touch) event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6242 | * Even when sync is false, this method may block while waiting for current |
| 6243 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6244 | * |
| 6245 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 6246 | * {@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] | 6247 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 6248 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 6249 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6250 | */ |
| 6251 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6252 | final int pid = Binder.getCallingPid(); |
| 6253 | final int uid = Binder.getCallingUid(); |
| 6254 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6255 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6256 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 6257 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) { |
| 6258 | newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 6259 | } |
| 6260 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6261 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 6262 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 6263 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 6264 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6265 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6266 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6267 | return reportInjectionResult(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6268 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6269 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6270 | /** |
| 6271 | * Inject a trackball (navigation device) event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6272 | * Even when sync is false, this method may block while waiting for current |
| 6273 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6274 | * |
| 6275 | * @param ev A motion event describing the trackball action. (As noted in |
| 6276 | * {@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] | 6277 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 6278 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 6279 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6280 | */ |
| 6281 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6282 | final int pid = Binder.getCallingPid(); |
| 6283 | final int uid = Binder.getCallingUid(); |
| 6284 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6285 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6286 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 6287 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) { |
| 6288 | newEvent.setSource(InputDevice.SOURCE_TRACKBALL); |
| 6289 | } |
| 6290 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6291 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 6292 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 6293 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 6294 | INJECTION_TIMEOUT_MILLIS); |
| 6295 | |
| 6296 | Binder.restoreCallingIdentity(ident); |
| 6297 | return reportInjectionResult(result); |
| 6298 | } |
| 6299 | |
| 6300 | /** |
| 6301 | * Inject an input event into the UI without waiting for dispatch to commence. |
| 6302 | * This variant is useful for fire-and-forget input event injection. It does not |
| 6303 | * block any longer than it takes to enqueue the input event. |
| 6304 | * |
| 6305 | * @param ev An input event. (Be sure to set the input source correctly.) |
| 6306 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6307 | */ |
| 6308 | public boolean injectInputEventNoWait(InputEvent ev) { |
| 6309 | final int pid = Binder.getCallingPid(); |
| 6310 | final int uid = Binder.getCallingUid(); |
| 6311 | final long ident = Binder.clearCallingIdentity(); |
| 6312 | |
| 6313 | final int result = mInputManager.injectInputEvent(ev, pid, uid, |
| 6314 | InputManager.INPUT_EVENT_INJECTION_SYNC_NONE, |
| 6315 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6316 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6317 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6318 | return reportInjectionResult(result); |
| 6319 | } |
| 6320 | |
| 6321 | private boolean reportInjectionResult(int result) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6322 | switch (result) { |
| 6323 | case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED: |
| 6324 | Slog.w(TAG, "Input event injection permission denied."); |
| 6325 | throw new SecurityException( |
| 6326 | "Injecting to another application requires INJECT_EVENTS permission"); |
| 6327 | case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED: |
Christopher Tate | 09e85dc | 2010-08-02 11:54:41 -0700 | [diff] [blame] | 6328 | //Slog.v(TAG, "Input event injection succeeded."); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6329 | return true; |
| 6330 | case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT: |
| 6331 | Slog.w(TAG, "Input event injection timed out."); |
| 6332 | return false; |
| 6333 | case InputManager.INPUT_EVENT_INJECTION_FAILED: |
| 6334 | default: |
| 6335 | Slog.w(TAG, "Input event injection failed."); |
| 6336 | return false; |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6337 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6338 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6339 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6340 | private WindowState getFocusedWindow() { |
| 6341 | synchronized (mWindowMap) { |
| 6342 | return getFocusedWindowLocked(); |
| 6343 | } |
| 6344 | } |
| 6345 | |
| 6346 | private WindowState getFocusedWindowLocked() { |
| 6347 | return mCurrentFocus; |
| 6348 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6349 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6350 | public boolean detectSafeMode() { |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 6351 | if (!mInputMonitor.waitForInputDevicesReady( |
| 6352 | INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) { |
| 6353 | Slog.w(TAG, "Devices still not ready after waiting " |
| 6354 | + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS |
| 6355 | + " milliseconds before attempting to detect safe mode."); |
| 6356 | } |
| 6357 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6358 | mSafeMode = mPolicy.detectSafeMode(); |
| 6359 | return mSafeMode; |
| 6360 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6361 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6362 | public void systemReady() { |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6363 | synchronized(mWindowMap) { |
| 6364 | if (mDisplay != null) { |
| 6365 | throw new IllegalStateException("Display already initialized"); |
| 6366 | } |
| 6367 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 6368 | mDisplay = wm.getDefaultDisplay(); |
| 6369 | mInitialDisplayWidth = mDisplay.getWidth(); |
| 6370 | mInitialDisplayHeight = mDisplay.getHeight(); |
Dianne Hackborn | 4c7cc34 | 2010-12-16 16:37:39 -0800 | [diff] [blame] | 6371 | mInputManager.setDisplaySize(0, Display.unmapDisplaySize(mInitialDisplayWidth), |
| 6372 | Display.unmapDisplaySize(mInitialDisplayHeight)); |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6373 | } |
| 6374 | |
| 6375 | try { |
| 6376 | mActivityManager.updateConfiguration(null); |
| 6377 | } catch (RemoteException e) { |
| 6378 | } |
Dianne Hackborn | 154db5f | 2010-07-29 19:15:19 -0700 | [diff] [blame] | 6379 | |
| 6380 | mPolicy.systemReady(); |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6381 | } |
| 6382 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6383 | // ------------------------------------------------------------- |
| 6384 | // Client Session State |
| 6385 | // ------------------------------------------------------------- |
| 6386 | |
| 6387 | private final class Session extends IWindowSession.Stub |
| 6388 | implements IBinder.DeathRecipient { |
| 6389 | final IInputMethodClient mClient; |
| 6390 | final IInputContext mInputContext; |
| 6391 | final int mUid; |
| 6392 | final int mPid; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6393 | final String mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6394 | SurfaceSession mSurfaceSession; |
| 6395 | int mNumWindow = 0; |
| 6396 | boolean mClientDead = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6397 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6398 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 6399 | mClient = client; |
| 6400 | mInputContext = inputContext; |
| 6401 | mUid = Binder.getCallingUid(); |
| 6402 | mPid = Binder.getCallingPid(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6403 | StringBuilder sb = new StringBuilder(); |
| 6404 | sb.append("Session{"); |
| 6405 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 6406 | sb.append(" uid "); |
| 6407 | sb.append(mUid); |
| 6408 | sb.append("}"); |
| 6409 | mStringName = sb.toString(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6410 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6411 | synchronized (mWindowMap) { |
| 6412 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 6413 | IBinder b = ServiceManager.getService( |
| 6414 | Context.INPUT_METHOD_SERVICE); |
| 6415 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 6416 | } |
| 6417 | } |
| 6418 | long ident = Binder.clearCallingIdentity(); |
| 6419 | try { |
| 6420 | // Note: it is safe to call in to the input method manager |
| 6421 | // here because we are not holding our lock. |
| 6422 | if (mInputMethodManager != null) { |
| 6423 | mInputMethodManager.addClient(client, inputContext, |
| 6424 | mUid, mPid); |
| 6425 | } else { |
| 6426 | client.setUsingInputMethod(false); |
| 6427 | } |
| 6428 | client.asBinder().linkToDeath(this, 0); |
| 6429 | } catch (RemoteException e) { |
| 6430 | // The caller has died, so we can just forget about this. |
| 6431 | try { |
| 6432 | if (mInputMethodManager != null) { |
| 6433 | mInputMethodManager.removeClient(client); |
| 6434 | } |
| 6435 | } catch (RemoteException ee) { |
| 6436 | } |
| 6437 | } finally { |
| 6438 | Binder.restoreCallingIdentity(ident); |
| 6439 | } |
| 6440 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6441 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6442 | @Override |
| 6443 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 6444 | throws RemoteException { |
| 6445 | try { |
| 6446 | return super.onTransact(code, data, reply, flags); |
| 6447 | } catch (RuntimeException e) { |
| 6448 | // Log all 'real' exceptions thrown to the caller |
| 6449 | if (!(e instanceof SecurityException)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6450 | Slog.e(TAG, "Window Session Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6451 | } |
| 6452 | throw e; |
| 6453 | } |
| 6454 | } |
| 6455 | |
| 6456 | public void binderDied() { |
| 6457 | // Note: it is safe to call in to the input method manager |
| 6458 | // here because we are not holding our lock. |
| 6459 | try { |
| 6460 | if (mInputMethodManager != null) { |
| 6461 | mInputMethodManager.removeClient(mClient); |
| 6462 | } |
| 6463 | } catch (RemoteException e) { |
| 6464 | } |
| 6465 | synchronized(mWindowMap) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 6466 | mClient.asBinder().unlinkToDeath(this, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6467 | mClientDead = true; |
| 6468 | killSessionLocked(); |
| 6469 | } |
| 6470 | } |
| 6471 | |
| 6472 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6473 | int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) { |
| 6474 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, |
| 6475 | outInputChannel); |
| 6476 | } |
| 6477 | |
| 6478 | public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6479 | int viewVisibility, Rect outContentInsets) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6480 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6481 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6482 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6483 | public void remove(IWindow window) { |
| 6484 | removeWindow(this, window); |
| 6485 | } |
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 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 6488 | int requestedWidth, int requestedHeight, int viewFlags, |
| 6489 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6490 | Rect outVisibleInsets, Configuration outConfig, Surface outSurface) { |
Dianne Hackborn | f123e49 | 2010-09-24 11:16:23 -0700 | [diff] [blame] | 6491 | //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid()); |
| 6492 | int res = relayoutWindow(this, window, attrs, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6493 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6494 | outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface); |
Dianne Hackborn | f123e49 | 2010-09-24 11:16:23 -0700 | [diff] [blame] | 6495 | //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid()); |
| 6496 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6497 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6498 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6499 | public void setTransparentRegion(IWindow window, Region region) { |
| 6500 | setTransparentRegionWindow(this, window, region); |
| 6501 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6502 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6503 | public void setInsets(IWindow window, int touchableInsets, |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 6504 | Rect contentInsets, Rect visibleInsets, Region touchableArea) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6505 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 6506 | visibleInsets, touchableArea); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6507 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6508 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6509 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 6510 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 6511 | } |
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 | public void finishDrawing(IWindow window) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6514 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6515 | TAG, "IWindow finishDrawing called for " + window); |
| 6516 | finishDrawingWindow(this, window); |
| 6517 | } |
| 6518 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6519 | public void setInTouchMode(boolean mode) { |
| 6520 | synchronized(mWindowMap) { |
| 6521 | mInTouchMode = mode; |
| 6522 | } |
| 6523 | } |
| 6524 | |
| 6525 | public boolean getInTouchMode() { |
| 6526 | synchronized(mWindowMap) { |
| 6527 | return mInTouchMode; |
| 6528 | } |
| 6529 | } |
| 6530 | |
| 6531 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 6532 | boolean always) { |
| 6533 | synchronized(mWindowMap) { |
| 6534 | long ident = Binder.clearCallingIdentity(); |
| 6535 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6536 | return mPolicy.performHapticFeedbackLw( |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6537 | windowForClientLocked(this, window, true), |
| 6538 | effectId, always); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6539 | } finally { |
| 6540 | Binder.restoreCallingIdentity(ident); |
| 6541 | } |
| 6542 | } |
| 6543 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6544 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6545 | /* Drag/drop */ |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 6546 | public IBinder prepareDrag(IWindow window, int flags, |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6547 | int width, int height, Surface outSurface) { |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 6548 | return prepareDragSurface(window, mSurfaceSession, flags, |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6549 | width, height, outSurface); |
| 6550 | } |
| 6551 | |
| 6552 | public boolean performDrag(IWindow window, IBinder dragToken, |
| 6553 | float touchX, float touchY, float thumbCenterX, float thumbCenterY, |
| 6554 | ClipData data) { |
| 6555 | if (DEBUG_DRAG) { |
| 6556 | Slog.d(TAG, "perform drag: win=" + window + " data=" + data); |
| 6557 | } |
| 6558 | |
| 6559 | synchronized (mWindowMap) { |
| 6560 | if (mDragState == null) { |
| 6561 | Slog.w(TAG, "No drag prepared"); |
| 6562 | throw new IllegalStateException("performDrag() without prepareDrag()"); |
| 6563 | } |
| 6564 | |
| 6565 | if (dragToken != mDragState.mToken) { |
| 6566 | Slog.w(TAG, "Performing mismatched drag"); |
| 6567 | throw new IllegalStateException("performDrag() does not match prepareDrag()"); |
| 6568 | } |
| 6569 | |
| 6570 | WindowState callingWin = windowForClientLocked(null, window, false); |
| 6571 | if (callingWin == null) { |
| 6572 | Slog.w(TAG, "Bad requesting window " + window); |
| 6573 | return false; // !!! TODO: throw here? |
| 6574 | } |
| 6575 | |
| 6576 | // !!! TODO: if input is not still focused on the initiating window, fail |
| 6577 | // the drag initiation (e.g. an alarm window popped up just as the application |
| 6578 | // called performDrag() |
| 6579 | |
| 6580 | mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder()); |
| 6581 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 6582 | // !!! TODO: extract the current touch (x, y) in screen coordinates. That |
| 6583 | // will let us eliminate the (touchX,touchY) parameters from the API. |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6584 | |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6585 | // !!! FIXME: put all this heavy stuff onto the mH looper, as well as |
| 6586 | // the actual drag event dispatch stuff in the dragstate |
| 6587 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6588 | mDragState.register(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 6589 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6590 | mInputMonitor.updateInputWindowsLw(); |
Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 6591 | if (!mInputManager.transferTouchFocus(callingWin.mInputChannel, |
| 6592 | mDragState.mServerChannel)) { |
| 6593 | Slog.e(TAG, "Unable to transfer touch focus"); |
| 6594 | mDragState.unregister(); |
| 6595 | mDragState = null; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 6596 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 6597 | mInputMonitor.updateInputWindowsLw(); |
| 6598 | return false; |
| 6599 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6600 | |
| 6601 | mDragState.mData = data; |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6602 | mDragState.mCurrentX = touchX; |
| 6603 | mDragState.mCurrentY = touchY; |
Chris Tate | b8203e9 | 2010-10-12 14:23:21 -0700 | [diff] [blame] | 6604 | mDragState.broadcastDragStartedLw(touchX, touchY); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6605 | |
| 6606 | // remember the thumb offsets for later |
| 6607 | mDragState.mThumbOffsetX = thumbCenterX; |
| 6608 | mDragState.mThumbOffsetY = thumbCenterY; |
| 6609 | |
| 6610 | // Make the surface visible at the proper location |
| 6611 | final Surface surface = mDragState.mSurface; |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 6612 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performDrag"); |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6613 | Surface.openTransaction(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6614 | try { |
| 6615 | surface.setPosition((int)(touchX - thumbCenterX), |
| 6616 | (int)(touchY - thumbCenterY)); |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6617 | surface.setAlpha(.7071f); |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 6618 | surface.setLayer(mDragState.getDragLayerLw()); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6619 | surface.show(); |
| 6620 | } finally { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6621 | Surface.closeTransaction(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 6622 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performDrag"); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6623 | } |
| 6624 | } |
| 6625 | |
| 6626 | return true; // success! |
| 6627 | } |
| 6628 | |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6629 | public void reportDropResult(IWindow window, boolean consumed) { |
| 6630 | IBinder token = window.asBinder(); |
| 6631 | if (DEBUG_DRAG) { |
| 6632 | Slog.d(TAG, "Drop result=" + consumed + " reported by " + token); |
| 6633 | } |
| 6634 | |
| 6635 | synchronized (mWindowMap) { |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 6636 | long ident = Binder.clearCallingIdentity(); |
| 6637 | try { |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 6638 | if (mDragState == null || mDragState.mToken != token) { |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 6639 | Slog.w(TAG, "Invalid drop-result claim by " + window); |
| 6640 | throw new IllegalStateException("reportDropResult() by non-recipient"); |
| 6641 | } |
| 6642 | |
| 6643 | // The right window has responded, even if it's no longer around, |
| 6644 | // so be sure to halt the timeout even if the later WindowState |
| 6645 | // lookup fails. |
| 6646 | mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder()); |
| 6647 | WindowState callingWin = windowForClientLocked(null, window, false); |
| 6648 | if (callingWin == null) { |
| 6649 | Slog.w(TAG, "Bad result-reporting window " + window); |
| 6650 | return; // !!! TODO: throw here? |
| 6651 | } |
| 6652 | |
| 6653 | mDragState.mDragResult = consumed; |
| 6654 | mDragState.endDragLw(); |
| 6655 | } finally { |
| 6656 | Binder.restoreCallingIdentity(ident); |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6657 | } |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6658 | } |
| 6659 | } |
| 6660 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6661 | public void dragRecipientEntered(IWindow window) { |
| 6662 | if (DEBUG_DRAG) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6663 | Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder()); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6664 | } |
| 6665 | } |
| 6666 | |
| 6667 | public void dragRecipientExited(IWindow window) { |
| 6668 | if (DEBUG_DRAG) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6669 | Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder()); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6670 | } |
| 6671 | } |
| 6672 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6673 | 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] | 6674 | synchronized(mWindowMap) { |
| 6675 | long ident = Binder.clearCallingIdentity(); |
| 6676 | try { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6677 | setWindowWallpaperPositionLocked( |
| 6678 | windowForClientLocked(this, window, true), |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6679 | x, y, xStep, yStep); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6680 | } finally { |
| 6681 | Binder.restoreCallingIdentity(ident); |
| 6682 | } |
| 6683 | } |
| 6684 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6685 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6686 | public void wallpaperOffsetsComplete(IBinder window) { |
| 6687 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 6688 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6689 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6690 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 6691 | int z, Bundle extras, boolean sync) { |
| 6692 | synchronized(mWindowMap) { |
| 6693 | long ident = Binder.clearCallingIdentity(); |
| 6694 | try { |
| 6695 | return sendWindowWallpaperCommandLocked( |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6696 | windowForClientLocked(this, window, true), |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6697 | action, x, y, z, extras, sync); |
| 6698 | } finally { |
| 6699 | Binder.restoreCallingIdentity(ident); |
| 6700 | } |
| 6701 | } |
| 6702 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6703 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6704 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 6705 | WindowManagerService.this.wallpaperCommandComplete(window, result); |
| 6706 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6707 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6708 | void windowAddedLocked() { |
| 6709 | if (mSurfaceSession == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6710 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6711 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 6712 | mSurfaceSession = new SurfaceSession(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6713 | if (SHOW_TRANSACTIONS) Slog.i( |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6714 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6715 | mSessions.add(this); |
| 6716 | } |
| 6717 | mNumWindow++; |
| 6718 | } |
| 6719 | |
| 6720 | void windowRemovedLocked() { |
| 6721 | mNumWindow--; |
| 6722 | killSessionLocked(); |
| 6723 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6724 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6725 | void killSessionLocked() { |
| 6726 | if (mNumWindow <= 0 && mClientDead) { |
| 6727 | mSessions.remove(this); |
| 6728 | if (mSurfaceSession != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6729 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6730 | TAG, "Last window removed from " + this |
| 6731 | + ", destroying " + mSurfaceSession); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6732 | if (SHOW_TRANSACTIONS) Slog.i( |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6733 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6734 | try { |
| 6735 | mSurfaceSession.kill(); |
| 6736 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6737 | Slog.w(TAG, "Exception thrown when killing surface session " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6738 | + mSurfaceSession + " in session " + this |
| 6739 | + ": " + e.toString()); |
| 6740 | } |
| 6741 | mSurfaceSession = null; |
| 6742 | } |
| 6743 | } |
| 6744 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6745 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6746 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6747 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 6748 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 6749 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6750 | } |
| 6751 | |
| 6752 | @Override |
| 6753 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6754 | return mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6755 | } |
| 6756 | } |
| 6757 | |
| 6758 | // ------------------------------------------------------------- |
| 6759 | // Client Window State |
| 6760 | // ------------------------------------------------------------- |
| 6761 | |
| 6762 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 6763 | final Session mSession; |
| 6764 | final IWindow mClient; |
| 6765 | WindowToken mToken; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6766 | WindowToken mRootToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6767 | AppWindowToken mAppToken; |
| 6768 | AppWindowToken mTargetAppToken; |
| 6769 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 6770 | final DeathRecipient mDeathRecipient; |
| 6771 | final WindowState mAttachedWindow; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6772 | final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6773 | final int mBaseLayer; |
| 6774 | final int mSubLayer; |
| 6775 | final boolean mLayoutAttached; |
| 6776 | final boolean mIsImWindow; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6777 | final boolean mIsWallpaper; |
| 6778 | final boolean mIsFloatingLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6779 | int mViewVisibility; |
| 6780 | boolean mPolicyVisibility = true; |
| 6781 | boolean mPolicyVisibilityAfterAnim = true; |
| 6782 | boolean mAppFreezing; |
| 6783 | Surface mSurface; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6784 | boolean mReportDestroySurface; |
| 6785 | boolean mSurfacePendingDestroy; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6786 | boolean mAttachedHidden; // is our parent window hidden? |
| 6787 | boolean mLastHidden; // was this window last hidden? |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6788 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6789 | int mRequestedWidth; |
| 6790 | int mRequestedHeight; |
| 6791 | int mLastRequestedWidth; |
| 6792 | int mLastRequestedHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6793 | int mLayer; |
| 6794 | int mAnimLayer; |
| 6795 | int mLastLayer; |
| 6796 | boolean mHaveFrame; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6797 | boolean mObscured; |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 6798 | boolean mTurnOnScreen; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6799 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6800 | int mLayoutSeq = -1; |
| 6801 | |
| 6802 | Configuration mConfiguration = null; |
| 6803 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6804 | // Actual frame shown on-screen (may be modified by animation) |
| 6805 | final Rect mShownFrame = new Rect(); |
| 6806 | final Rect mLastShownFrame = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6807 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6808 | /** |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 6809 | * Set when we have changed the size of the surface, to know that |
| 6810 | * we must tell them application to resize (and thus redraw itself). |
| 6811 | */ |
| 6812 | boolean mSurfaceResized; |
| 6813 | |
| 6814 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6815 | * Insets that determine the actually visible area |
| 6816 | */ |
| 6817 | final Rect mVisibleInsets = new Rect(); |
| 6818 | final Rect mLastVisibleInsets = new Rect(); |
| 6819 | boolean mVisibleInsetsChanged; |
| 6820 | |
| 6821 | /** |
| 6822 | * Insets that are covered by system windows |
| 6823 | */ |
| 6824 | final Rect mContentInsets = new Rect(); |
| 6825 | final Rect mLastContentInsets = new Rect(); |
| 6826 | boolean mContentInsetsChanged; |
| 6827 | |
| 6828 | /** |
| 6829 | * Set to true if we are waiting for this window to receive its |
| 6830 | * given internal insets before laying out other windows based on it. |
| 6831 | */ |
| 6832 | boolean mGivenInsetsPending; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6833 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6834 | /** |
| 6835 | * These are the content insets that were given during layout for |
| 6836 | * this window, to be applied to windows behind it. |
| 6837 | */ |
| 6838 | final Rect mGivenContentInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6839 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6840 | /** |
| 6841 | * These are the visible insets that were given during layout for |
| 6842 | * this window, to be applied to windows behind it. |
| 6843 | */ |
| 6844 | final Rect mGivenVisibleInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6845 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6846 | /** |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 6847 | * This is the given touchable area relative to the window frame, or null if none. |
| 6848 | */ |
| 6849 | final Region mGivenTouchableRegion = new Region(); |
| 6850 | |
| 6851 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6852 | * Flag indicating whether the touchable region should be adjusted by |
| 6853 | * the visible insets; if false the area outside the visible insets is |
| 6854 | * NOT touchable, so we must use those to adjust the frame during hit |
| 6855 | * tests. |
| 6856 | */ |
| 6857 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6858 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6859 | // Current transformation being applied. |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 6860 | boolean mHaveMatrix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6861 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 6862 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 6863 | float mHScale=1, mVScale=1; |
| 6864 | float mLastHScale=1, mLastVScale=1; |
| 6865 | final Matrix mTmpMatrix = new Matrix(); |
| 6866 | |
| 6867 | // "Real" frame that the application sees. |
| 6868 | final Rect mFrame = new Rect(); |
| 6869 | final Rect mLastFrame = new Rect(); |
| 6870 | |
| 6871 | final Rect mContainingFrame = new Rect(); |
| 6872 | final Rect mDisplayFrame = new Rect(); |
| 6873 | final Rect mContentFrame = new Rect(); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 6874 | final Rect mParentFrame = new Rect(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6875 | final Rect mVisibleFrame = new Rect(); |
| 6876 | |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6877 | boolean mContentChanged; |
| 6878 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6879 | float mShownAlpha = 1; |
| 6880 | float mAlpha = 1; |
| 6881 | float mLastAlpha = 1; |
| 6882 | |
| 6883 | // Set to true if, when the window gets displayed, it should perform |
| 6884 | // an enter animation. |
| 6885 | boolean mEnterAnimationPending; |
| 6886 | |
| 6887 | // Currently running animation. |
| 6888 | boolean mAnimating; |
| 6889 | boolean mLocalAnimating; |
| 6890 | Animation mAnimation; |
| 6891 | boolean mAnimationIsEntrance; |
| 6892 | boolean mHasTransformation; |
| 6893 | boolean mHasLocalTransformation; |
| 6894 | final Transformation mTransformation = new Transformation(); |
| 6895 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6896 | // If a window showing a wallpaper: the requested offset for the |
| 6897 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 6898 | float mWallpaperX = -1; |
| 6899 | float mWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6900 | |
| 6901 | // If a window showing a wallpaper: what fraction of the offset |
| 6902 | // range corresponds to a full virtual screen. |
| 6903 | float mWallpaperXStep = -1; |
| 6904 | float mWallpaperYStep = -1; |
| 6905 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6906 | // Wallpaper windows: pixels offset based on above variables. |
| 6907 | int mXOffset; |
| 6908 | int mYOffset; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6909 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6910 | // This is set after IWindowSession.relayout() has been called at |
| 6911 | // least once for the window. It allows us to detect the situation |
| 6912 | // where we don't yet have a surface, but should have one soon, so |
| 6913 | // we can give the window focus before waiting for the relayout. |
| 6914 | boolean mRelayoutCalled; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6915 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6916 | // This is set after the Surface has been created but before the |
| 6917 | // window has been drawn. During this time the surface is hidden. |
| 6918 | boolean mDrawPending; |
| 6919 | |
| 6920 | // This is set after the window has finished drawing for the first |
| 6921 | // time but before its surface is shown. The surface will be |
| 6922 | // displayed when the next layout is run. |
| 6923 | boolean mCommitDrawPending; |
| 6924 | |
| 6925 | // This is set during the time after the window's drawing has been |
| 6926 | // committed, and before its surface is actually shown. It is used |
| 6927 | // to delay showing the surface until all windows in a token are ready |
| 6928 | // to be shown. |
| 6929 | boolean mReadyToShow; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6930 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6931 | // Set when the window has been shown in the screen the first time. |
| 6932 | boolean mHasDrawn; |
| 6933 | |
| 6934 | // Currently running an exit animation? |
| 6935 | boolean mExiting; |
| 6936 | |
| 6937 | // Currently on the mDestroySurface list? |
| 6938 | boolean mDestroying; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6939 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6940 | // Completely remove from window manager after exit animation? |
| 6941 | boolean mRemoveOnExit; |
| 6942 | |
| 6943 | // Set when the orientation is changing and this window has not yet |
| 6944 | // been updated for the new orientation. |
| 6945 | boolean mOrientationChanging; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6946 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6947 | // Is this window now (or just being) removed? |
| 6948 | boolean mRemoved; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6949 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6950 | // Temp for keeping track of windows that have been removed when |
| 6951 | // rebuilding window list. |
| 6952 | boolean mRebuilding; |
| 6953 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6954 | // For debugging, this is the last information given to the surface flinger. |
| 6955 | boolean mSurfaceShown; |
| 6956 | int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH; |
| 6957 | int mSurfaceLayer; |
| 6958 | float mSurfaceAlpha; |
| 6959 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6960 | // Input channel and input window handle used by the input dispatcher. |
| 6961 | InputWindowHandle mInputWindowHandle; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6962 | InputChannel mInputChannel; |
| 6963 | |
Mattias Petersson | 1622eee | 2010-12-21 10:15:11 +0100 | [diff] [blame] | 6964 | // Used to improve performance of toString() |
| 6965 | String mStringNameCache; |
| 6966 | CharSequence mLastTitle; |
| 6967 | boolean mWasPaused; |
| 6968 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6969 | WindowState(Session s, IWindow c, WindowToken token, |
| 6970 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 6971 | int viewVisibility) { |
| 6972 | mSession = s; |
| 6973 | mClient = c; |
| 6974 | mToken = token; |
| 6975 | mAttrs.copyFrom(a); |
| 6976 | mViewVisibility = viewVisibility; |
| 6977 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 6978 | mAlpha = a.alpha; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6979 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6980 | TAG, "Window " + this + " client=" + c.asBinder() |
| 6981 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 6982 | try { |
| 6983 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 6984 | } catch (RemoteException e) { |
| 6985 | mDeathRecipient = null; |
| 6986 | mAttachedWindow = null; |
| 6987 | mLayoutAttached = false; |
| 6988 | mIsImWindow = false; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6989 | mIsWallpaper = false; |
| 6990 | mIsFloatingLayer = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6991 | mBaseLayer = 0; |
| 6992 | mSubLayer = 0; |
| 6993 | return; |
| 6994 | } |
| 6995 | mDeathRecipient = deathRecipient; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6996 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6997 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 6998 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 6999 | // The multiplier here is to reserve space for multiple |
| 7000 | // windows in the same type layer. |
| 7001 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 7002 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 7003 | + TYPE_LAYER_OFFSET; |
| 7004 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 7005 | mAttachedWindow = attachedWindow; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7006 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7007 | mAttachedWindow.mChildWindows.add(this); |
| 7008 | mLayoutAttached = mAttrs.type != |
| 7009 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 7010 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 7011 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7012 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 7013 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7014 | } else { |
| 7015 | // The multiplier here is to reserve space for multiple |
| 7016 | // windows in the same type layer. |
| 7017 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 7018 | * TYPE_LAYER_MULTIPLIER |
| 7019 | + TYPE_LAYER_OFFSET; |
| 7020 | mSubLayer = 0; |
| 7021 | mAttachedWindow = null; |
| 7022 | mLayoutAttached = false; |
| 7023 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 7024 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7025 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 7026 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7027 | } |
| 7028 | |
| 7029 | WindowState appWin = this; |
| 7030 | while (appWin.mAttachedWindow != null) { |
| 7031 | appWin = mAttachedWindow; |
| 7032 | } |
| 7033 | WindowToken appToken = appWin.mToken; |
| 7034 | while (appToken.appWindowToken == null) { |
| 7035 | WindowToken parent = mTokenMap.get(appToken.token); |
| 7036 | if (parent == null || appToken == parent) { |
| 7037 | break; |
| 7038 | } |
| 7039 | appToken = parent; |
| 7040 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7041 | mRootToken = appToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7042 | mAppToken = appToken.appWindowToken; |
| 7043 | |
| 7044 | mSurface = null; |
| 7045 | mRequestedWidth = 0; |
| 7046 | mRequestedHeight = 0; |
| 7047 | mLastRequestedWidth = 0; |
| 7048 | mLastRequestedHeight = 0; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7049 | mXOffset = 0; |
| 7050 | mYOffset = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7051 | mLayer = 0; |
| 7052 | mAnimLayer = 0; |
| 7053 | mLastLayer = 0; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 7054 | mInputWindowHandle = new InputWindowHandle( |
| 7055 | mAppToken != null ? mAppToken.mInputApplicationHandle : null, this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7056 | } |
| 7057 | |
| 7058 | void attach() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7059 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7060 | TAG, "Attaching " + this + " token=" + mToken |
| 7061 | + ", list=" + mToken.windows); |
| 7062 | mSession.windowAddedLocked(); |
| 7063 | } |
| 7064 | |
| 7065 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 7066 | mHaveFrame = true; |
| 7067 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7068 | final Rect container = mContainingFrame; |
| 7069 | container.set(pf); |
| 7070 | |
| 7071 | final Rect display = mDisplayFrame; |
| 7072 | display.set(df); |
| 7073 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7074 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7075 | container.intersect(mCompatibleScreenFrame); |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7076 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 7077 | display.intersect(mCompatibleScreenFrame); |
| 7078 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7079 | } |
| 7080 | |
| 7081 | final int pw = container.right - container.left; |
| 7082 | final int ph = container.bottom - container.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7083 | |
| 7084 | int w,h; |
| 7085 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 7086 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 7087 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 7088 | } else { |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 7089 | w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth; |
| 7090 | h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7091 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7092 | |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 7093 | if (!mParentFrame.equals(pf)) { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 7094 | //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame |
| 7095 | // + " to " + pf); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 7096 | mParentFrame.set(pf); |
| 7097 | mContentChanged = true; |
| 7098 | } |
| 7099 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7100 | final Rect content = mContentFrame; |
| 7101 | content.set(cf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7102 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7103 | final Rect visible = mVisibleFrame; |
| 7104 | visible.set(vf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7105 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7106 | final Rect frame = mFrame; |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7107 | final int fw = frame.width(); |
| 7108 | final int fh = frame.height(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7109 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7110 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 7111 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 7112 | |
| 7113 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 7114 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 7115 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 7116 | |
| 7117 | //System.out.println("Out: " + mFrame); |
| 7118 | |
| 7119 | // Now make sure the window fits in the overall display. |
| 7120 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7121 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7122 | // Make sure the content and visible frames are inside of the |
| 7123 | // final window frame. |
| 7124 | if (content.left < frame.left) content.left = frame.left; |
| 7125 | if (content.top < frame.top) content.top = frame.top; |
| 7126 | if (content.right > frame.right) content.right = frame.right; |
| 7127 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 7128 | if (visible.left < frame.left) visible.left = frame.left; |
| 7129 | if (visible.top < frame.top) visible.top = frame.top; |
| 7130 | if (visible.right > frame.right) visible.right = frame.right; |
| 7131 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7132 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7133 | final Rect contentInsets = mContentInsets; |
| 7134 | contentInsets.left = content.left-frame.left; |
| 7135 | contentInsets.top = content.top-frame.top; |
| 7136 | contentInsets.right = frame.right-content.right; |
| 7137 | contentInsets.bottom = frame.bottom-content.bottom; |
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 | final Rect visibleInsets = mVisibleInsets; |
| 7140 | visibleInsets.left = visible.left-frame.left; |
| 7141 | visibleInsets.top = visible.top-frame.top; |
| 7142 | visibleInsets.right = frame.right-visible.right; |
| 7143 | visibleInsets.bottom = frame.bottom-visible.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7144 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 7145 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 7146 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 7147 | mDisplay.getHeight(), false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7148 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7149 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7150 | if (localLOGV) { |
| 7151 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 7152 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7153 | Slog.v(TAG, "Resolving (mRequestedWidth=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7154 | + mRequestedWidth + ", mRequestedheight=" |
| 7155 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 7156 | + "): frame=" + mFrame.toShortString() |
| 7157 | + " ci=" + contentInsets.toShortString() |
| 7158 | + " vi=" + visibleInsets.toShortString()); |
| 7159 | //} |
| 7160 | } |
| 7161 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7162 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7163 | public Rect getFrameLw() { |
| 7164 | return mFrame; |
| 7165 | } |
| 7166 | |
| 7167 | public Rect getShownFrameLw() { |
| 7168 | return mShownFrame; |
| 7169 | } |
| 7170 | |
| 7171 | public Rect getDisplayFrameLw() { |
| 7172 | return mDisplayFrame; |
| 7173 | } |
| 7174 | |
| 7175 | public Rect getContentFrameLw() { |
| 7176 | return mContentFrame; |
| 7177 | } |
| 7178 | |
| 7179 | public Rect getVisibleFrameLw() { |
| 7180 | return mVisibleFrame; |
| 7181 | } |
| 7182 | |
| 7183 | public boolean getGivenInsetsPendingLw() { |
| 7184 | return mGivenInsetsPending; |
| 7185 | } |
| 7186 | |
| 7187 | public Rect getGivenContentInsetsLw() { |
| 7188 | return mGivenContentInsets; |
| 7189 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7191 | public Rect getGivenVisibleInsetsLw() { |
| 7192 | return mGivenVisibleInsets; |
| 7193 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7194 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7195 | public WindowManager.LayoutParams getAttrs() { |
| 7196 | return mAttrs; |
| 7197 | } |
| 7198 | |
| 7199 | public int getSurfaceLayer() { |
| 7200 | return mLayer; |
| 7201 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7202 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7203 | public IApplicationToken getAppToken() { |
| 7204 | return mAppToken != null ? mAppToken.appToken : null; |
| 7205 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 7206 | |
| 7207 | public long getInputDispatchingTimeoutNanos() { |
| 7208 | return mAppToken != null |
| 7209 | ? mAppToken.inputDispatchingTimeoutNanos |
| 7210 | : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 7211 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7212 | |
| 7213 | public boolean hasAppShownWindows() { |
| 7214 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 7215 | } |
| 7216 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7217 | public void setAnimation(Animation anim) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7218 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7219 | TAG, "Setting animation in " + this + ": " + anim); |
| 7220 | mAnimating = false; |
| 7221 | mLocalAnimating = false; |
| 7222 | mAnimation = anim; |
| 7223 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 7224 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 7225 | } |
| 7226 | |
| 7227 | public void clearAnimation() { |
| 7228 | if (mAnimation != null) { |
| 7229 | mAnimating = true; |
| 7230 | mLocalAnimating = false; |
Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7231 | mAnimation.cancel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7232 | mAnimation = null; |
| 7233 | } |
| 7234 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7235 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7236 | Surface createSurfaceLocked() { |
| 7237 | if (mSurface == null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7238 | mReportDestroySurface = false; |
| 7239 | mSurfacePendingDestroy = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7240 | mDrawPending = true; |
| 7241 | mCommitDrawPending = false; |
| 7242 | mReadyToShow = false; |
| 7243 | if (mAppToken != null) { |
| 7244 | mAppToken.allDrawn = false; |
| 7245 | } |
| 7246 | |
| 7247 | int flags = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7248 | |
| 7249 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 7250 | flags |= Surface.SECURE; |
| 7251 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7252 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7253 | TAG, "Creating surface in session " |
| 7254 | + mSession.mSurfaceSession + " window " + this |
| 7255 | + " w=" + mFrame.width() |
| 7256 | + " h=" + mFrame.height() + " format=" |
| 7257 | + mAttrs.format + " flags=" + flags); |
| 7258 | |
| 7259 | int w = mFrame.width(); |
| 7260 | int h = mFrame.height(); |
| 7261 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 7262 | // for a scaled surface, we always want the requested |
| 7263 | // size. |
| 7264 | w = mRequestedWidth; |
| 7265 | h = mRequestedHeight; |
| 7266 | } |
| 7267 | |
Romain Guy | 9825ec6 | 2009-10-01 00:58:09 -0700 | [diff] [blame] | 7268 | // Something is wrong and SurfaceFlinger will not like this, |
| 7269 | // try to revert to sane values |
| 7270 | if (w <= 0) w = 1; |
| 7271 | if (h <= 0) h = 1; |
| 7272 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7273 | mSurfaceShown = false; |
| 7274 | mSurfaceLayer = 0; |
| 7275 | mSurfaceAlpha = 1; |
| 7276 | mSurfaceX = 0; |
| 7277 | mSurfaceY = 0; |
| 7278 | mSurfaceW = w; |
| 7279 | mSurfaceH = h; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7280 | try { |
Romain Guy | d10cd57 | 2010-10-10 13:33:22 -0700 | [diff] [blame] | 7281 | final boolean isHwAccelerated = (mAttrs.flags & |
| 7282 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0; |
| 7283 | final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format; |
| 7284 | if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) { |
| 7285 | flags |= Surface.OPAQUE; |
| 7286 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7287 | mSurface = new Surface( |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7288 | mSession.mSurfaceSession, mSession.mPid, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 7289 | mAttrs.getTitle().toString(), |
Romain Guy | d10cd57 | 2010-10-10 13:33:22 -0700 | [diff] [blame] | 7290 | 0, w, h, format, flags); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7291 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7292 | + mSurface + " IN SESSION " |
| 7293 | + mSession.mSurfaceSession |
| 7294 | + ": pid=" + mSession.mPid + " format=" |
| 7295 | + mAttrs.format + " flags=0x" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7296 | + Integer.toHexString(flags) |
| 7297 | + " / " + this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7298 | } catch (Surface.OutOfResourcesException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7299 | Slog.w(TAG, "OutOfResourcesException creating surface"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7300 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 7301 | return null; |
| 7302 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7303 | Slog.e(TAG, "Exception creating surface", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7304 | return null; |
| 7305 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7306 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7307 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7308 | TAG, "Got surface: " + mSurface |
| 7309 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 7310 | + ", animLayer=" + mAnimLayer); |
| 7311 | if (SHOW_TRANSACTIONS) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 7312 | Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked"); |
| 7313 | logSurface(this, "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" + |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7314 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 7315 | mAnimLayer + " HIDE", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7316 | } |
| 7317 | Surface.openTransaction(); |
| 7318 | try { |
| 7319 | try { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7320 | mSurfaceX = mFrame.left + mXOffset; |
Dianne Hackborn | 529bef6 | 2010-03-25 11:48:43 -0700 | [diff] [blame] | 7321 | mSurfaceY = mFrame.top + mYOffset; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7322 | mSurface.setPosition(mSurfaceX, mSurfaceY); |
| 7323 | mSurfaceLayer = mAnimLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7324 | mSurface.setLayer(mAnimLayer); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7325 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7326 | mSurface.hide(); |
| 7327 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7328 | if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7329 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 7330 | Surface.SURFACE_DITHER); |
| 7331 | } |
| 7332 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7333 | Slog.w(TAG, "Error creating surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7334 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 7335 | } |
| 7336 | mLastHidden = true; |
| 7337 | } finally { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7338 | Surface.closeTransaction(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 7339 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION createSurfaceLocked"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7340 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7341 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7342 | TAG, "Created surface " + this); |
| 7343 | } |
| 7344 | return mSurface; |
| 7345 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7346 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7347 | void destroySurfaceLocked() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7348 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 7349 | mAppToken.startingDisplayed = false; |
| 7350 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7351 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7352 | if (mSurface != null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7353 | mDrawPending = false; |
| 7354 | mCommitDrawPending = false; |
| 7355 | mReadyToShow = false; |
| 7356 | |
| 7357 | int i = mChildWindows.size(); |
| 7358 | while (i > 0) { |
| 7359 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7360 | WindowState c = mChildWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7361 | c.mAttachedHidden = true; |
| 7362 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7363 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7364 | if (mReportDestroySurface) { |
| 7365 | mReportDestroySurface = false; |
| 7366 | mSurfacePendingDestroy = true; |
| 7367 | try { |
| 7368 | mClient.dispatchGetNewSurface(); |
| 7369 | // We'll really destroy on the next time around. |
| 7370 | return; |
| 7371 | } catch (RemoteException e) { |
| 7372 | } |
| 7373 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7374 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7375 | try { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7376 | if (DEBUG_VISIBILITY) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7377 | RuntimeException e = null; |
| 7378 | if (!HIDE_STACK_CRAWLS) { |
| 7379 | e = new RuntimeException(); |
| 7380 | e.fillInStackTrace(); |
| 7381 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7382 | Slog.w(TAG, "Window " + this + " destroying surface " |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7383 | + mSurface + ", session " + mSession, e); |
| 7384 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7385 | if (SHOW_TRANSACTIONS) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7386 | RuntimeException e = null; |
| 7387 | if (!HIDE_STACK_CRAWLS) { |
| 7388 | e = new RuntimeException(); |
| 7389 | e.fillInStackTrace(); |
| 7390 | } |
| 7391 | if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7392 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7393 | mSurface.destroy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7394 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7395 | Slog.w(TAG, "Exception thrown when destroying Window " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7396 | + " surface " + mSurface + " session " + mSession |
| 7397 | + ": " + e.toString()); |
| 7398 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7399 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7400 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7401 | mSurface = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7402 | } |
| 7403 | } |
| 7404 | |
| 7405 | boolean finishDrawingLocked() { |
| 7406 | if (mDrawPending) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7407 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7408 | TAG, "finishDrawingLocked: " + mSurface); |
| 7409 | mCommitDrawPending = true; |
| 7410 | mDrawPending = false; |
| 7411 | return true; |
| 7412 | } |
| 7413 | return false; |
| 7414 | } |
| 7415 | |
| 7416 | // This must be called while inside a transaction. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7417 | boolean commitFinishDrawingLocked(long currentTime) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7418 | //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7419 | if (!mCommitDrawPending) { |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7420 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7421 | } |
| 7422 | mCommitDrawPending = false; |
| 7423 | mReadyToShow = true; |
| 7424 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 7425 | final AppWindowToken atoken = mAppToken; |
| 7426 | if (atoken == null || atoken.allDrawn || starting) { |
| 7427 | performShowLocked(); |
| 7428 | } |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7429 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7430 | } |
| 7431 | |
| 7432 | // This must be called while inside a transaction. |
| 7433 | boolean performShowLocked() { |
| 7434 | if (DEBUG_VISIBILITY) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7435 | RuntimeException e = null; |
| 7436 | if (!HIDE_STACK_CRAWLS) { |
| 7437 | e = new RuntimeException(); |
| 7438 | e.fillInStackTrace(); |
| 7439 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7440 | Slog.v(TAG, "performShow on " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7441 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 7442 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 7443 | } |
| 7444 | if (mReadyToShow && isReadyForDisplay()) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7445 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this, |
| 7446 | "SHOW (performShowLocked)", null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7447 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7448 | + " during animation: policyVis=" + mPolicyVisibility |
| 7449 | + " attHidden=" + mAttachedHidden |
| 7450 | + " tok.hiddenRequested=" |
| 7451 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7452 | + " tok.hidden=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7453 | + (mAppToken != null ? mAppToken.hidden : false) |
| 7454 | + " animating=" + mAnimating |
| 7455 | + " tok animating=" |
| 7456 | + (mAppToken != null ? mAppToken.animating : false)); |
| 7457 | if (!showSurfaceRobustlyLocked(this)) { |
| 7458 | return false; |
| 7459 | } |
| 7460 | mLastAlpha = -1; |
| 7461 | mHasDrawn = true; |
| 7462 | mLastHidden = false; |
| 7463 | mReadyToShow = false; |
| 7464 | enableScreenIfNeededLocked(); |
| 7465 | |
| 7466 | applyEnterAnimationLocked(this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7467 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7468 | int i = mChildWindows.size(); |
| 7469 | while (i > 0) { |
| 7470 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7471 | WindowState c = mChildWindows.get(i); |
Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7472 | if (c.mAttachedHidden) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7473 | c.mAttachedHidden = false; |
Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7474 | if (c.mSurface != null) { |
| 7475 | c.performShowLocked(); |
| 7476 | // It hadn't been shown, which means layout not |
| 7477 | // performed on it, so now we want to make sure to |
| 7478 | // do a layout. If called from within the transaction |
| 7479 | // loop, this will cause it to restart with a new |
| 7480 | // layout. |
| 7481 | mLayoutNeeded = true; |
| 7482 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7483 | } |
| 7484 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7485 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7486 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 7487 | && mAppToken != null) { |
| 7488 | mAppToken.firstWindowDrawn = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7489 | |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7490 | if (mAppToken.startingData != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7491 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7492 | "Finish starting " + mToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7493 | + ": first real window is shown, no animation"); |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7494 | // If this initial window is animating, stop it -- we |
| 7495 | // will do an animation to reveal it from behind the |
| 7496 | // starting window, so there is no need for it to also |
| 7497 | // be doing its own stuff. |
| 7498 | if (mAnimation != null) { |
Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7499 | mAnimation.cancel(); |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7500 | mAnimation = null; |
| 7501 | // Make sure we clean up the animation. |
| 7502 | mAnimating = true; |
| 7503 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7504 | mFinishedStarting.add(mAppToken); |
| 7505 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7506 | } |
| 7507 | mAppToken.updateReportedVisibilityLocked(); |
| 7508 | } |
| 7509 | } |
| 7510 | return true; |
| 7511 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7512 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7513 | // This must be called while inside a transaction. Returns true if |
| 7514 | // there is more animation to run. |
| 7515 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7516 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7517 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7518 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7519 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 7520 | mHasTransformation = true; |
| 7521 | mHasLocalTransformation = true; |
| 7522 | if (!mLocalAnimating) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7523 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7524 | TAG, "Starting animation in " + this + |
| 7525 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 7526 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 7527 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 7528 | mAnimation.setStartTime(currentTime); |
| 7529 | mLocalAnimating = true; |
| 7530 | mAnimating = true; |
| 7531 | } |
| 7532 | mTransformation.clear(); |
| 7533 | final boolean more = mAnimation.getTransformation( |
| 7534 | currentTime, mTransformation); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7535 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7536 | TAG, "Stepped animation in " + this + |
| 7537 | ": more=" + more + ", xform=" + mTransformation); |
| 7538 | if (more) { |
| 7539 | // we're not done! |
| 7540 | return true; |
| 7541 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7542 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7543 | TAG, "Finished animation in " + this + |
| 7544 | " @ " + currentTime); |
Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7545 | |
| 7546 | if (mAnimation != null) { |
| 7547 | mAnimation.cancel(); |
| 7548 | mAnimation = null; |
| 7549 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7550 | //WindowManagerService.this.dump(); |
| 7551 | } |
| 7552 | mHasLocalTransformation = false; |
| 7553 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7554 | && mAppToken.animation != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7555 | // When our app token is animating, we kind-of pretend like |
| 7556 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 7557 | // part of this check means that we will only do this if |
| 7558 | // our window is not currently exiting, or it is not |
| 7559 | // locally animating itself. The idea being that one that |
| 7560 | // is exiting and doing a local animation should be removed |
| 7561 | // once that animation is done. |
| 7562 | mAnimating = true; |
| 7563 | mHasTransformation = true; |
| 7564 | mTransformation.clear(); |
| 7565 | return false; |
| 7566 | } else if (mHasTransformation) { |
| 7567 | // Little trick to get through the path below to act like |
| 7568 | // we have finished an animation. |
| 7569 | mAnimating = true; |
| 7570 | } else if (isAnimating()) { |
| 7571 | mAnimating = true; |
| 7572 | } |
| 7573 | } else if (mAnimation != null) { |
| 7574 | // If the display is frozen, and there is a pending animation, |
| 7575 | // clear it and make sure we run the cleanup code. |
| 7576 | mAnimating = true; |
| 7577 | mLocalAnimating = true; |
Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7578 | mAnimation.cancel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7579 | mAnimation = null; |
| 7580 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7581 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7582 | if (!mAnimating && !mLocalAnimating) { |
| 7583 | return false; |
| 7584 | } |
| 7585 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7586 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7587 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 7588 | + ", reportedVisible=" |
| 7589 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7590 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7591 | mAnimating = false; |
| 7592 | mLocalAnimating = false; |
Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7593 | if (mAnimation != null) { |
| 7594 | mAnimation.cancel(); |
| 7595 | mAnimation = null; |
| 7596 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7597 | mAnimLayer = mLayer; |
| 7598 | if (mIsImWindow) { |
| 7599 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7600 | } else if (mIsWallpaper) { |
| 7601 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7602 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7603 | if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7604 | + " anim layer: " + mAnimLayer); |
| 7605 | mHasTransformation = false; |
| 7606 | mHasLocalTransformation = false; |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7607 | if (mPolicyVisibility != mPolicyVisibilityAfterAnim) { |
| 7608 | if (DEBUG_VISIBILITY) { |
| 7609 | Slog.v(TAG, "Policy visibility changing after anim in " + this + ": " |
| 7610 | + mPolicyVisibilityAfterAnim); |
| 7611 | } |
| 7612 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 7613 | if (!mPolicyVisibility) { |
| 7614 | if (mCurrentFocus == this) { |
| 7615 | mFocusMayChange = true; |
| 7616 | } |
| 7617 | // Window is no longer visible -- make sure if we were waiting |
| 7618 | // for it to be displayed before enabling the display, that |
| 7619 | // we allow the display to be enabled now. |
| 7620 | enableScreenIfNeededLocked(); |
| 7621 | } |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7622 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7623 | mTransformation.clear(); |
| 7624 | if (mHasDrawn |
| 7625 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 7626 | && mAppToken != null |
| 7627 | && mAppToken.firstWindowDrawn |
| 7628 | && mAppToken.startingData != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7629 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7630 | + mToken + ": first real window done animating"); |
| 7631 | mFinishedStarting.add(mAppToken); |
| 7632 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7633 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7634 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7635 | finishExit(); |
| 7636 | |
| 7637 | if (mAppToken != null) { |
| 7638 | mAppToken.updateReportedVisibilityLocked(); |
| 7639 | } |
| 7640 | |
| 7641 | return false; |
| 7642 | } |
| 7643 | |
| 7644 | void finishExit() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7645 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7646 | TAG, "finishExit in " + this |
| 7647 | + ": exiting=" + mExiting |
| 7648 | + " remove=" + mRemoveOnExit |
| 7649 | + " windowAnimating=" + isWindowAnimating()); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7650 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7651 | final int N = mChildWindows.size(); |
| 7652 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7653 | mChildWindows.get(i).finishExit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7654 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7655 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7656 | if (!mExiting) { |
| 7657 | return; |
| 7658 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7659 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7660 | if (isWindowAnimating()) { |
| 7661 | return; |
| 7662 | } |
| 7663 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7664 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7665 | TAG, "Exit animation finished in " + this |
| 7666 | + ": remove=" + mRemoveOnExit); |
| 7667 | if (mSurface != null) { |
| 7668 | mDestroySurface.add(this); |
| 7669 | mDestroying = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7670 | if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7671 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7672 | try { |
| 7673 | mSurface.hide(); |
| 7674 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7675 | Slog.w(TAG, "Error hiding surface in " + this, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7676 | } |
| 7677 | mLastHidden = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7678 | } |
| 7679 | mExiting = false; |
| 7680 | if (mRemoveOnExit) { |
| 7681 | mPendingRemove.add(this); |
| 7682 | mRemoveOnExit = false; |
| 7683 | } |
| 7684 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7685 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7686 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 7687 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 7688 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 7689 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 7690 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 7691 | return true; |
| 7692 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7693 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7694 | void computeShownFrameLocked() { |
| 7695 | final boolean selfTransformation = mHasLocalTransformation; |
| 7696 | Transformation attachedTransformation = |
| 7697 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 7698 | ? mAttachedWindow.mTransformation : null; |
| 7699 | Transformation appTransformation = |
| 7700 | (mAppToken != null && mAppToken.hasTransformation) |
| 7701 | ? mAppToken.transformation : null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7702 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7703 | // Wallpapers are animated based on the "real" window they |
| 7704 | // are currently targeting. |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7705 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7706 | && mWallpaperTarget != null) { |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7707 | if (mWallpaperTarget.mHasLocalTransformation && |
| 7708 | mWallpaperTarget.mAnimation != null && |
| 7709 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7710 | attachedTransformation = mWallpaperTarget.mTransformation; |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7711 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7712 | Slog.v(TAG, "WP target attached xform: " + attachedTransformation); |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7713 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7714 | } |
| 7715 | if (mWallpaperTarget.mAppToken != null && |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7716 | mWallpaperTarget.mAppToken.hasTransformation && |
| 7717 | mWallpaperTarget.mAppToken.animation != null && |
| 7718 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7719 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7720 | if (DEBUG_WALLPAPER && appTransformation != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7721 | Slog.v(TAG, "WP target app xform: " + appTransformation); |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7722 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7723 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7724 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7725 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7726 | final boolean screenAnimation = mScreenRotationAnimation != null |
| 7727 | && mScreenRotationAnimation.isAnimating(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7728 | if (selfTransformation || attachedTransformation != null |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7729 | || appTransformation != null || screenAnimation) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7730 | // cache often used attributes locally |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7731 | final Rect frame = mFrame; |
| 7732 | final float tmpFloats[] = mTmpFloats; |
| 7733 | final Matrix tmpMatrix = mTmpMatrix; |
| 7734 | |
| 7735 | // Compute the desired transformation. |
Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7736 | tmpMatrix.setTranslate(0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7737 | if (selfTransformation) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7738 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7739 | } |
Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7740 | tmpMatrix.postTranslate(frame.left, frame.top); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7741 | if (attachedTransformation != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7742 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7743 | } |
| 7744 | if (appTransformation != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7745 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7746 | } |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7747 | if (screenAnimation) { |
| 7748 | tmpMatrix.postConcat( |
| 7749 | mScreenRotationAnimation.getEnterTransformation().getMatrix()); |
| 7750 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7751 | |
| 7752 | // "convert" it into SurfaceFlinger's format |
| 7753 | // (a 2x2 matrix + an offset) |
| 7754 | // Here we must not transform the position of the surface |
| 7755 | // since it is already included in the transformation. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7756 | //Slog.i(TAG, "Transform: " + matrix); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7757 | |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 7758 | mHaveMatrix = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7759 | tmpMatrix.getValues(tmpFloats); |
| 7760 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7761 | mDtDx = tmpFloats[Matrix.MSKEW_Y]; |
| 7762 | mDsDy = tmpFloats[Matrix.MSKEW_X]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7763 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7764 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 7765 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7766 | int w = frame.width(); |
| 7767 | int h = frame.height(); |
| 7768 | mShownFrame.set(x, y, x+w, y+h); |
| 7769 | |
| 7770 | // Now set the alpha... but because our current hardware |
| 7771 | // can't do alpha transformation on a non-opaque surface, |
| 7772 | // turn it off if we are running an animation that is also |
| 7773 | // transforming since it is more important to have that |
| 7774 | // animation be smooth. |
| 7775 | mShownAlpha = mAlpha; |
| 7776 | if (!mLimitedAlphaCompositing |
| 7777 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 7778 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 7779 | && x == frame.left && y == frame.top))) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7780 | //Slog.i(TAG, "Applying alpha transform"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7781 | if (selfTransformation) { |
| 7782 | mShownAlpha *= mTransformation.getAlpha(); |
| 7783 | } |
| 7784 | if (attachedTransformation != null) { |
| 7785 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 7786 | } |
| 7787 | if (appTransformation != null) { |
| 7788 | mShownAlpha *= appTransformation.getAlpha(); |
| 7789 | } |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7790 | if (screenAnimation) { |
| 7791 | mShownAlpha *= |
| 7792 | mScreenRotationAnimation.getEnterTransformation().getAlpha(); |
| 7793 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7794 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7795 | //Slog.i(TAG, "Not applying alpha transform"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7796 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7797 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7798 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7799 | TAG, "Continuing animation in " + this + |
| 7800 | ": " + mShownFrame + |
| 7801 | ", alpha=" + mTransformation.getAlpha()); |
| 7802 | return; |
| 7803 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7804 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7805 | mShownFrame.set(mFrame); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7806 | if (mXOffset != 0 || mYOffset != 0) { |
| 7807 | mShownFrame.offset(mXOffset, mYOffset); |
| 7808 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7809 | mShownAlpha = mAlpha; |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 7810 | mHaveMatrix = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7811 | mDsDx = 1; |
| 7812 | mDtDx = 0; |
| 7813 | mDsDy = 0; |
| 7814 | mDtDy = 1; |
| 7815 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7816 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7817 | /** |
| 7818 | * Is this window visible? It is not visible if there is no |
| 7819 | * surface, or we are in the process of running an exit animation |
| 7820 | * that will remove the surface, or its app token has been hidden. |
| 7821 | */ |
| 7822 | public boolean isVisibleLw() { |
| 7823 | final AppWindowToken atoken = mAppToken; |
| 7824 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7825 | && (atoken == null || !atoken.hiddenRequested) |
| 7826 | && !mExiting && !mDestroying; |
| 7827 | } |
| 7828 | |
| 7829 | /** |
Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7830 | * Like {@link #isVisibleLw}, but also counts a window that is currently |
| 7831 | * "hidden" behind the keyguard as visible. This allows us to apply |
| 7832 | * things like window flags that impact the keyguard. |
| 7833 | * XXX I am starting to think we need to have ANOTHER visibility flag |
| 7834 | * for this "hidden behind keyguard" state rather than overloading |
| 7835 | * mPolicyVisibility. Ungh. |
| 7836 | */ |
| 7837 | public boolean isVisibleOrBehindKeyguardLw() { |
| 7838 | final AppWindowToken atoken = mAppToken; |
| 7839 | return mSurface != null && !mAttachedHidden |
| 7840 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7841 | && !mDrawPending && !mCommitDrawPending |
Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7842 | && !mExiting && !mDestroying; |
| 7843 | } |
| 7844 | |
| 7845 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7846 | * Is this window visible, ignoring its app token? It is not visible |
| 7847 | * if there is no surface, or we are in the process of running an exit animation |
| 7848 | * that will remove the surface. |
| 7849 | */ |
| 7850 | public boolean isWinVisibleLw() { |
| 7851 | final AppWindowToken atoken = mAppToken; |
| 7852 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7853 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 7854 | && !mExiting && !mDestroying; |
| 7855 | } |
| 7856 | |
| 7857 | /** |
| 7858 | * The same as isVisible(), but follows the current hidden state of |
| 7859 | * the associated app token, not the pending requested hidden state. |
| 7860 | */ |
| 7861 | boolean isVisibleNow() { |
| 7862 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7863 | && !mRootToken.hidden && !mExiting && !mDestroying; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7864 | } |
| 7865 | |
| 7866 | /** |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7867 | * Can this window possibly be a drag/drop target? The test here is |
| 7868 | * a combination of the above "visible now" with the check that the |
| 7869 | * Input Manager uses when discarding windows from input consideration. |
| 7870 | */ |
| 7871 | boolean isPotentialDragTarget() { |
| 7872 | return isVisibleNow() && (mInputChannel != null) && !mRemoved; |
| 7873 | } |
| 7874 | |
| 7875 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7876 | * Same as isVisible(), but we also count it as visible between the |
| 7877 | * call to IWindowSession.add() and the first relayout(). |
| 7878 | */ |
| 7879 | boolean isVisibleOrAdding() { |
| 7880 | final AppWindowToken atoken = mAppToken; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7881 | return ((mSurface != null && !mReportDestroySurface) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7882 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 7883 | && mPolicyVisibility && !mAttachedHidden |
| 7884 | && (atoken == null || !atoken.hiddenRequested) |
| 7885 | && !mExiting && !mDestroying; |
| 7886 | } |
| 7887 | |
| 7888 | /** |
| 7889 | * Is this window currently on-screen? It is on-screen either if it |
| 7890 | * is visible or it is currently running an animation before no longer |
| 7891 | * being visible. |
| 7892 | */ |
| 7893 | boolean isOnScreen() { |
| 7894 | final AppWindowToken atoken = mAppToken; |
| 7895 | if (atoken != null) { |
| 7896 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7897 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7898 | || mAnimation != null || atoken.animation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7899 | } else { |
| 7900 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7901 | && (!mAttachedHidden || mAnimation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | * Like isOnScreen(), but we don't return true if the window is part |
| 7907 | * of a transition that has not yet been started. |
| 7908 | */ |
| 7909 | boolean isReadyForDisplay() { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7910 | if (mRootToken.waitingToShow && |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 7911 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7912 | return false; |
| 7913 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7914 | final AppWindowToken atoken = mAppToken; |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7915 | final boolean animating = atoken != null |
| 7916 | ? (atoken.animation != null) : false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7917 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7918 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 7919 | && !mRootToken.hidden) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7920 | || mAnimation != null || animating); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7921 | } |
| 7922 | |
| 7923 | /** Is the window or its container currently animating? */ |
| 7924 | boolean isAnimating() { |
| 7925 | final WindowState attached = mAttachedWindow; |
| 7926 | final AppWindowToken atoken = mAppToken; |
| 7927 | return mAnimation != null |
| 7928 | || (attached != null && attached.mAnimation != null) |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7929 | || (atoken != null && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7930 | (atoken.animation != null |
| 7931 | || atoken.inPendingTransaction)); |
| 7932 | } |
| 7933 | |
| 7934 | /** Is this window currently animating? */ |
| 7935 | boolean isWindowAnimating() { |
| 7936 | return mAnimation != null; |
| 7937 | } |
| 7938 | |
| 7939 | /** |
| 7940 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 7941 | * been drawn. |
| 7942 | */ |
| 7943 | public boolean isDisplayedLw() { |
| 7944 | final AppWindowToken atoken = mAppToken; |
| 7945 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7946 | && !mDrawPending && !mCommitDrawPending |
| 7947 | && ((!mAttachedHidden && |
| 7948 | (atoken == null || !atoken.hiddenRequested)) |
| 7949 | || mAnimating); |
| 7950 | } |
| 7951 | |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7952 | /** |
| 7953 | * Returns true if the window has a surface that it has drawn a |
| 7954 | * complete UI in to. |
| 7955 | */ |
| 7956 | public boolean isDrawnLw() { |
| 7957 | final AppWindowToken atoken = mAppToken; |
| 7958 | return mSurface != null && !mDestroying |
| 7959 | && !mDrawPending && !mCommitDrawPending; |
| 7960 | } |
| 7961 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7962 | /** |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7963 | * Return true if the window is opaque and fully drawn. This indicates |
| 7964 | * it may obscure windows behind it. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7965 | */ |
| 7966 | boolean isOpaqueDrawn() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7967 | return (mAttrs.format == PixelFormat.OPAQUE |
| 7968 | || mAttrs.type == TYPE_WALLPAPER) |
| 7969 | && mSurface != null && mAnimation == null |
| 7970 | && (mAppToken == null || mAppToken.animation == null) |
| 7971 | && !mDrawPending && !mCommitDrawPending; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7972 | } |
| 7973 | |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 7974 | /** |
| 7975 | * Return whether this window is wanting to have a translation |
| 7976 | * animation applied to it for an in-progress move. (Only makes |
| 7977 | * sense to call from performLayoutAndPlaceSurfacesLockedInner().) |
| 7978 | */ |
| 7979 | boolean shouldAnimateMove() { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 7980 | return mContentChanged && !mExiting && !mLastHidden && !mDisplayFrozen |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 7981 | && (mFrame.top != mLastFrame.top |
| 7982 | || mFrame.left != mLastFrame.left) |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 7983 | && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove()) |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 7984 | && mPolicy.isScreenOn(); |
| 7985 | } |
| 7986 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7987 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 7988 | return |
| 7989 | // only if the application is requesting compatible window |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7990 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 7991 | // only if it's visible |
| 7992 | mHasDrawn && mViewVisibility == View.VISIBLE && |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7993 | // and only if the application fills the compatible screen |
| 7994 | mFrame.left <= mCompatibleScreenFrame.left && |
| 7995 | mFrame.top <= mCompatibleScreenFrame.top && |
| 7996 | mFrame.right >= mCompatibleScreenFrame.right && |
| 7997 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7998 | // and starting window do not need background filler |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7999 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8000 | } |
| 8001 | |
| 8002 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 8003 | return mFrame.left <= 0 && mFrame.top <= 0 && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 8004 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8005 | } |
| 8006 | |
| 8007 | void removeLocked() { |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 8008 | disposeInputChannel(); |
| 8009 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8010 | if (mAttachedWindow != null) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8011 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8012 | mAttachedWindow.mChildWindows.remove(this); |
| 8013 | } |
| 8014 | destroySurfaceLocked(); |
| 8015 | mSession.windowRemovedLocked(); |
| 8016 | try { |
| 8017 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 8018 | } catch (RuntimeException e) { |
| 8019 | // Ignore if it has already been removed (usually because |
| 8020 | // we are doing this as part of processing a death note.) |
| 8021 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 8022 | } |
| 8023 | |
| 8024 | void disposeInputChannel() { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 8025 | if (mInputChannel != null) { |
| 8026 | mInputManager.unregisterInputChannel(mInputChannel); |
| 8027 | |
| 8028 | mInputChannel.dispose(); |
| 8029 | mInputChannel = null; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8030 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8031 | } |
| 8032 | |
| 8033 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 8034 | public void binderDied() { |
| 8035 | try { |
| 8036 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8037 | WindowState win = windowForClientLocked(mSession, mClient, false); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8038 | Slog.i(TAG, "WIN DEATH: " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8039 | if (win != null) { |
| 8040 | removeWindowLocked(mSession, win); |
| 8041 | } |
| 8042 | } |
| 8043 | } catch (IllegalArgumentException ex) { |
| 8044 | // This will happen if the window has already been |
| 8045 | // removed. |
| 8046 | } |
| 8047 | } |
| 8048 | } |
| 8049 | |
| 8050 | /** Returns true if this window desires key events. */ |
| 8051 | public final boolean canReceiveKeys() { |
| 8052 | return isVisibleOrAdding() |
| 8053 | && (mViewVisibility == View.VISIBLE) |
| 8054 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 8055 | } |
| 8056 | |
| 8057 | public boolean hasDrawnLw() { |
| 8058 | return mHasDrawn; |
| 8059 | } |
| 8060 | |
| 8061 | public boolean showLw(boolean doAnimation) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8062 | return showLw(doAnimation, true); |
| 8063 | } |
| 8064 | |
| 8065 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 8066 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 8067 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8068 | } |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8069 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8070 | if (doAnimation) { |
| 8071 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
| 8072 | + mPolicyVisibility + " mAnimation=" + mAnimation); |
| 8073 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 8074 | doAnimation = false; |
| 8075 | } else if (mPolicyVisibility && mAnimation == null) { |
| 8076 | // Check for the case where we are currently visible and |
| 8077 | // not animating; we do not want to do animation at such a |
| 8078 | // point to become visible when we already are. |
| 8079 | doAnimation = false; |
| 8080 | } |
| 8081 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8082 | mPolicyVisibility = true; |
| 8083 | mPolicyVisibilityAfterAnim = true; |
| 8084 | if (doAnimation) { |
| 8085 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 8086 | } |
| 8087 | if (requestAnim) { |
| 8088 | requestAnimationLocked(0); |
| 8089 | } |
| 8090 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8091 | } |
| 8092 | |
| 8093 | public boolean hideLw(boolean doAnimation) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8094 | return hideLw(doAnimation, true); |
| 8095 | } |
| 8096 | |
| 8097 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8098 | if (doAnimation) { |
| 8099 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 8100 | doAnimation = false; |
| 8101 | } |
| 8102 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8103 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 8104 | : mPolicyVisibility; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8105 | if (!current) { |
| 8106 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8107 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8108 | if (doAnimation) { |
| 8109 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 8110 | if (mAnimation == null) { |
| 8111 | doAnimation = false; |
| 8112 | } |
| 8113 | } |
| 8114 | if (doAnimation) { |
| 8115 | mPolicyVisibilityAfterAnim = false; |
| 8116 | } else { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8117 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8118 | mPolicyVisibilityAfterAnim = false; |
| 8119 | mPolicyVisibility = false; |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 8120 | // Window is no longer visible -- make sure if we were waiting |
| 8121 | // for it to be displayed before enabling the display, that |
| 8122 | // we allow the display to be enabled now. |
| 8123 | enableScreenIfNeededLocked(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8124 | if (mCurrentFocus == this) { |
| 8125 | mFocusMayChange = true; |
| 8126 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8127 | } |
| 8128 | if (requestAnim) { |
| 8129 | requestAnimationLocked(0); |
| 8130 | } |
| 8131 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8132 | } |
| 8133 | |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 8134 | public void getTouchableRegion(Region outRegion) { |
| 8135 | final Rect frame = mFrame; |
| 8136 | switch (mTouchableInsets) { |
| 8137 | default: |
| 8138 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME: |
| 8139 | outRegion.set(frame); |
| 8140 | break; |
| 8141 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: { |
| 8142 | final Rect inset = mGivenContentInsets; |
| 8143 | outRegion.set( |
| 8144 | frame.left + inset.left, frame.top + inset.top, |
| 8145 | frame.right - inset.right, frame.bottom - inset.bottom); |
| 8146 | break; |
| 8147 | } |
| 8148 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: { |
| 8149 | final Rect inset = mGivenVisibleInsets; |
| 8150 | outRegion.set( |
| 8151 | frame.left + inset.left, frame.top + inset.top, |
| 8152 | frame.right - inset.right, frame.bottom - inset.bottom); |
| 8153 | break; |
| 8154 | } |
| 8155 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: { |
| 8156 | final Region givenTouchableRegion = mGivenTouchableRegion; |
| 8157 | outRegion.set(givenTouchableRegion); |
| 8158 | outRegion.translate(frame.left, frame.top); |
| 8159 | break; |
| 8160 | } |
| 8161 | } |
| 8162 | } |
| 8163 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8164 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8165 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 8166 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 8167 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 8168 | if (mAttachedWindow != null || mLayoutAttached) { |
| 8169 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 8170 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 8171 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 8172 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 8173 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 8174 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8175 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 8176 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8177 | } |
| 8178 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 8179 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 8180 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 8181 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 8182 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 8183 | pw.print("="); pw.print(mAnimLayer); |
| 8184 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 8185 | if (mSurface != null) { |
| 8186 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8187 | pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown); |
| 8188 | pw.print(" layer="); pw.print(mSurfaceLayer); |
| 8189 | pw.print(" alpha="); pw.print(mSurfaceAlpha); |
| 8190 | pw.print(" rect=("); pw.print(mSurfaceX); |
| 8191 | pw.print(","); pw.print(mSurfaceY); |
| 8192 | pw.print(") "); pw.print(mSurfaceW); |
| 8193 | pw.print(" x "); pw.println(mSurfaceH); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8194 | } |
| 8195 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 8196 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 8197 | if (mAppToken != null) { |
| 8198 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 8199 | } |
| 8200 | if (mTargetAppToken != null) { |
| 8201 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 8202 | } |
| 8203 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 8204 | pw.print(Integer.toHexString(mViewVisibility)); |
| 8205 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8206 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 8207 | pw.print(" mObscured="); pw.println(mObscured); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8208 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 8209 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 8210 | pw.print(mPolicyVisibility); |
| 8211 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 8212 | pw.print(mPolicyVisibilityAfterAnim); |
| 8213 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 8214 | } |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 8215 | if (!mRelayoutCalled) { |
| 8216 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled); |
| 8217 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8218 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8219 | pw.print(" h="); pw.print(mRequestedHeight); |
| 8220 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8221 | if (mXOffset != 0 || mYOffset != 0) { |
| 8222 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 8223 | pw.print(" y="); pw.println(mYOffset); |
| 8224 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8225 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 8226 | mGivenContentInsets.printShortString(pw); |
| 8227 | pw.print(" mGivenVisibleInsets="); |
| 8228 | mGivenVisibleInsets.printShortString(pw); |
| 8229 | pw.println(); |
| 8230 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 8231 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 8232 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 8233 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8234 | pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8235 | pw.print(prefix); pw.print("mShownFrame="); |
| 8236 | mShownFrame.printShortString(pw); |
| 8237 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 8238 | pw.println(); |
| 8239 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 8240 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 8241 | pw.println(); |
| 8242 | pw.print(prefix); pw.print("mContainingFrame="); |
| 8243 | mContainingFrame.printShortString(pw); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 8244 | pw.print(" mParentFrame="); |
| 8245 | mParentFrame.printShortString(pw); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8246 | pw.print(" mDisplayFrame="); |
| 8247 | mDisplayFrame.printShortString(pw); |
| 8248 | pw.println(); |
| 8249 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 8250 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 8251 | pw.println(); |
| 8252 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 8253 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 8254 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 8255 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 8256 | pw.println(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8257 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 8258 | || mAnimation != null) { |
| 8259 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 8260 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 8261 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 8262 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 8263 | } |
| 8264 | if (mHasTransformation || mHasLocalTransformation) { |
| 8265 | pw.print(prefix); pw.print("XForm: has="); |
| 8266 | pw.print(mHasTransformation); |
| 8267 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 8268 | pw.print(" "); mTransformation.printShortString(pw); |
| 8269 | pw.println(); |
| 8270 | } |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 8271 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 8272 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 8273 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 8274 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 8275 | } |
| 8276 | if (mHaveMatrix) { |
| 8277 | pw.print(prefix); pw.print("mDsDx="); pw.print(mDsDx); |
| 8278 | pw.print(" mDtDx="); pw.print(mDtDx); |
| 8279 | pw.print(" mDsDy="); pw.print(mDsDy); |
| 8280 | pw.print(" mDtDy="); pw.println(mDtDy); |
| 8281 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8282 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 8283 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 8284 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 8285 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 8286 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 8287 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 8288 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 8289 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 8290 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 8291 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8292 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8293 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 8294 | pw.print(mOrientationChanging); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8295 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 8296 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8297 | } |
Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 8298 | if (mHScale != 1 || mVScale != 1) { |
| 8299 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 8300 | pw.print(" mVScale="); pw.println(mVScale); |
| 8301 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 8302 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8303 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 8304 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 8305 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 8306 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 8307 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 8308 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 8309 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8310 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8311 | |
| 8312 | String makeInputChannelName() { |
| 8313 | return Integer.toHexString(System.identityHashCode(this)) |
| 8314 | + " " + mAttrs.getTitle(); |
| 8315 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8316 | |
| 8317 | @Override |
| 8318 | public String toString() { |
Mattias Petersson | 1622eee | 2010-12-21 10:15:11 +0100 | [diff] [blame] | 8319 | if (mStringNameCache == null || mLastTitle != mAttrs.getTitle() |
| 8320 | || mWasPaused != mToken.paused) { |
| 8321 | mLastTitle = mAttrs.getTitle(); |
| 8322 | mWasPaused = mToken.paused; |
| 8323 | mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this)) |
| 8324 | + " " + mLastTitle + " paused=" + mWasPaused + "}"; |
| 8325 | } |
| 8326 | return mStringNameCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8327 | } |
| 8328 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8329 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8330 | // ------------------------------------------------------------- |
| 8331 | // Window Token State |
| 8332 | // ------------------------------------------------------------- |
| 8333 | |
| 8334 | class WindowToken { |
| 8335 | // The actual token. |
| 8336 | final IBinder token; |
| 8337 | |
| 8338 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 8339 | final int windowType; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8340 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8341 | // Set if this token was explicitly added by a client, so should |
| 8342 | // not be removed when all windows are removed. |
| 8343 | final boolean explicit; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8344 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8345 | // For printing. |
| 8346 | String stringName; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8347 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8348 | // If this is an AppWindowToken, this is non-null. |
| 8349 | AppWindowToken appWindowToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8350 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8351 | // All of the windows associated with this token. |
| 8352 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 8353 | |
| 8354 | // Is key dispatching paused for this token? |
| 8355 | boolean paused = false; |
| 8356 | |
| 8357 | // Should this token's windows be hidden? |
| 8358 | boolean hidden; |
| 8359 | |
| 8360 | // Temporary for finding which tokens no longer have visible windows. |
| 8361 | boolean hasVisible; |
| 8362 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8363 | // Set to true when this token is in a pending transaction where it |
| 8364 | // will be shown. |
| 8365 | boolean waitingToShow; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8366 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8367 | // Set to true when this token is in a pending transaction where it |
| 8368 | // will be hidden. |
| 8369 | boolean waitingToHide; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8370 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8371 | // Set to true when this token is in a pending transaction where its |
| 8372 | // windows will be put to the bottom of the list. |
| 8373 | boolean sendingToBottom; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8374 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8375 | // Set to true when this token is in a pending transaction where its |
| 8376 | // windows will be put to the top of the list. |
| 8377 | boolean sendingToTop; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8378 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8379 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 8380 | token = _token; |
| 8381 | windowType = type; |
| 8382 | explicit = _explicit; |
| 8383 | } |
| 8384 | |
| 8385 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8386 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 8387 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 8388 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 8389 | pw.print(" hidden="); pw.print(hidden); |
| 8390 | pw.print(" hasVisible="); pw.println(hasVisible); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8391 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 8392 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 8393 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 8394 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 8395 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 8396 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8397 | } |
| 8398 | |
| 8399 | @Override |
| 8400 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8401 | if (stringName == null) { |
| 8402 | StringBuilder sb = new StringBuilder(); |
| 8403 | sb.append("WindowToken{"); |
| 8404 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8405 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8406 | stringName = sb.toString(); |
| 8407 | } |
| 8408 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8409 | } |
| 8410 | }; |
| 8411 | |
| 8412 | class AppWindowToken extends WindowToken { |
| 8413 | // Non-null only for application tokens. |
| 8414 | final IApplicationToken appToken; |
| 8415 | |
| 8416 | // All of the windows and child windows that are included in this |
| 8417 | // application token. Note this list is NOT sorted! |
| 8418 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 8419 | |
| 8420 | int groupId = -1; |
| 8421 | boolean appFullscreen; |
| 8422 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8423 | |
| 8424 | // The input dispatching timeout for this application token in nanoseconds. |
| 8425 | long inputDispatchingTimeoutNanos; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8426 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8427 | // These are used for determining when all windows associated with |
| 8428 | // an activity have been drawn, so they can be made visible together |
| 8429 | // at the same time. |
| 8430 | int lastTransactionSequence = mTransactionSequence-1; |
| 8431 | int numInterestingWindows; |
| 8432 | int numDrawnWindows; |
| 8433 | boolean inPendingTransaction; |
| 8434 | boolean allDrawn; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8435 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8436 | // Is this token going to be hidden in a little while? If so, it |
| 8437 | // won't be taken into account for setting the screen orientation. |
| 8438 | boolean willBeHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8439 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8440 | // Is this window's surface needed? This is almost like hidden, except |
| 8441 | // it will sometimes be true a little earlier: when the token has |
| 8442 | // been shown, but is still waiting for its app transition to execute |
| 8443 | // before making its windows shown. |
| 8444 | boolean hiddenRequested; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8445 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8446 | // Have we told the window clients to hide themselves? |
| 8447 | boolean clientHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8448 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8449 | // Last visibility state we reported to the app token. |
| 8450 | boolean reportedVisible; |
| 8451 | |
| 8452 | // Set to true when the token has been removed from the window mgr. |
| 8453 | boolean removed; |
| 8454 | |
| 8455 | // Have we been asked to have this token keep the screen frozen? |
| 8456 | boolean freezingScreen; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8457 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8458 | boolean animating; |
| 8459 | Animation animation; |
| 8460 | boolean hasTransformation; |
| 8461 | final Transformation transformation = new Transformation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8462 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8463 | // Offset to the window of all layers in the token, for use by |
| 8464 | // AppWindowToken animations. |
| 8465 | int animLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8466 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8467 | // Information about an application starting window if displayed. |
| 8468 | StartingData startingData; |
| 8469 | WindowState startingWindow; |
| 8470 | View startingView; |
| 8471 | boolean startingDisplayed; |
| 8472 | boolean startingMoved; |
| 8473 | boolean firstWindowDrawn; |
| 8474 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 8475 | // Input application handle used by the input dispatcher. |
| 8476 | InputApplicationHandle mInputApplicationHandle; |
| 8477 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8478 | AppWindowToken(IApplicationToken _token) { |
| 8479 | super(_token.asBinder(), |
| 8480 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 8481 | appWindowToken = this; |
| 8482 | appToken = _token; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 8483 | mInputApplicationHandle = new InputApplicationHandle(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8484 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8485 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8486 | public void setAnimation(Animation anim) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8487 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8488 | TAG, "Setting animation in " + this + ": " + anim); |
| 8489 | animation = anim; |
| 8490 | animating = false; |
| 8491 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 8492 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 8493 | int zorder = anim.getZAdjustment(); |
| 8494 | int adj = 0; |
| 8495 | if (zorder == Animation.ZORDER_TOP) { |
| 8496 | adj = TYPE_LAYER_OFFSET; |
| 8497 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 8498 | adj = -TYPE_LAYER_OFFSET; |
| 8499 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8500 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8501 | if (animLayerAdjustment != adj) { |
| 8502 | animLayerAdjustment = adj; |
| 8503 | updateLayers(); |
| 8504 | } |
| 8505 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8506 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8507 | public void setDummyAnimation() { |
| 8508 | if (animation == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8509 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8510 | TAG, "Setting dummy animation in " + this); |
| 8511 | animation = sDummyAnimation; |
| 8512 | } |
| 8513 | } |
| 8514 | |
| 8515 | public void clearAnimation() { |
| 8516 | if (animation != null) { |
| 8517 | animation = null; |
| 8518 | animating = true; |
| 8519 | } |
| 8520 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8521 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8522 | void updateLayers() { |
| 8523 | final int N = allAppWindows.size(); |
| 8524 | final int adj = animLayerAdjustment; |
| 8525 | for (int i=0; i<N; i++) { |
| 8526 | WindowState w = allAppWindows.get(i); |
| 8527 | w.mAnimLayer = w.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8528 | if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8529 | + w.mAnimLayer); |
| 8530 | if (w == mInputMethodTarget) { |
| 8531 | setInputMethodAnimLayerAdjustment(adj); |
| 8532 | } |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8533 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8534 | setWallpaperAnimLayerAdjustmentLocked(adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8535 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8536 | } |
| 8537 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8538 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8539 | void sendAppVisibilityToClients() { |
| 8540 | final int N = allAppWindows.size(); |
| 8541 | for (int i=0; i<N; i++) { |
| 8542 | WindowState win = allAppWindows.get(i); |
| 8543 | if (win == startingWindow && clientHidden) { |
| 8544 | // Don't hide the starting window. |
| 8545 | continue; |
| 8546 | } |
| 8547 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8548 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8549 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 8550 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 8551 | } catch (RemoteException e) { |
| 8552 | } |
| 8553 | } |
| 8554 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8555 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8556 | void showAllWindowsLocked() { |
| 8557 | final int NW = allAppWindows.size(); |
| 8558 | for (int i=0; i<NW; i++) { |
| 8559 | WindowState w = allAppWindows.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8560 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8561 | "performing show on: " + w); |
| 8562 | w.performShowLocked(); |
| 8563 | } |
| 8564 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8565 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8566 | // This must be called while inside a transaction. |
| 8567 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8568 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8569 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8570 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8571 | if (animation == sDummyAnimation) { |
| 8572 | // This guy is going to animate, but not yet. For now count |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8573 | // it as not animating for purposes of scheduling transactions; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8574 | // when it is really time to animate, this will be set to |
| 8575 | // a real animation and the next call will execute normally. |
| 8576 | return false; |
| 8577 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8578 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8579 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 8580 | if (!animating) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8581 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8582 | TAG, "Starting animation in " + this + |
| 8583 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 8584 | + " scale=" + mTransitionAnimationScale |
| 8585 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 8586 | animation.initialize(dw, dh, dw, dh); |
| 8587 | animation.setStartTime(currentTime); |
| 8588 | animating = true; |
| 8589 | } |
| 8590 | transformation.clear(); |
| 8591 | final boolean more = animation.getTransformation( |
| 8592 | currentTime, transformation); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8593 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8594 | TAG, "Stepped animation in " + this + |
| 8595 | ": more=" + more + ", xform=" + transformation); |
| 8596 | if (more) { |
| 8597 | // we're done! |
| 8598 | hasTransformation = true; |
| 8599 | return true; |
| 8600 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8601 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8602 | TAG, "Finished animation in " + this + |
| 8603 | " @ " + currentTime); |
| 8604 | animation = null; |
| 8605 | } |
| 8606 | } else if (animation != null) { |
| 8607 | // If the display is frozen, and there is a pending animation, |
| 8608 | // clear it and make sure we run the cleanup code. |
| 8609 | animating = true; |
| 8610 | animation = null; |
| 8611 | } |
| 8612 | |
| 8613 | hasTransformation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8614 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8615 | if (!animating) { |
| 8616 | return false; |
| 8617 | } |
| 8618 | |
| 8619 | clearAnimation(); |
| 8620 | animating = false; |
| 8621 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 8622 | moveInputMethodWindowsIfNeededLocked(true); |
| 8623 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8624 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8625 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8626 | TAG, "Animation done in " + this |
| 8627 | + ": reportedVisible=" + reportedVisible); |
| 8628 | |
| 8629 | transformation.clear(); |
| 8630 | if (animLayerAdjustment != 0) { |
| 8631 | animLayerAdjustment = 0; |
| 8632 | updateLayers(); |
| 8633 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8634 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8635 | final int N = windows.size(); |
| 8636 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8637 | windows.get(i).finishExit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8638 | } |
| 8639 | updateReportedVisibilityLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8640 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8641 | return false; |
| 8642 | } |
| 8643 | |
| 8644 | void updateReportedVisibilityLocked() { |
| 8645 | if (appToken == null) { |
| 8646 | return; |
| 8647 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8648 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8649 | int numInteresting = 0; |
| 8650 | int numVisible = 0; |
| 8651 | boolean nowGone = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8652 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8653 | 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] | 8654 | final int N = allAppWindows.size(); |
| 8655 | for (int i=0; i<N; i++) { |
| 8656 | WindowState win = allAppWindows.get(i); |
Dianne Hackborn | 6cf67fa | 2009-12-21 16:46:34 -0800 | [diff] [blame] | 8657 | if (win == startingWindow || win.mAppFreezing |
The Android Open Source Project | 727cec0 | 2010-04-08 11:35:37 -0700 | [diff] [blame] | 8658 | || win.mViewVisibility != View.VISIBLE |
Ulf Rosdahl | 3935770 | 2010-09-29 12:34:38 +0200 | [diff] [blame] | 8659 | || win.mAttrs.type == TYPE_APPLICATION_STARTING |
| 8660 | || win.mDestroying) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8661 | continue; |
| 8662 | } |
| 8663 | if (DEBUG_VISIBILITY) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8664 | Slog.v(TAG, "Win " + win + ": isDrawn=" |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8665 | + win.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8666 | + ", isAnimating=" + win.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8667 | if (!win.isDrawnLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8668 | Slog.v(TAG, "Not displayed: s=" + win.mSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8669 | + " pv=" + win.mPolicyVisibility |
| 8670 | + " dp=" + win.mDrawPending |
| 8671 | + " cdp=" + win.mCommitDrawPending |
| 8672 | + " ah=" + win.mAttachedHidden |
| 8673 | + " th=" |
| 8674 | + (win.mAppToken != null |
| 8675 | ? win.mAppToken.hiddenRequested : false) |
| 8676 | + " a=" + win.mAnimating); |
| 8677 | } |
| 8678 | } |
| 8679 | numInteresting++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8680 | if (win.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8681 | if (!win.isAnimating()) { |
| 8682 | numVisible++; |
| 8683 | } |
| 8684 | nowGone = false; |
| 8685 | } else if (win.isAnimating()) { |
| 8686 | nowGone = false; |
| 8687 | } |
| 8688 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8689 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8690 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8691 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8692 | + numInteresting + " visible=" + numVisible); |
| 8693 | if (nowVisible != reportedVisible) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8694 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8695 | TAG, "Visibility changed in " + this |
| 8696 | + ": vis=" + nowVisible); |
| 8697 | reportedVisible = nowVisible; |
| 8698 | Message m = mH.obtainMessage( |
| 8699 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 8700 | nowVisible ? 1 : 0, |
| 8701 | nowGone ? 1 : 0, |
| 8702 | this); |
| 8703 | mH.sendMessage(m); |
| 8704 | } |
| 8705 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8706 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8707 | WindowState findMainWindow() { |
| 8708 | int j = windows.size(); |
| 8709 | while (j > 0) { |
| 8710 | j--; |
| 8711 | WindowState win = windows.get(j); |
| 8712 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 8713 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 8714 | return win; |
| 8715 | } |
| 8716 | } |
| 8717 | return null; |
| 8718 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8719 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8720 | void dump(PrintWriter pw, String prefix) { |
| 8721 | super.dump(pw, prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8722 | if (appToken != null) { |
| 8723 | pw.print(prefix); pw.println("app=true"); |
| 8724 | } |
| 8725 | if (allAppWindows.size() > 0) { |
| 8726 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 8727 | } |
| 8728 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8729 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8730 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 8731 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 8732 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 8733 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 8734 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 8735 | if (paused || freezingScreen) { |
| 8736 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 8737 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 8738 | } |
| 8739 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 8740 | || inPendingTransaction || allDrawn) { |
| 8741 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 8742 | pw.print(numInterestingWindows); |
| 8743 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 8744 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 8745 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 8746 | } |
| 8747 | if (animating || animation != null) { |
| 8748 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 8749 | pw.print(" animation="); pw.println(animation); |
| 8750 | } |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 8751 | if (hasTransformation) { |
| 8752 | pw.print(prefix); pw.print("XForm: "); |
| 8753 | transformation.printShortString(pw); |
| 8754 | pw.println(); |
| 8755 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8756 | if (animLayerAdjustment != 0) { |
| 8757 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 8758 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8759 | if (startingData != null || removed || firstWindowDrawn) { |
| 8760 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 8761 | pw.print(" removed="); pw.print(removed); |
| 8762 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 8763 | } |
| 8764 | if (startingWindow != null || startingView != null |
| 8765 | || startingDisplayed || startingMoved) { |
| 8766 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 8767 | pw.print(" startingView="); pw.print(startingView); |
| 8768 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 8769 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 8770 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8771 | } |
| 8772 | |
| 8773 | @Override |
| 8774 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8775 | if (stringName == null) { |
| 8776 | StringBuilder sb = new StringBuilder(); |
| 8777 | sb.append("AppWindowToken{"); |
| 8778 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8779 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8780 | stringName = sb.toString(); |
| 8781 | } |
| 8782 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8783 | } |
| 8784 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8785 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8786 | // ------------------------------------------------------------- |
| 8787 | // DummyAnimation |
| 8788 | // ------------------------------------------------------------- |
| 8789 | |
| 8790 | // This is an animation that does nothing: it just immediately finishes |
| 8791 | // itself every time it is called. It is used as a stub animation in cases |
| 8792 | // where we want to synchronize multiple things that may be animating. |
| 8793 | static final class DummyAnimation extends Animation { |
| 8794 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 8795 | return false; |
| 8796 | } |
| 8797 | } |
| 8798 | static final Animation sDummyAnimation = new DummyAnimation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8799 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8800 | // ------------------------------------------------------------- |
| 8801 | // Async Handler |
| 8802 | // ------------------------------------------------------------- |
| 8803 | |
| 8804 | static final class StartingData { |
| 8805 | final String pkg; |
| 8806 | final int theme; |
| 8807 | final CharSequence nonLocalizedLabel; |
| 8808 | final int labelRes; |
| 8809 | final int icon; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 8810 | final int windowFlags; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8811 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8812 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 8813 | int _labelRes, int _icon, int _windowFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8814 | pkg = _pkg; |
| 8815 | theme = _theme; |
| 8816 | nonLocalizedLabel = _nonLocalizedLabel; |
| 8817 | labelRes = _labelRes; |
| 8818 | icon = _icon; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 8819 | windowFlags = _windowFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8820 | } |
| 8821 | } |
| 8822 | |
| 8823 | private final class H extends Handler { |
| 8824 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 8825 | public static final int REPORT_LOSING_FOCUS = 3; |
| 8826 | public static final int ANIMATE = 4; |
| 8827 | public static final int ADD_STARTING = 5; |
| 8828 | public static final int REMOVE_STARTING = 6; |
| 8829 | public static final int FINISHED_STARTING = 7; |
| 8830 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8831 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 8832 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 8833 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 8834 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 8835 | public static final int FORCE_GC = 15; |
| 8836 | public static final int ENABLE_SCREEN = 16; |
| 8837 | public static final int APP_FREEZE_TIMEOUT = 17; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8838 | public static final int SEND_NEW_CONFIGURATION = 18; |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8839 | public static final int REPORT_WINDOWS_CHANGE = 19; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8840 | public static final int DRAG_START_TIMEOUT = 20; |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 8841 | public static final int DRAG_END_TIMEOUT = 21; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8842 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8843 | private Session mLastReportedHold; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8844 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8845 | public H() { |
| 8846 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8847 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8848 | @Override |
| 8849 | public void handleMessage(Message msg) { |
| 8850 | switch (msg.what) { |
| 8851 | case REPORT_FOCUS_CHANGE: { |
| 8852 | WindowState lastFocus; |
| 8853 | WindowState newFocus; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8854 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8855 | synchronized(mWindowMap) { |
| 8856 | lastFocus = mLastFocus; |
| 8857 | newFocus = mCurrentFocus; |
| 8858 | if (lastFocus == newFocus) { |
| 8859 | // Focus is not changing, so nothing to do. |
| 8860 | return; |
| 8861 | } |
| 8862 | mLastFocus = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8863 | //Slog.i(TAG, "Focus moving from " + lastFocus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8864 | // + " to " + newFocus); |
| 8865 | if (newFocus != null && lastFocus != null |
| 8866 | && !newFocus.isDisplayedLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8867 | //Slog.i(TAG, "Delaying loss of focus..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8868 | mLosingFocus.add(lastFocus); |
| 8869 | lastFocus = null; |
| 8870 | } |
| 8871 | } |
| 8872 | |
| 8873 | if (lastFocus != newFocus) { |
| 8874 | //System.out.println("Changing focus from " + lastFocus |
| 8875 | // + " to " + newFocus); |
| 8876 | if (newFocus != null) { |
| 8877 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8878 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8879 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 8880 | } catch (RemoteException e) { |
| 8881 | // Ignore if process has died. |
| 8882 | } |
Konstantin Lopyrev | 5e7833a | 2010-08-09 17:01:11 -0700 | [diff] [blame] | 8883 | notifyFocusChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8884 | } |
| 8885 | |
| 8886 | if (lastFocus != null) { |
| 8887 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8888 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8889 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 8890 | } catch (RemoteException e) { |
| 8891 | // Ignore if process has died. |
| 8892 | } |
| 8893 | } |
| 8894 | } |
| 8895 | } break; |
| 8896 | |
| 8897 | case REPORT_LOSING_FOCUS: { |
| 8898 | ArrayList<WindowState> losers; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8899 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8900 | synchronized(mWindowMap) { |
| 8901 | losers = mLosingFocus; |
| 8902 | mLosingFocus = new ArrayList<WindowState>(); |
| 8903 | } |
| 8904 | |
| 8905 | final int N = losers.size(); |
| 8906 | for (int i=0; i<N; i++) { |
| 8907 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8908 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8909 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 8910 | } catch (RemoteException e) { |
| 8911 | // Ignore if process has died. |
| 8912 | } |
| 8913 | } |
| 8914 | } break; |
| 8915 | |
| 8916 | case ANIMATE: { |
| 8917 | synchronized(mWindowMap) { |
| 8918 | mAnimationPending = false; |
| 8919 | performLayoutAndPlaceSurfacesLocked(); |
| 8920 | } |
| 8921 | } break; |
| 8922 | |
| 8923 | case ADD_STARTING: { |
| 8924 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8925 | final StartingData sd = wtoken.startingData; |
| 8926 | |
| 8927 | if (sd == null) { |
| 8928 | // Animation has been canceled... do nothing. |
| 8929 | return; |
| 8930 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8931 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8932 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8933 | + wtoken + ": pkg=" + sd.pkg); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8934 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8935 | View view = null; |
| 8936 | try { |
| 8937 | view = mPolicy.addStartingWindow( |
| 8938 | wtoken.token, sd.pkg, |
| 8939 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 8940 | sd.icon, sd.windowFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8941 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8942 | Slog.w(TAG, "Exception when adding starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8943 | } |
| 8944 | |
| 8945 | if (view != null) { |
| 8946 | boolean abort = false; |
| 8947 | |
| 8948 | synchronized(mWindowMap) { |
| 8949 | if (wtoken.removed || wtoken.startingData == null) { |
| 8950 | // If the window was successfully added, then |
| 8951 | // we need to remove it. |
| 8952 | if (wtoken.startingWindow != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8953 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8954 | "Aborted starting " + wtoken |
| 8955 | + ": removed=" + wtoken.removed |
| 8956 | + " startingData=" + wtoken.startingData); |
| 8957 | wtoken.startingWindow = null; |
| 8958 | wtoken.startingData = null; |
| 8959 | abort = true; |
| 8960 | } |
| 8961 | } else { |
| 8962 | wtoken.startingView = view; |
| 8963 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8964 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8965 | "Added starting " + wtoken |
| 8966 | + ": startingWindow=" |
| 8967 | + wtoken.startingWindow + " startingView=" |
| 8968 | + wtoken.startingView); |
| 8969 | } |
| 8970 | |
| 8971 | if (abort) { |
| 8972 | try { |
| 8973 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 8974 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8975 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8976 | } |
| 8977 | } |
| 8978 | } |
| 8979 | } break; |
| 8980 | |
| 8981 | case REMOVE_STARTING: { |
| 8982 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8983 | IBinder token = null; |
| 8984 | View view = null; |
| 8985 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8986 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8987 | + wtoken + ": startingWindow=" |
| 8988 | + wtoken.startingWindow + " startingView=" |
| 8989 | + wtoken.startingView); |
| 8990 | if (wtoken.startingWindow != null) { |
| 8991 | view = wtoken.startingView; |
| 8992 | token = wtoken.token; |
| 8993 | wtoken.startingData = null; |
| 8994 | wtoken.startingView = null; |
| 8995 | wtoken.startingWindow = null; |
| 8996 | } |
| 8997 | } |
| 8998 | if (view != null) { |
| 8999 | try { |
| 9000 | mPolicy.removeStartingWindow(token, view); |
| 9001 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9002 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9003 | } |
| 9004 | } |
| 9005 | } break; |
| 9006 | |
| 9007 | case FINISHED_STARTING: { |
| 9008 | IBinder token = null; |
| 9009 | View view = null; |
| 9010 | while (true) { |
| 9011 | synchronized (mWindowMap) { |
| 9012 | final int N = mFinishedStarting.size(); |
| 9013 | if (N <= 0) { |
| 9014 | break; |
| 9015 | } |
| 9016 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 9017 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9018 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9019 | "Finished starting " + wtoken |
| 9020 | + ": startingWindow=" + wtoken.startingWindow |
| 9021 | + " startingView=" + wtoken.startingView); |
| 9022 | |
| 9023 | if (wtoken.startingWindow == null) { |
| 9024 | continue; |
| 9025 | } |
| 9026 | |
| 9027 | view = wtoken.startingView; |
| 9028 | token = wtoken.token; |
| 9029 | wtoken.startingData = null; |
| 9030 | wtoken.startingView = null; |
| 9031 | wtoken.startingWindow = null; |
| 9032 | } |
| 9033 | |
| 9034 | try { |
| 9035 | mPolicy.removeStartingWindow(token, view); |
| 9036 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9037 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9038 | } |
| 9039 | } |
| 9040 | } break; |
| 9041 | |
| 9042 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 9043 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 9044 | |
| 9045 | boolean nowVisible = msg.arg1 != 0; |
| 9046 | boolean nowGone = msg.arg2 != 0; |
| 9047 | |
| 9048 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9049 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9050 | TAG, "Reporting visible in " + wtoken |
| 9051 | + " visible=" + nowVisible |
| 9052 | + " gone=" + nowGone); |
| 9053 | if (nowVisible) { |
| 9054 | wtoken.appToken.windowsVisible(); |
| 9055 | } else { |
| 9056 | wtoken.appToken.windowsGone(); |
| 9057 | } |
| 9058 | } catch (RemoteException ex) { |
| 9059 | } |
| 9060 | } break; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9061 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9062 | case WINDOW_FREEZE_TIMEOUT: { |
| 9063 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9064 | Slog.w(TAG, "Window freeze timeout expired."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9065 | int i = mWindows.size(); |
| 9066 | while (i > 0) { |
| 9067 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9068 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9069 | if (w.mOrientationChanging) { |
| 9070 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9071 | Slog.w(TAG, "Force clearing orientation change: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9072 | } |
| 9073 | } |
| 9074 | performLayoutAndPlaceSurfacesLocked(); |
| 9075 | } |
| 9076 | break; |
| 9077 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9078 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9079 | case HOLD_SCREEN_CHANGED: { |
| 9080 | Session oldHold; |
| 9081 | Session newHold; |
| 9082 | synchronized (mWindowMap) { |
| 9083 | oldHold = mLastReportedHold; |
| 9084 | newHold = (Session)msg.obj; |
| 9085 | mLastReportedHold = newHold; |
| 9086 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9087 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9088 | if (oldHold != newHold) { |
| 9089 | try { |
| 9090 | if (oldHold != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9091 | mBatteryStats.noteStopWakelock(oldHold.mUid, -1, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9092 | "window", |
| 9093 | BatteryStats.WAKE_TYPE_WINDOW); |
| 9094 | } |
| 9095 | if (newHold != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9096 | mBatteryStats.noteStartWakelock(newHold.mUid, -1, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9097 | "window", |
| 9098 | BatteryStats.WAKE_TYPE_WINDOW); |
| 9099 | } |
| 9100 | } catch (RemoteException e) { |
| 9101 | } |
| 9102 | } |
| 9103 | break; |
| 9104 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9105 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9106 | case APP_TRANSITION_TIMEOUT: { |
| 9107 | synchronized (mWindowMap) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9108 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9109 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9110 | "*** APP TRANSITION TIMEOUT"); |
| 9111 | mAppTransitionReady = true; |
| 9112 | mAppTransitionTimeout = true; |
| 9113 | performLayoutAndPlaceSurfacesLocked(); |
| 9114 | } |
| 9115 | } |
| 9116 | break; |
| 9117 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9118 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9119 | case PERSIST_ANIMATION_SCALE: { |
| 9120 | Settings.System.putFloat(mContext.getContentResolver(), |
| 9121 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 9122 | Settings.System.putFloat(mContext.getContentResolver(), |
| 9123 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 9124 | break; |
| 9125 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9126 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9127 | case FORCE_GC: { |
| 9128 | synchronized(mWindowMap) { |
| 9129 | if (mAnimationPending) { |
| 9130 | // If we are animating, don't do the gc now but |
| 9131 | // delay a bit so we don't interrupt the animation. |
| 9132 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 9133 | 2000); |
| 9134 | return; |
| 9135 | } |
| 9136 | // If we are currently rotating the display, it will |
| 9137 | // schedule a new message when done. |
| 9138 | if (mDisplayFrozen) { |
| 9139 | return; |
| 9140 | } |
| 9141 | mFreezeGcPending = 0; |
| 9142 | } |
| 9143 | Runtime.getRuntime().gc(); |
| 9144 | break; |
| 9145 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9146 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9147 | case ENABLE_SCREEN: { |
| 9148 | performEnableScreen(); |
| 9149 | break; |
| 9150 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9151 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9152 | case APP_FREEZE_TIMEOUT: { |
| 9153 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9154 | Slog.w(TAG, "App freeze timeout expired."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9155 | int i = mAppTokens.size(); |
| 9156 | while (i > 0) { |
| 9157 | i--; |
| 9158 | AppWindowToken tok = mAppTokens.get(i); |
| 9159 | if (tok.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9160 | Slog.w(TAG, "Force clearing freeze: " + tok); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9161 | unsetAppFreezingScreenLocked(tok, true, true); |
| 9162 | } |
| 9163 | } |
| 9164 | } |
| 9165 | break; |
| 9166 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9167 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9168 | case SEND_NEW_CONFIGURATION: { |
| 9169 | removeMessages(SEND_NEW_CONFIGURATION); |
| 9170 | sendNewConfiguration(); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 9171 | break; |
| 9172 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9173 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 9174 | case REPORT_WINDOWS_CHANGE: { |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 9175 | if (mWindowsChanged) { |
| 9176 | synchronized (mWindowMap) { |
| 9177 | mWindowsChanged = false; |
| 9178 | } |
| 9179 | notifyWindowsChanged(); |
| 9180 | } |
| 9181 | break; |
| 9182 | } |
| 9183 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 9184 | case DRAG_START_TIMEOUT: { |
| 9185 | IBinder win = (IBinder)msg.obj; |
| 9186 | if (DEBUG_DRAG) { |
| 9187 | Slog.w(TAG, "Timeout starting drag by win " + win); |
| 9188 | } |
| 9189 | synchronized (mWindowMap) { |
| 9190 | // !!! TODO: ANR the app that has failed to start the drag in time |
| 9191 | if (mDragState != null) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 9192 | mDragState.unregister(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 9193 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 9194 | mInputMonitor.updateInputWindowsLw(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 9195 | mDragState.reset(); |
| 9196 | mDragState = null; |
| 9197 | } |
| 9198 | } |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 9199 | break; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 9200 | } |
| 9201 | |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 9202 | case DRAG_END_TIMEOUT: { |
| 9203 | IBinder win = (IBinder)msg.obj; |
| 9204 | if (DEBUG_DRAG) { |
| 9205 | Slog.w(TAG, "Timeout ending drag to win " + win); |
| 9206 | } |
| 9207 | synchronized (mWindowMap) { |
| 9208 | // !!! TODO: ANR the drag-receiving app |
| 9209 | mDragState.mDragResult = false; |
| 9210 | mDragState.endDragLw(); |
| 9211 | } |
| 9212 | break; |
| 9213 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9214 | } |
| 9215 | } |
| 9216 | } |
| 9217 | |
| 9218 | // ------------------------------------------------------------- |
| 9219 | // IWindowManager API |
| 9220 | // ------------------------------------------------------------- |
| 9221 | |
| 9222 | public IWindowSession openSession(IInputMethodClient client, |
| 9223 | IInputContext inputContext) { |
| 9224 | if (client == null) throw new IllegalArgumentException("null client"); |
| 9225 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 9226 | Session session = new Session(client, inputContext); |
| 9227 | return session; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9228 | } |
| 9229 | |
| 9230 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 9231 | synchronized (mWindowMap) { |
| 9232 | // The focus for the client is the window immediately below |
| 9233 | // where we would place the input method window. |
| 9234 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 9235 | WindowState imFocus; |
| 9236 | if (idx > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9237 | imFocus = mWindows.get(idx-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9238 | if (imFocus != null) { |
| 9239 | if (imFocus.mSession.mClient != null && |
| 9240 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 9241 | return true; |
| 9242 | } |
| 9243 | } |
| 9244 | } |
| 9245 | } |
| 9246 | return false; |
| 9247 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9248 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9249 | // ------------------------------------------------------------- |
| 9250 | // Internals |
| 9251 | // ------------------------------------------------------------- |
| 9252 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9253 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 9254 | boolean throwOnError) { |
| 9255 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9256 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9257 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9258 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 9259 | boolean throwOnError) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9260 | WindowState win = mWindowMap.get(client); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9261 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9262 | TAG, "Looking up client " + client + ": " + win); |
| 9263 | if (win == null) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9264 | RuntimeException ex = new IllegalArgumentException( |
| 9265 | "Requested window " + client + " does not exist"); |
| 9266 | if (throwOnError) { |
| 9267 | throw ex; |
| 9268 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9269 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9270 | return null; |
| 9271 | } |
| 9272 | if (session != null && win.mSession != session) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9273 | RuntimeException ex = new IllegalArgumentException( |
| 9274 | "Requested window " + client + " is in session " + |
| 9275 | win.mSession + ", not " + session); |
| 9276 | if (throwOnError) { |
| 9277 | throw ex; |
| 9278 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9279 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9280 | return null; |
| 9281 | } |
| 9282 | |
| 9283 | return win; |
| 9284 | } |
| 9285 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9286 | final void rebuildAppWindowListLocked() { |
| 9287 | int NW = mWindows.size(); |
| 9288 | int i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9289 | int lastWallpaper = -1; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9290 | int numRemoved = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9291 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9292 | if (mRebuildTmp.length < NW) { |
| 9293 | mRebuildTmp = new WindowState[NW+10]; |
| 9294 | } |
| 9295 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9296 | // First remove all existing app windows. |
| 9297 | i=0; |
| 9298 | while (i < NW) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9299 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9300 | if (w.mAppToken != null) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9301 | WindowState win = mWindows.remove(i); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9302 | win.mRebuilding = true; |
| 9303 | mRebuildTmp[numRemoved] = win; |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 9304 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9305 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9306 | "Rebuild removing window: " + win); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9307 | NW--; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9308 | numRemoved++; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9309 | continue; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9310 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 9311 | && lastWallpaper == i-1) { |
| 9312 | lastWallpaper = i; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9313 | } |
| 9314 | i++; |
| 9315 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9316 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9317 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 9318 | // so skip them before adding app tokens. |
| 9319 | lastWallpaper++; |
| 9320 | i = lastWallpaper; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9321 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9322 | // First add all of the exiting app tokens... these are no longer |
| 9323 | // in the main app list, but still have windows shown. We put them |
| 9324 | // in the back because now that the animation is over we no longer |
| 9325 | // will care about them. |
| 9326 | int NT = mExitingAppTokens.size(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9327 | for (int j=0; j<NT; j++) { |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9328 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 9329 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9330 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9331 | // And add in the still active app tokens in Z order. |
| 9332 | NT = mAppTokens.size(); |
| 9333 | for (int j=0; j<NT; j++) { |
| 9334 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9335 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9336 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9337 | i -= lastWallpaper; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9338 | if (i != numRemoved) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9339 | Slog.w(TAG, "Rebuild removed " + numRemoved |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9340 | + " windows but added " + i); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9341 | for (i=0; i<numRemoved; i++) { |
| 9342 | WindowState ws = mRebuildTmp[i]; |
| 9343 | if (ws.mRebuilding) { |
| 9344 | StringWriter sw = new StringWriter(); |
| 9345 | PrintWriter pw = new PrintWriter(sw); |
| 9346 | ws.dump(pw, ""); |
| 9347 | pw.flush(); |
| 9348 | Slog.w(TAG, "This window was lost: " + ws); |
| 9349 | Slog.w(TAG, sw.toString()); |
| 9350 | } |
| 9351 | } |
| 9352 | Slog.w(TAG, "Current app token list:"); |
| 9353 | dumpAppTokensLocked(); |
| 9354 | Slog.w(TAG, "Final window list:"); |
| 9355 | dumpWindowsLocked(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9356 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9357 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9358 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9359 | private final void assignLayersLocked() { |
| 9360 | int N = mWindows.size(); |
| 9361 | int curBaseLayer = 0; |
| 9362 | int curLayer = 0; |
| 9363 | int i; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9364 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9365 | if (DEBUG_LAYERS) { |
| 9366 | RuntimeException here = new RuntimeException("here"); |
| 9367 | here.fillInStackTrace(); |
| 9368 | Log.v(TAG, "Assigning layers", here); |
| 9369 | } |
| 9370 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9371 | for (i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9372 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9373 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 9374 | || (i > 0 && w.mIsWallpaper)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9375 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 9376 | w.mLayer = curLayer; |
| 9377 | } else { |
| 9378 | curBaseLayer = curLayer = w.mBaseLayer; |
| 9379 | w.mLayer = curLayer; |
| 9380 | } |
| 9381 | if (w.mTargetAppToken != null) { |
| 9382 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 9383 | } else if (w.mAppToken != null) { |
| 9384 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 9385 | } else { |
| 9386 | w.mAnimLayer = w.mLayer; |
| 9387 | } |
| 9388 | if (w.mIsImWindow) { |
| 9389 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 9390 | } else if (w.mIsWallpaper) { |
| 9391 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9392 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9393 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9394 | + w.mAnimLayer); |
| 9395 | //System.out.println( |
| 9396 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 9397 | } |
| 9398 | } |
| 9399 | |
| 9400 | private boolean mInLayout = false; |
| 9401 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 9402 | if (mInLayout) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 9403 | if (DEBUG) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9404 | throw new RuntimeException("Recursive call!"); |
| 9405 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9406 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9407 | return; |
| 9408 | } |
| 9409 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9410 | if (mWaitingForConfig) { |
| 9411 | // Our configuration has changed (most likely rotation), but we |
| 9412 | // don't yet have the complete configuration to report to |
| 9413 | // applications. Don't do any window layout until we have it. |
| 9414 | return; |
| 9415 | } |
| 9416 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9417 | if (mDisplay == null) { |
| 9418 | // Not yet initialized, nothing to do. |
| 9419 | return; |
| 9420 | } |
| 9421 | |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 9422 | mInLayout = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9423 | boolean recoveringMemory = false; |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 9424 | |
| 9425 | try { |
| 9426 | if (mForceRemoves != null) { |
| 9427 | recoveringMemory = true; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9428 | // Wait a little bit for things to settle down, and off we go. |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 9429 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 9430 | WindowState ws = mForceRemoves.get(i); |
| 9431 | Slog.i(TAG, "Force removing: " + ws); |
| 9432 | removeWindowInnerLocked(ws.mSession, ws); |
| 9433 | } |
| 9434 | mForceRemoves = null; |
| 9435 | Slog.w(TAG, "Due to memory failure, waiting a bit for next layout"); |
| 9436 | Object tmp = new Object(); |
| 9437 | synchronized (tmp) { |
| 9438 | try { |
| 9439 | tmp.wait(250); |
| 9440 | } catch (InterruptedException e) { |
| 9441 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9442 | } |
| 9443 | } |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 9444 | } catch (RuntimeException e) { |
| 9445 | Slog.e(TAG, "Unhandled exception while force removing for memory", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9446 | } |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 9447 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9448 | try { |
| 9449 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9450 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9451 | int N = mPendingRemove.size(); |
| 9452 | if (N > 0) { |
| 9453 | if (mPendingRemoveTmp.length < N) { |
| 9454 | mPendingRemoveTmp = new WindowState[N+10]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9455 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9456 | mPendingRemove.toArray(mPendingRemoveTmp); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9457 | mPendingRemove.clear(); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9458 | for (int i=0; i<N; i++) { |
| 9459 | WindowState w = mPendingRemoveTmp[i]; |
| 9460 | removeWindowInnerLocked(w.mSession, w); |
| 9461 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9462 | |
| 9463 | mInLayout = false; |
| 9464 | assignLayersLocked(); |
| 9465 | mLayoutNeeded = true; |
| 9466 | performLayoutAndPlaceSurfacesLocked(); |
| 9467 | |
| 9468 | } else { |
| 9469 | mInLayout = false; |
| 9470 | if (mLayoutNeeded) { |
| 9471 | requestAnimationLocked(0); |
| 9472 | } |
| 9473 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 9474 | if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) { |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 9475 | mH.removeMessages(H.REPORT_WINDOWS_CHANGE); |
| 9476 | mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE)); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 9477 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9478 | } catch (RuntimeException e) { |
| 9479 | mInLayout = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9480 | 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] | 9481 | } |
| 9482 | } |
| 9483 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 9484 | private final int performLayoutLockedInner(boolean initial, boolean updateInputWindows) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9485 | if (!mLayoutNeeded) { |
| 9486 | return 0; |
| 9487 | } |
| 9488 | |
| 9489 | mLayoutNeeded = false; |
| 9490 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9491 | final int dw = mDisplay.getWidth(); |
| 9492 | final int dh = mDisplay.getHeight(); |
| 9493 | |
| 9494 | final int N = mWindows.size(); |
| 9495 | int i; |
| 9496 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9497 | if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed=" |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 9498 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 9499 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9500 | mPolicy.beginLayoutLw(dw, dh); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9501 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9502 | int seq = mLayoutSeq+1; |
| 9503 | if (seq < 0) seq = 0; |
| 9504 | mLayoutSeq = seq; |
| 9505 | |
| 9506 | // First perform layout of any root windows (not attached |
| 9507 | // to another window). |
| 9508 | int topAttached = -1; |
| 9509 | for (i = N-1; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9510 | WindowState win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9511 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9512 | // Don't do layout of a window if it is not visible, or |
| 9513 | // soon won't be visible, to avoid wasting time and funky |
| 9514 | // changes while a window is animating away. |
| 9515 | final AppWindowToken atoken = win.mAppToken; |
| 9516 | final boolean gone = win.mViewVisibility == View.GONE |
| 9517 | || !win.mRelayoutCalled |
| 9518 | || win.mRootToken.hidden |
| 9519 | || (atoken != null && atoken.hiddenRequested) |
| 9520 | || win.mAttachedHidden |
| 9521 | || win.mExiting || win.mDestroying; |
| 9522 | |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 9523 | if (DEBUG_LAYOUT && !win.mLayoutAttached) { |
| 9524 | Slog.v(TAG, "First pass " + win |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9525 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 9526 | + " mLayoutAttached=" + win.mLayoutAttached); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 9527 | if (gone) Slog.v(TAG, " (mViewVisibility=" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9528 | + win.mViewVisibility + " mRelayoutCalled=" |
| 9529 | + win.mRelayoutCalled + " hidden=" |
| 9530 | + win.mRootToken.hidden + " hiddenRequested=" |
| 9531 | + (atoken != null && atoken.hiddenRequested) |
| 9532 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 9533 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9534 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9535 | // If this view is GONE, then skip it -- keep the current |
| 9536 | // frame, and let the caller know so they can ignore it |
| 9537 | // if they want. (We do the normal layout for INVISIBLE |
| 9538 | // windows, since that means "perform layout as normal, |
| 9539 | // just don't display"). |
| 9540 | if (!gone || !win.mHaveFrame) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9541 | if (!win.mLayoutAttached) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9542 | if (initial) { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 9543 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9544 | win.mContentChanged = false; |
| 9545 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9546 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 9547 | win.mLayoutSeq = seq; |
| 9548 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 9549 | + win.mFrame + " mContainingFrame=" |
| 9550 | + win.mContainingFrame + " mDisplayFrame=" |
| 9551 | + win.mDisplayFrame); |
| 9552 | } else { |
| 9553 | if (topAttached < 0) topAttached = i; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9554 | } |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9555 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9556 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9557 | |
| 9558 | // Now perform layout of attached windows, which usually |
| 9559 | // depend on the position of the window they are attached to. |
| 9560 | // XXX does not deal with windows that are attached to windows |
| 9561 | // that are themselves attached. |
| 9562 | for (i = topAttached; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9563 | WindowState win = mWindows.get(i); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9564 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9565 | if (win.mLayoutAttached) { |
| 9566 | if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win |
| 9567 | + " mHaveFrame=" + win.mHaveFrame |
| 9568 | + " mViewVisibility=" + win.mViewVisibility |
| 9569 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 9570 | // If this view is GONE, then skip it -- keep the current |
| 9571 | // frame, and let the caller know so they can ignore it |
| 9572 | // if they want. (We do the normal layout for INVISIBLE |
| 9573 | // windows, since that means "perform layout as normal, |
| 9574 | // just don't display"). |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9575 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 9576 | || !win.mHaveFrame) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9577 | if (initial) { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 9578 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9579 | win.mContentChanged = false; |
| 9580 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9581 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 9582 | win.mLayoutSeq = seq; |
| 9583 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 9584 | + win.mFrame + " mContainingFrame=" |
| 9585 | + win.mContainingFrame + " mDisplayFrame=" |
| 9586 | + win.mDisplayFrame); |
| 9587 | } |
| 9588 | } |
| 9589 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9590 | |
| 9591 | // Window frames may have changed. Tell the input dispatcher about it. |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 9592 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 9593 | if (updateInputWindows) { |
| 9594 | mInputMonitor.updateInputWindowsLw(); |
| 9595 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9596 | |
| 9597 | return mPolicy.finishLayoutLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9598 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9599 | |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 9600 | // "Something has changed! Let's make it correct now." |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9601 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 9602 | boolean recoveringMemory) { |
Joe Onorato | 34bcebc | 2010-07-07 18:05:01 -0400 | [diff] [blame] | 9603 | if (mDisplay == null) { |
| 9604 | Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay"); |
| 9605 | return; |
| 9606 | } |
| 9607 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9608 | final long currentTime = SystemClock.uptimeMillis(); |
| 9609 | final int dw = mDisplay.getWidth(); |
| 9610 | final int dh = mDisplay.getHeight(); |
| 9611 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9612 | int i; |
| 9613 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9614 | if (mFocusMayChange) { |
| 9615 | mFocusMayChange = false; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 9616 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 9617 | false /*updateInputWindows*/); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9618 | } |
| 9619 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9620 | // Initialize state of exiting tokens. |
| 9621 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9622 | mExitingTokens.get(i).hasVisible = false; |
| 9623 | } |
| 9624 | |
| 9625 | // Initialize state of exiting applications. |
| 9626 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9627 | mExitingAppTokens.get(i).hasVisible = false; |
| 9628 | } |
| 9629 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9630 | boolean orientationChangeComplete = true; |
| 9631 | Session holdScreen = null; |
| 9632 | float screenBrightness = -1; |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9633 | float buttonBrightness = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9634 | boolean focusDisplayed = false; |
| 9635 | boolean animating = false; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9636 | boolean createWatermark = false; |
| 9637 | |
| 9638 | if (mFxSession == null) { |
| 9639 | mFxSession = new SurfaceSession(); |
| 9640 | createWatermark = true; |
| 9641 | } |
| 9642 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 9643 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9644 | |
| 9645 | Surface.openTransaction(); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9646 | |
| 9647 | if (createWatermark) { |
| 9648 | createWatermark(); |
| 9649 | } |
| 9650 | if (mWatermark != null) { |
| 9651 | mWatermark.positionSurface(dw, dh); |
| 9652 | } |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 9653 | if (mStrictModeFlash != null) { |
| 9654 | mStrictModeFlash.positionSurface(dw, dh); |
| 9655 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9656 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9657 | try { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9658 | boolean wallpaperForceHidingChanged = false; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9659 | int repeats = 0; |
| 9660 | int changes = 0; |
| 9661 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9662 | do { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9663 | repeats++; |
| 9664 | if (repeats > 6) { |
| 9665 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 9666 | mLayoutNeeded = false; |
| 9667 | break; |
| 9668 | } |
| 9669 | |
| 9670 | if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER |
| 9671 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG |
| 9672 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) { |
| 9673 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 9674 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 9675 | assignLayersLocked(); |
| 9676 | mLayoutNeeded = true; |
| 9677 | } |
| 9678 | } |
| 9679 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 9680 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 9681 | if (updateOrientationFromAppTokensLocked(true)) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9682 | mLayoutNeeded = true; |
| 9683 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 9684 | } |
| 9685 | } |
| 9686 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 9687 | mLayoutNeeded = true; |
| 9688 | } |
| 9689 | } |
| 9690 | |
| 9691 | // FIRST LOOP: Perform a layout, if needed. |
| 9692 | if (repeats < 4) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 9693 | changes = performLayoutLockedInner(repeats == 0, false /*updateInputWindows*/); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9694 | if (changes != 0) { |
| 9695 | continue; |
| 9696 | } |
| 9697 | } else { |
| 9698 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 9699 | changes = 0; |
| 9700 | } |
| 9701 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9702 | final int transactionSequence = ++mTransactionSequence; |
| 9703 | |
| 9704 | // Update animations of all applications, including those |
| 9705 | // associated with exiting/removed apps |
| 9706 | boolean tokensAnimating = false; |
| 9707 | final int NAT = mAppTokens.size(); |
| 9708 | for (i=0; i<NAT; i++) { |
| 9709 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9710 | tokensAnimating = true; |
| 9711 | } |
| 9712 | } |
| 9713 | final int NEAT = mExitingAppTokens.size(); |
| 9714 | for (i=0; i<NEAT; i++) { |
| 9715 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9716 | tokensAnimating = true; |
| 9717 | } |
| 9718 | } |
| 9719 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9720 | // SECOND LOOP: Execute animations and update visibility of windows. |
| 9721 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9722 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq=" |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9723 | + transactionSequence + " tokensAnimating=" |
| 9724 | + tokensAnimating); |
| 9725 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9726 | animating = tokensAnimating; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9727 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 9728 | if (mScreenRotationAnimation != null) { |
| 9729 | if (mScreenRotationAnimation.isAnimating()) { |
| 9730 | if (mScreenRotationAnimation.stepAnimation(currentTime)) { |
| 9731 | animating = true; |
| 9732 | } else { |
| 9733 | mScreenRotationAnimation = null; |
| 9734 | } |
| 9735 | } |
| 9736 | } |
| 9737 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9738 | boolean tokenMayBeDrawn = false; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9739 | boolean wallpaperMayChange = false; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9740 | boolean forceHiding = false; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9741 | WindowState windowDetachedWallpaper = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9742 | |
| 9743 | mPolicy.beginAnimationLw(dw, dh); |
| 9744 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9745 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9746 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9747 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9748 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9749 | |
| 9750 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9751 | |
| 9752 | if (w.mSurface != null) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9753 | // Take care of the window being ready to display. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9754 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 9755 | if ((w.mAttrs.flags |
| 9756 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9757 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9758 | "First draw done in potential wallpaper target " + w); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9759 | wallpaperMayChange = true; |
| 9760 | } |
| 9761 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9762 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9763 | final boolean wasAnimating = w.mAnimating; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9764 | |
| 9765 | int animDw = dw; |
| 9766 | int animDh = dh; |
| 9767 | |
| 9768 | // If the window has moved due to its containing |
| 9769 | // content frame changing, then we'd like to animate |
| 9770 | // it. The checks here are ordered by what is least |
Joe Onorato | 3fe7f2f | 2010-11-20 13:48:58 -0800 | [diff] [blame] | 9771 | // likely to be true first. |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 9772 | if (w.shouldAnimateMove()) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9773 | // Frame has moved, containing content frame |
| 9774 | // has also moved, and we're not currently animating... |
| 9775 | // let's do something. |
| 9776 | Animation a = AnimationUtils.loadAnimation(mContext, |
| 9777 | com.android.internal.R.anim.window_move_from_decor); |
| 9778 | w.setAnimation(a); |
| 9779 | animDw = w.mLastFrame.left - w.mFrame.left; |
| 9780 | animDh = w.mLastFrame.top - w.mFrame.top; |
| 9781 | } |
| 9782 | |
| 9783 | // Execute animation. |
| 9784 | final boolean nowAnimating = w.stepAnimationLocked(currentTime, |
| 9785 | animDw, animDh); |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9786 | |
| 9787 | // If this window is animating, make a note that we have |
| 9788 | // an animating window and take care of a request to run |
| 9789 | // a detached wallpaper animation. |
| 9790 | if (nowAnimating) { |
| 9791 | if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) { |
| 9792 | windowDetachedWallpaper = w; |
| 9793 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9794 | animating = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9795 | } |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9796 | |
| 9797 | // If this window's app token is running a detached wallpaper |
| 9798 | // animation, make a note so we can ensure the wallpaper is |
| 9799 | // displayed behind it. |
| 9800 | if (w.mAppToken != null && w.mAppToken.animation != null |
| 9801 | && w.mAppToken.animation.getDetachWallpaper()) { |
| 9802 | windowDetachedWallpaper = w; |
| 9803 | } |
| 9804 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9805 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 9806 | wallpaperMayChange = true; |
| 9807 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9808 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9809 | if (mPolicy.doesForceHide(w, attrs)) { |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9810 | if (!wasAnimating && nowAnimating) { |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9811 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9812 | "Animation started that could impact force hide: " |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9813 | + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9814 | wallpaperForceHidingChanged = true; |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9815 | mFocusMayChange = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9816 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 9817 | forceHiding = true; |
| 9818 | } |
| 9819 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9820 | boolean changed; |
| 9821 | if (forceHiding) { |
| 9822 | changed = w.hideLw(false, false); |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9823 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9824 | "Now policy hidden: " + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9825 | } else { |
| 9826 | changed = w.showLw(false, false); |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9827 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9828 | "Now policy shown: " + w); |
| 9829 | if (changed) { |
| 9830 | if (wallpaperForceHidingChanged |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9831 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9832 | // Assume we will need to animate. If |
| 9833 | // we don't (because the wallpaper will |
| 9834 | // stay with the lock screen), then we will |
| 9835 | // clean up later. |
| 9836 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 9837 | if (a != null) { |
| 9838 | w.setAnimation(a); |
| 9839 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9840 | } |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9841 | if (mCurrentFocus == null || |
| 9842 | mCurrentFocus.mLayer < w.mLayer) { |
| 9843 | // We are showing on to of the current |
| 9844 | // focus, so re-evaluate focus to make |
| 9845 | // sure it is correct. |
| 9846 | mFocusMayChange = true; |
| 9847 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9848 | } |
| 9849 | } |
| 9850 | if (changed && (attrs.flags |
| 9851 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 9852 | wallpaperMayChange = true; |
| 9853 | } |
| 9854 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9855 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9856 | mPolicy.animatingWindowLw(w, attrs); |
| 9857 | } |
| 9858 | |
| 9859 | final AppWindowToken atoken = w.mAppToken; |
| 9860 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 9861 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 9862 | atoken.lastTransactionSequence = transactionSequence; |
| 9863 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 9864 | atoken.startingDisplayed = false; |
| 9865 | } |
| 9866 | if ((w.isOnScreen() || w.mAttrs.type |
| 9867 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 9868 | && !w.mExiting && !w.mDestroying) { |
| 9869 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9870 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9871 | + w.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9872 | + ", isAnimating=" + w.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9873 | if (!w.isDrawnLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9874 | Slog.v(TAG, "Not displayed: s=" + w.mSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9875 | + " pv=" + w.mPolicyVisibility |
| 9876 | + " dp=" + w.mDrawPending |
| 9877 | + " cdp=" + w.mCommitDrawPending |
| 9878 | + " ah=" + w.mAttachedHidden |
| 9879 | + " th=" + atoken.hiddenRequested |
| 9880 | + " a=" + w.mAnimating); |
| 9881 | } |
| 9882 | } |
| 9883 | if (w != atoken.startingWindow) { |
| 9884 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 9885 | atoken.numInterestingWindows++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9886 | if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9887 | atoken.numDrawnWindows++; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9888 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9889 | "tokenMayBeDrawn: " + atoken |
| 9890 | + " freezingScreen=" + atoken.freezingScreen |
| 9891 | + " mAppFreezing=" + w.mAppFreezing); |
| 9892 | tokenMayBeDrawn = true; |
| 9893 | } |
| 9894 | } |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9895 | } else if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9896 | atoken.startingDisplayed = true; |
| 9897 | } |
| 9898 | } |
| 9899 | } else if (w.mReadyToShow) { |
| 9900 | w.performShowLocked(); |
| 9901 | } |
| 9902 | } |
| 9903 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9904 | changes |= mPolicy.finishAnimationLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9905 | |
| 9906 | if (tokenMayBeDrawn) { |
| 9907 | // See if any windows have been drawn, so they (and others |
| 9908 | // associated with them) can now be shown. |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9909 | final int NT = mAppTokens.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9910 | for (i=0; i<NT; i++) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9911 | AppWindowToken wtoken = mAppTokens.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9912 | if (wtoken.freezingScreen) { |
| 9913 | int numInteresting = wtoken.numInterestingWindows; |
| 9914 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9915 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9916 | "allDrawn: " + wtoken |
| 9917 | + " interesting=" + numInteresting |
| 9918 | + " drawn=" + wtoken.numDrawnWindows); |
| 9919 | wtoken.showAllWindowsLocked(); |
| 9920 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 9921 | orientationChangeComplete = true; |
| 9922 | } |
| 9923 | } else if (!wtoken.allDrawn) { |
| 9924 | int numInteresting = wtoken.numInterestingWindows; |
| 9925 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9926 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9927 | "allDrawn: " + wtoken |
| 9928 | + " interesting=" + numInteresting |
| 9929 | + " drawn=" + wtoken.numDrawnWindows); |
| 9930 | wtoken.allDrawn = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9931 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9932 | |
| 9933 | // We can now show all of the drawn windows! |
| 9934 | if (!mOpeningApps.contains(wtoken)) { |
| 9935 | wtoken.showAllWindowsLocked(); |
| 9936 | } |
| 9937 | } |
| 9938 | } |
| 9939 | } |
| 9940 | } |
| 9941 | |
| 9942 | // If we are ready to perform an app transition, check through |
| 9943 | // all of the app tokens to be shown and see if they are ready |
| 9944 | // to go. |
| 9945 | if (mAppTransitionReady) { |
| 9946 | int NN = mOpeningApps.size(); |
| 9947 | boolean goodToGo = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9948 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9949 | "Checking " + NN + " opening apps (frozen=" |
| 9950 | + mDisplayFrozen + " timeout=" |
| 9951 | + mAppTransitionTimeout + ")..."); |
| 9952 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 9953 | // If the display isn't frozen, wait to do anything until |
| 9954 | // all of the apps are ready. Otherwise just go because |
| 9955 | // we'll unfreeze the display when everyone is ready. |
| 9956 | for (i=0; i<NN && goodToGo; i++) { |
| 9957 | AppWindowToken wtoken = mOpeningApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9958 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9959 | "Check opening app" + wtoken + ": allDrawn=" |
| 9960 | + wtoken.allDrawn + " startingDisplayed=" |
| 9961 | + wtoken.startingDisplayed); |
| 9962 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 9963 | && !wtoken.startingMoved) { |
| 9964 | goodToGo = false; |
| 9965 | } |
| 9966 | } |
| 9967 | } |
| 9968 | if (goodToGo) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9969 | 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] | 9970 | int transit = mNextAppTransition; |
| 9971 | if (mSkipAppTransitionAnimation) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9972 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9973 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9974 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9975 | mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9976 | mAppTransitionRunning = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9977 | mAppTransitionTimeout = false; |
| 9978 | mStartingIconInTransition = false; |
| 9979 | mSkipAppTransitionAnimation = false; |
| 9980 | |
| 9981 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 9982 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9983 | // If there are applications waiting to come to the |
| 9984 | // top of the stack, now is the time to move their windows. |
| 9985 | // (Note that we don't do apps going to the bottom |
| 9986 | // here -- we want to keep their windows in the old |
| 9987 | // Z-order until the animation completes.) |
| 9988 | if (mToTopApps.size() > 0) { |
| 9989 | NN = mAppTokens.size(); |
| 9990 | for (i=0; i<NN; i++) { |
| 9991 | AppWindowToken wtoken = mAppTokens.get(i); |
| 9992 | if (wtoken.sendingToTop) { |
| 9993 | wtoken.sendingToTop = false; |
| 9994 | moveAppWindowsLocked(wtoken, NN, false); |
| 9995 | } |
| 9996 | } |
| 9997 | mToTopApps.clear(); |
| 9998 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9999 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10000 | WindowState oldWallpaper = mWallpaperTarget; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10001 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 10002 | adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10003 | wallpaperMayChange = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10004 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10005 | // The top-most window will supply the layout params, |
| 10006 | // and we will determine it below. |
| 10007 | LayoutParams animLp = null; |
| 10008 | int bestAnimLayer = -1; |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 10009 | boolean fullscreenAnim = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10010 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10011 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 10012 | "New wallpaper target=" + mWallpaperTarget |
| 10013 | + ", lower target=" + mLowerWallpaperTarget |
| 10014 | + ", upper target=" + mUpperWallpaperTarget); |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10015 | int foundWallpapers = 0; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10016 | // Do a first pass through the tokens for two |
| 10017 | // things: |
| 10018 | // (1) Determine if both the closing and opening |
| 10019 | // app token sets are wallpaper targets, in which |
| 10020 | // case special animations are needed |
| 10021 | // (since the wallpaper needs to stay static |
| 10022 | // behind them). |
| 10023 | // (2) Find the layout params of the top-most |
| 10024 | // application window in the tokens, which is |
| 10025 | // what will control the animation theme. |
| 10026 | final int NC = mClosingApps.size(); |
| 10027 | NN = NC + mOpeningApps.size(); |
| 10028 | for (i=0; i<NN; i++) { |
| 10029 | AppWindowToken wtoken; |
| 10030 | int mode; |
| 10031 | if (i < NC) { |
| 10032 | wtoken = mClosingApps.get(i); |
| 10033 | mode = 1; |
| 10034 | } else { |
| 10035 | wtoken = mOpeningApps.get(i-NC); |
| 10036 | mode = 2; |
| 10037 | } |
| 10038 | if (mLowerWallpaperTarget != null) { |
| 10039 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 10040 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 10041 | foundWallpapers |= mode; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 10042 | } |
| 10043 | } |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10044 | if (wtoken.appFullscreen) { |
| 10045 | WindowState ws = wtoken.findMainWindow(); |
| 10046 | if (ws != null) { |
| 10047 | // If this is a compatibility mode |
| 10048 | // window, we will always use its anim. |
| 10049 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 10050 | animLp = ws.mAttrs; |
| 10051 | bestAnimLayer = Integer.MAX_VALUE; |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 10052 | } else if (!fullscreenAnim || ws.mLayer > bestAnimLayer) { |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10053 | animLp = ws.mAttrs; |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 10054 | bestAnimLayer = ws.mLayer; |
| 10055 | } |
| 10056 | fullscreenAnim = true; |
| 10057 | } |
| 10058 | } else if (!fullscreenAnim) { |
| 10059 | WindowState ws = wtoken.findMainWindow(); |
| 10060 | if (ws != null) { |
| 10061 | if (ws.mLayer > bestAnimLayer) { |
| 10062 | animLp = ws.mAttrs; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10063 | bestAnimLayer = ws.mLayer; |
| 10064 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10065 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 10066 | } |
| 10067 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10068 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10069 | if (foundWallpapers == 3) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10070 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10071 | "Wallpaper animation!"); |
| 10072 | switch (transit) { |
| 10073 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 10074 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 10075 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 10076 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 10077 | break; |
| 10078 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 10079 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 10080 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 10081 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 10082 | break; |
| 10083 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10084 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10085 | "New transit: " + transit); |
| 10086 | } else if (oldWallpaper != null) { |
| 10087 | // We are transitioning from an activity with |
| 10088 | // a wallpaper to one without. |
| 10089 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10090 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10091 | "New transit away from wallpaper: " + transit); |
| 10092 | } else if (mWallpaperTarget != null) { |
| 10093 | // We are transitioning from an activity without |
| 10094 | // a wallpaper to now showing the wallpaper |
| 10095 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10096 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10097 | "New transit into wallpaper: " + transit); |
| 10098 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10099 | |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10100 | // If all closing windows are obscured, then there is |
| 10101 | // no need to do an animation. This is the case, for |
| 10102 | // example, when this transition is being done behind |
| 10103 | // the lock screen. |
| 10104 | if (!mPolicy.allowAppAnimationsLw()) { |
| 10105 | animLp = null; |
| 10106 | } |
| 10107 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10108 | NN = mOpeningApps.size(); |
| 10109 | for (i=0; i<NN; i++) { |
| 10110 | AppWindowToken wtoken = mOpeningApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10111 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10112 | "Now opening app" + wtoken); |
| 10113 | wtoken.reportedVisible = false; |
| 10114 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 10115 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10116 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10117 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10118 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10119 | wtoken.showAllWindowsLocked(); |
| 10120 | } |
| 10121 | NN = mClosingApps.size(); |
| 10122 | for (i=0; i<NN; i++) { |
| 10123 | AppWindowToken wtoken = mClosingApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10124 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10125 | "Now closing app" + wtoken); |
| 10126 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 10127 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10128 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10129 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10130 | wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10131 | // Force the allDrawn flag, because we want to start |
| 10132 | // this guy's animations regardless of whether it's |
| 10133 | // gotten drawn. |
| 10134 | wtoken.allDrawn = true; |
| 10135 | } |
| 10136 | |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 10137 | mNextAppTransitionPackage = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10138 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10139 | mOpeningApps.clear(); |
| 10140 | mClosingApps.clear(); |
| 10141 | |
| 10142 | // This has changed the visibility of windows, so perform |
| 10143 | // a new layout to get them all up-to-date. |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 10144 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT |
| 10145 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10146 | mLayoutNeeded = true; |
Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 10147 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 10148 | assignLayersLocked(); |
| 10149 | } |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 10150 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, |
| 10151 | false /*updateInputWindows*/); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10152 | mFocusMayChange = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10153 | } |
| 10154 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10155 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10156 | int adjResult = 0; |
| 10157 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10158 | if (!animating && mAppTransitionRunning) { |
| 10159 | // We have finished the animation of an app transition. To do |
| 10160 | // this, we have delayed a lot of operations like showing and |
| 10161 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10162 | // reflects the correct Z-order, but the window list may now |
| 10163 | // be out of sync with it. So here we will just rebuild the |
| 10164 | // entire app window list. Fun! |
| 10165 | mAppTransitionRunning = false; |
| 10166 | // Clear information about apps that were moving. |
| 10167 | mToBottomApps.clear(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10168 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10169 | rebuildAppWindowListLocked(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10170 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10171 | adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10172 | moveInputMethodWindowsIfNeededLocked(false); |
| 10173 | wallpaperMayChange = true; |
Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 10174 | // Since the window list has been rebuilt, focus might |
| 10175 | // have to be recomputed since the actual order of windows |
| 10176 | // might have changed again. |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10177 | mFocusMayChange = true; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10178 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10179 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10180 | if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10181 | // At this point, there was a window with a wallpaper that |
| 10182 | // was force hiding other windows behind it, but now it |
| 10183 | // is going away. This may be simple -- just animate |
| 10184 | // away the wallpaper and its window -- or it may be |
| 10185 | // hard -- the wallpaper now needs to be shown behind |
| 10186 | // something that was hidden. |
| 10187 | WindowState oldWallpaper = mWallpaperTarget; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10188 | if (mLowerWallpaperTarget != null |
| 10189 | && mLowerWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10190 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10191 | "wallpaperForceHiding changed with lower=" |
| 10192 | + mLowerWallpaperTarget); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10193 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10194 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 10195 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 10196 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 10197 | // The lower target has become hidden before we |
| 10198 | // actually started the animation... let's completely |
| 10199 | // re-evaluate everything. |
| 10200 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10201 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10202 | } |
| 10203 | } |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10204 | adjResult |= adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10205 | wallpaperMayChange = false; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10206 | wallpaperForceHidingChanged = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10207 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10208 | + " NEW: " + mWallpaperTarget |
| 10209 | + " LOWER: " + mLowerWallpaperTarget); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10210 | if (mLowerWallpaperTarget == null) { |
| 10211 | // Whoops, we don't need a special wallpaper animation. |
| 10212 | // Clear them out. |
| 10213 | forceHiding = false; |
| 10214 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10215 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10216 | if (w.mSurface != null) { |
| 10217 | final WindowManager.LayoutParams attrs = w.mAttrs; |
Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 10218 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10219 | if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10220 | forceHiding = true; |
| 10221 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 10222 | if (!w.mAnimating) { |
| 10223 | // We set the animation above so it |
| 10224 | // is not yet running. |
| 10225 | w.clearAnimation(); |
| 10226 | } |
| 10227 | } |
| 10228 | } |
| 10229 | } |
| 10230 | } |
| 10231 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10232 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 10233 | if (mWindowDetachedWallpaper != windowDetachedWallpaper) { |
| 10234 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 10235 | "Detached wallpaper changed from " + mWindowDetachedWallpaper |
| 10236 | + windowDetachedWallpaper); |
| 10237 | mWindowDetachedWallpaper = windowDetachedWallpaper; |
| 10238 | wallpaperMayChange = true; |
| 10239 | } |
| 10240 | |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10241 | if (wallpaperMayChange) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10242 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10243 | "Wallpaper may change! Adjusting"); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10244 | adjResult |= adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10245 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10246 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10247 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10248 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10249 | "Wallpaper layer changed: assigning layers + relayout"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10250 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10251 | assignLayersLocked(); |
| 10252 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10253 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10254 | "Wallpaper visibility changed: relayout"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10255 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10256 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10257 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10258 | if (mFocusMayChange) { |
| 10259 | mFocusMayChange = false; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 10260 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, |
| 10261 | false /*updateInputWindows*/)) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10262 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10263 | adjResult = 0; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10264 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10265 | } |
| 10266 | |
| 10267 | if (mLayoutNeeded) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10268 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10269 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10270 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10271 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x" |
| 10272 | + Integer.toHexString(changes)); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10273 | } while (changes != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10274 | |
| 10275 | // THIRD LOOP: Update the surfaces of all windows. |
| 10276 | |
| 10277 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 10278 | |
| 10279 | boolean obscured = false; |
| 10280 | boolean blurring = false; |
| 10281 | boolean dimming = false; |
| 10282 | boolean covered = false; |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10283 | boolean syswin = false; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10284 | boolean backgroundFillerShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10285 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 10286 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10287 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10288 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10289 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10290 | |
| 10291 | boolean displayed = false; |
| 10292 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 10293 | final int attrFlags = attrs.flags; |
| 10294 | |
| 10295 | if (w.mSurface != null) { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10296 | // XXX NOTE: The logic here could be improved. We have |
| 10297 | // the decision about whether to resize a window separated |
| 10298 | // from whether to hide the surface. This can cause us to |
| 10299 | // resize a surface even if we are going to hide it. You |
| 10300 | // can see this by (1) holding device in landscape mode on |
| 10301 | // home screen; (2) tapping browser icon (device will rotate |
| 10302 | // to landscape; (3) tap home. The wallpaper will be resized |
| 10303 | // in step 2 but then immediately hidden, causing us to |
| 10304 | // have to resize and then redraw it again in step 3. It |
| 10305 | // would be nice to figure out how to avoid this, but it is |
| 10306 | // difficult because we do need to resize surfaces in some |
| 10307 | // cases while they are hidden such as when first showing a |
| 10308 | // window. |
| 10309 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10310 | w.computeShownFrameLocked(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10311 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10312 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 10313 | + ": new=" + w.mShownFrame + ", old=" |
| 10314 | + w.mLastShownFrame); |
| 10315 | |
| 10316 | boolean resize; |
| 10317 | int width, height; |
| 10318 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 10319 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 10320 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 10321 | // for a scaled surface, we just want to use |
| 10322 | // the requested size. |
| 10323 | width = w.mRequestedWidth; |
| 10324 | height = w.mRequestedHeight; |
| 10325 | w.mLastRequestedWidth = width; |
| 10326 | w.mLastRequestedHeight = height; |
| 10327 | w.mLastShownFrame.set(w.mShownFrame); |
| 10328 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10329 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10330 | "POS " + w.mShownFrame.left |
| 10331 | + ", " + w.mShownFrame.top, null); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10332 | w.mSurfaceX = w.mShownFrame.left; |
| 10333 | w.mSurfaceY = w.mShownFrame.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10334 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 10335 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10336 | Slog.w(TAG, "Error positioning surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10337 | if (!recoveringMemory) { |
| 10338 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 10339 | } |
| 10340 | } |
| 10341 | } else { |
| 10342 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 10343 | width = w.mShownFrame.width(); |
| 10344 | height = w.mShownFrame.height(); |
| 10345 | w.mLastShownFrame.set(w.mShownFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10346 | } |
| 10347 | |
| 10348 | if (resize) { |
| 10349 | if (width < 1) width = 1; |
| 10350 | if (height < 1) height = 1; |
| 10351 | if (w.mSurface != null) { |
| 10352 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10353 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10354 | "POS " + w.mShownFrame.left + "," |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10355 | + w.mShownFrame.top + " SIZE " |
| 10356 | + w.mShownFrame.width() + "x" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10357 | + w.mShownFrame.height(), null); |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10358 | w.mSurfaceResized = true; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10359 | w.mSurfaceW = width; |
| 10360 | w.mSurfaceH = height; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10361 | w.mSurface.setSize(width, height); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10362 | w.mSurfaceX = w.mShownFrame.left; |
| 10363 | w.mSurfaceY = w.mShownFrame.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10364 | w.mSurface.setPosition(w.mShownFrame.left, |
| 10365 | w.mShownFrame.top); |
| 10366 | } catch (RuntimeException e) { |
| 10367 | // If something goes wrong with the surface (such |
| 10368 | // as running out of memory), don't take down the |
| 10369 | // entire system. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10370 | Slog.e(TAG, "Failure updating surface of " + w |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 10371 | + " size=(" + width + "x" + height |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10372 | + "), pos=(" + w.mShownFrame.left |
| 10373 | + "," + w.mShownFrame.top + ")", e); |
| 10374 | if (!recoveringMemory) { |
| 10375 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 10376 | } |
| 10377 | } |
| 10378 | } |
| 10379 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10380 | if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10381 | w.mContentInsetsChanged = |
| 10382 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 10383 | w.mVisibleInsetsChanged = |
| 10384 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10385 | boolean configChanged = |
| 10386 | w.mConfiguration != mCurConfiguration |
| 10387 | && (w.mConfiguration == null |
| 10388 | || mCurConfiguration.diff(w.mConfiguration) != 0); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10389 | if (DEBUG_CONFIGURATION && configChanged) { |
| 10390 | Slog.v(TAG, "Win " + w + " config changed: " |
| 10391 | + mCurConfiguration); |
| 10392 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10393 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10394 | + ": configChanged=" + configChanged |
| 10395 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10396 | if (!w.mLastFrame.equals(w.mFrame) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10397 | || w.mContentInsetsChanged |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10398 | || w.mVisibleInsetsChanged |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10399 | || w.mSurfaceResized |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10400 | || configChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10401 | w.mLastFrame.set(w.mFrame); |
| 10402 | w.mLastContentInsets.set(w.mContentInsets); |
| 10403 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10404 | // If the screen is currently frozen, then keep |
| 10405 | // it frozen until this window draws at its new |
| 10406 | // orientation. |
| 10407 | if (mDisplayFrozen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10408 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10409 | "Resizing while display frozen: " + w); |
| 10410 | w.mOrientationChanging = true; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10411 | if (!mWindowsFreezingScreen) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10412 | mWindowsFreezingScreen = true; |
| 10413 | // XXX should probably keep timeout from |
| 10414 | // when we first froze the display. |
| 10415 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10416 | mH.sendMessageDelayed(mH.obtainMessage( |
| 10417 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 10418 | } |
| 10419 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10420 | // If the orientation is changing, then we need to |
| 10421 | // hold off on unfreezing the display until this |
| 10422 | // window has been redrawn; to do that, we need |
| 10423 | // to go through the process of getting informed |
| 10424 | // by the application when it has finished drawing. |
| 10425 | if (w.mOrientationChanging) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10426 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10427 | "Orientation start waiting for draw in " |
| 10428 | + w + ", surface " + w.mSurface); |
| 10429 | w.mDrawPending = true; |
| 10430 | w.mCommitDrawPending = false; |
| 10431 | w.mReadyToShow = false; |
| 10432 | if (w.mAppToken != null) { |
| 10433 | w.mAppToken.allDrawn = false; |
| 10434 | } |
| 10435 | } |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10436 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10437 | "Resizing window " + w + " to " + w.mFrame); |
| 10438 | mResizingWindows.add(w); |
| 10439 | } else if (w.mOrientationChanging) { |
| 10440 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10441 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10442 | "Orientation not waiting for draw in " |
| 10443 | + w + ", surface " + w.mSurface); |
| 10444 | w.mOrientationChanging = false; |
| 10445 | } |
| 10446 | } |
| 10447 | } |
| 10448 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10449 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10450 | if (!w.mLastHidden) { |
| 10451 | //dump(); |
| 10452 | w.mLastHidden = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10453 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10454 | "HIDE (performLayout)", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10455 | if (w.mSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10456 | w.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10457 | try { |
| 10458 | w.mSurface.hide(); |
| 10459 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10460 | Slog.w(TAG, "Exception hiding surface in " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10461 | } |
| 10462 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10463 | } |
| 10464 | // If we are waiting for this window to handle an |
| 10465 | // orientation change, well, it is hidden, so |
| 10466 | // doesn't really matter. Note that this does |
| 10467 | // introduce a potential glitch if the window |
| 10468 | // becomes unhidden before it has drawn for the |
| 10469 | // new orientation. |
| 10470 | if (w.mOrientationChanging) { |
| 10471 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10472 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10473 | "Orientation change skips hidden " + w); |
| 10474 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10475 | } else if (w.mLastLayer != w.mAnimLayer |
| 10476 | || w.mLastAlpha != w.mShownAlpha |
| 10477 | || w.mLastDsDx != w.mDsDx |
| 10478 | || w.mLastDtDx != w.mDtDx |
| 10479 | || w.mLastDsDy != w.mDsDy |
| 10480 | || w.mLastDtDy != w.mDtDy |
| 10481 | || w.mLastHScale != w.mHScale |
| 10482 | || w.mLastVScale != w.mVScale |
| 10483 | || w.mLastHidden) { |
| 10484 | displayed = true; |
| 10485 | w.mLastAlpha = w.mShownAlpha; |
| 10486 | w.mLastLayer = w.mAnimLayer; |
| 10487 | w.mLastDsDx = w.mDsDx; |
| 10488 | w.mLastDtDx = w.mDtDx; |
| 10489 | w.mLastDsDy = w.mDsDy; |
| 10490 | w.mLastDtDy = w.mDtDy; |
| 10491 | w.mLastHScale = w.mHScale; |
| 10492 | w.mLastVScale = w.mVScale; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10493 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10494 | "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10495 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 10496 | + "," + (w.mDtDx*w.mVScale) |
| 10497 | + "][" + (w.mDsDy*w.mHScale) |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10498 | + "," + (w.mDtDy*w.mVScale) + "]", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10499 | if (w.mSurface != null) { |
| 10500 | try { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10501 | w.mSurfaceAlpha = w.mShownAlpha; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10502 | w.mSurface.setAlpha(w.mShownAlpha); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10503 | w.mSurfaceLayer = w.mAnimLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10504 | w.mSurface.setLayer(w.mAnimLayer); |
| 10505 | w.mSurface.setMatrix( |
| 10506 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 10507 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 10508 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10509 | Slog.w(TAG, "Error updating surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10510 | if (!recoveringMemory) { |
| 10511 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 10512 | } |
| 10513 | } |
| 10514 | } |
| 10515 | |
| 10516 | if (w.mLastHidden && !w.mDrawPending |
| 10517 | && !w.mCommitDrawPending |
| 10518 | && !w.mReadyToShow) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10519 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10520 | "SHOW (performLayout)", null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10521 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10522 | + " during relayout"); |
| 10523 | if (showSurfaceRobustlyLocked(w)) { |
| 10524 | w.mHasDrawn = true; |
| 10525 | w.mLastHidden = false; |
| 10526 | } else { |
| 10527 | w.mOrientationChanging = false; |
| 10528 | } |
| 10529 | } |
| 10530 | if (w.mSurface != null) { |
| 10531 | w.mToken.hasVisible = true; |
| 10532 | } |
| 10533 | } else { |
| 10534 | displayed = true; |
| 10535 | } |
| 10536 | |
| 10537 | if (displayed) { |
| 10538 | if (!covered) { |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 10539 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 10540 | && attrs.height == LayoutParams.MATCH_PARENT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10541 | covered = true; |
| 10542 | } |
| 10543 | } |
| 10544 | if (w.mOrientationChanging) { |
| 10545 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 10546 | orientationChangeComplete = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10547 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10548 | "Orientation continue waiting for draw in " + w); |
| 10549 | } else { |
| 10550 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10551 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10552 | "Orientation change complete in " + w); |
| 10553 | } |
| 10554 | } |
| 10555 | w.mToken.hasVisible = true; |
| 10556 | } |
| 10557 | } else if (w.mOrientationChanging) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10558 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10559 | "Orientation change skips hidden " + w); |
| 10560 | w.mOrientationChanging = false; |
| 10561 | } |
| 10562 | |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 10563 | if (w.mContentChanged) { |
| 10564 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing"); |
| 10565 | w.mContentChanged = false; |
| 10566 | } |
| 10567 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10568 | final boolean canBeSeen = w.isDisplayedLw(); |
| 10569 | |
| 10570 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 10571 | focusDisplayed = true; |
| 10572 | } |
| 10573 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10574 | final boolean obscuredChanged = w.mObscured != obscured; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10575 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10576 | // Update effect. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10577 | if (!(w.mObscured=obscured)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10578 | if (w.mSurface != null) { |
| 10579 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 10580 | holdScreen = w.mSession; |
| 10581 | } |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10582 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 10583 | && screenBrightness < 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10584 | screenBrightness = w.mAttrs.screenBrightness; |
| 10585 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10586 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 10587 | && buttonBrightness < 0) { |
| 10588 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 10589 | } |
Mike Lockwood | 46af6a8 | 2010-03-09 08:28:22 -0500 | [diff] [blame] | 10590 | if (canBeSeen |
| 10591 | && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 10592 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 10593 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) { |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10594 | syswin = true; |
| 10595 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10596 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10597 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10598 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 10599 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10600 | // This window completely covers everything behind it, |
| 10601 | // so we want to leave all of them as unblurred (for |
| 10602 | // performance reasons). |
| 10603 | obscured = true; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10604 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10605 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler"); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10606 | // This window is in compatibility mode, and needs background filler. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10607 | obscured = true; |
| 10608 | if (mBackgroundFillerSurface == null) { |
| 10609 | try { |
| 10610 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10611 | "BackGroundFiller", |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10612 | 0, dw, dh, |
| 10613 | PixelFormat.OPAQUE, |
| 10614 | Surface.FX_SURFACE_NORMAL); |
| 10615 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10616 | Slog.e(TAG, "Exception creating filler surface", e); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10617 | } |
| 10618 | } |
| 10619 | try { |
| 10620 | mBackgroundFillerSurface.setPosition(0, 0); |
| 10621 | mBackgroundFillerSurface.setSize(dw, dh); |
| 10622 | // Using the same layer as Dim because they will never be shown at the |
| 10623 | // same time. |
| 10624 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 10625 | mBackgroundFillerSurface.show(); |
| 10626 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10627 | Slog.e(TAG, "Exception showing filler surface"); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10628 | } |
| 10629 | backgroundFillerShown = true; |
| 10630 | mBackgroundFillerShown = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10631 | } else if (canBeSeen && !obscured && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10632 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10633 | if (localLOGV) Slog.v(TAG, "Win " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10634 | + ": blurring=" + blurring |
| 10635 | + " obscured=" + obscured |
| 10636 | + " displayed=" + displayed); |
| 10637 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 10638 | if (!dimming) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10639 | //Slog.i(TAG, "DIM BEHIND: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10640 | dimming = true; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10641 | if (mDimAnimator == null) { |
| 10642 | mDimAnimator = new DimAnimator(mFxSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10643 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10644 | mDimAnimator.show(dw, dh); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 10645 | mDimAnimator.updateParameters(mContext.getResources(), |
| 10646 | w, currentTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10647 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10648 | } |
| 10649 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 10650 | if (!blurring) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10651 | //Slog.i(TAG, "BLUR BEHIND: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10652 | blurring = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10653 | if (mBlurSurface == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10654 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10655 | + mBlurSurface + ": CREATE"); |
| 10656 | try { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10657 | mBlurSurface = new Surface(mFxSession, 0, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10658 | "BlurSurface", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10659 | -1, 16, 16, |
| 10660 | PixelFormat.OPAQUE, |
| 10661 | Surface.FX_SURFACE_BLUR); |
| 10662 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10663 | Slog.e(TAG, "Exception creating Blur surface", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10664 | } |
| 10665 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10666 | if (mBlurSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10667 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10668 | + mBlurSurface + ": pos=(0,0) (" + |
| 10669 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10670 | mBlurSurface.setPosition(0, 0); |
| 10671 | mBlurSurface.setSize(dw, dh); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10672 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 10673 | if (!mBlurShown) { |
| 10674 | try { |
| 10675 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10676 | + mBlurSurface + ": SHOW"); |
| 10677 | mBlurSurface.show(); |
| 10678 | } catch (RuntimeException e) { |
| 10679 | Slog.w(TAG, "Failure showing blur surface", e); |
| 10680 | } |
| 10681 | mBlurShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10682 | } |
| 10683 | } |
| 10684 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10685 | } |
| 10686 | } |
| 10687 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10688 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10689 | if (obscuredChanged && mWallpaperTarget == w) { |
| 10690 | // This is the wallpaper target and its obscured state |
| 10691 | // changed... make sure the current wallaper's visibility |
| 10692 | // has been updated accordingly. |
| 10693 | updateWallpaperVisibilityLocked(); |
| 10694 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10695 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10696 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10697 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 10698 | mBackgroundFillerShown = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10699 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler"); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10700 | try { |
| 10701 | mBackgroundFillerSurface.hide(); |
| 10702 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10703 | Slog.e(TAG, "Exception hiding filler surface", e); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10704 | } |
| 10705 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10706 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10707 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10708 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 10709 | mDisplayFrozen || !mPolicy.isScreenOn()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10710 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10711 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10712 | if (!blurring && mBlurShown) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10713 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10714 | + ": HIDE"); |
| 10715 | try { |
| 10716 | mBlurSurface.hide(); |
| 10717 | } catch (IllegalArgumentException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10718 | Slog.w(TAG, "Illegal argument exception hiding blur surface"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10719 | } |
| 10720 | mBlurShown = false; |
| 10721 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10722 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10723 | Slog.e(TAG, "Unhandled exception in Window Manager", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10724 | } |
| 10725 | |
| 10726 | Surface.closeTransaction(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10727 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 10728 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces"); |
| 10729 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10730 | if (mWatermark != null) { |
| 10731 | mWatermark.drawIfNeeded(); |
| 10732 | } |
| 10733 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10734 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10735 | "With display frozen, orientationChangeComplete=" |
| 10736 | + orientationChangeComplete); |
| 10737 | if (orientationChangeComplete) { |
| 10738 | if (mWindowsFreezingScreen) { |
| 10739 | mWindowsFreezingScreen = false; |
| 10740 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10741 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10742 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10743 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10744 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10745 | i = mResizingWindows.size(); |
| 10746 | if (i > 0) { |
| 10747 | do { |
| 10748 | i--; |
| 10749 | WindowState win = mResizingWindows.get(i); |
| 10750 | try { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10751 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| 10752 | "Reporting new frame to " + win + ": " + win.mFrame); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10753 | int diff = 0; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10754 | boolean configChanged = |
| 10755 | win.mConfiguration != mCurConfiguration |
| 10756 | && (win.mConfiguration == null |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10757 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); |
| 10758 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) |
| 10759 | && configChanged) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10760 | Slog.i(TAG, "Sending new config to window " + win + ": " |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10761 | + win.mFrame.width() + "x" + win.mFrame.height() |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10762 | + " / " + mCurConfiguration + " / 0x" |
| 10763 | + Integer.toHexString(diff)); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10764 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10765 | win.mConfiguration = mCurConfiguration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10766 | win.mClient.resized(win.mFrame.width(), |
| 10767 | win.mFrame.height(), win.mLastContentInsets, |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10768 | win.mLastVisibleInsets, win.mDrawPending, |
| 10769 | configChanged ? win.mConfiguration : null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10770 | win.mContentInsetsChanged = false; |
| 10771 | win.mVisibleInsetsChanged = false; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10772 | win.mSurfaceResized = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10773 | } catch (RemoteException e) { |
| 10774 | win.mOrientationChanging = false; |
| 10775 | } |
| 10776 | } while (i > 0); |
| 10777 | mResizingWindows.clear(); |
| 10778 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10779 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10780 | // Destroy the surface of any windows that are no longer visible. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10781 | boolean wallpaperDestroyed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10782 | i = mDestroySurface.size(); |
| 10783 | if (i > 0) { |
| 10784 | do { |
| 10785 | i--; |
| 10786 | WindowState win = mDestroySurface.get(i); |
| 10787 | win.mDestroying = false; |
| 10788 | if (mInputMethodWindow == win) { |
| 10789 | mInputMethodWindow = null; |
| 10790 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10791 | if (win == mWallpaperTarget) { |
| 10792 | wallpaperDestroyed = true; |
| 10793 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10794 | win.destroySurfaceLocked(); |
| 10795 | } while (i > 0); |
| 10796 | mDestroySurface.clear(); |
| 10797 | } |
| 10798 | |
| 10799 | // Time to remove any exiting tokens? |
| 10800 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 10801 | WindowToken token = mExitingTokens.get(i); |
| 10802 | if (!token.hasVisible) { |
| 10803 | mExitingTokens.remove(i); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10804 | if (token.windowType == TYPE_WALLPAPER) { |
| 10805 | mWallpaperTokens.remove(token); |
| 10806 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10807 | } |
| 10808 | } |
| 10809 | |
| 10810 | // Time to remove any exiting applications? |
| 10811 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10812 | AppWindowToken token = mExitingAppTokens.get(i); |
| 10813 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 10814 | // Make sure there is no animation running on this token, |
| 10815 | // so any windows associated with it will be removed as |
| 10816 | // soon as their animations are complete |
| 10817 | token.animation = null; |
| 10818 | token.animating = false; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 10819 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 10820 | "performLayout: App token exiting now removed" + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10821 | mAppTokens.remove(token); |
| 10822 | mExitingAppTokens.remove(i); |
| 10823 | } |
| 10824 | } |
| 10825 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10826 | boolean needRelayout = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10827 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10828 | if (!animating && mAppTransitionRunning) { |
| 10829 | // We have finished the animation of an app transition. To do |
| 10830 | // this, we have delayed a lot of operations like showing and |
| 10831 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10832 | // reflects the correct Z-order, but the window list may now |
| 10833 | // be out of sync with it. So here we will just rebuild the |
| 10834 | // entire app window list. Fun! |
| 10835 | mAppTransitionRunning = false; |
| 10836 | needRelayout = true; |
| 10837 | rebuildAppWindowListLocked(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10838 | assignLayersLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10839 | // Clear information about apps that were moving. |
| 10840 | mToBottomApps.clear(); |
| 10841 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10842 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10843 | if (focusDisplayed) { |
| 10844 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 10845 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10846 | if (wallpaperDestroyed) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10847 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10848 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10849 | if (needRelayout) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10850 | requestAnimationLocked(0); |
| 10851 | } else if (animating) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10852 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 10853 | } |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 10854 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 10855 | // Finally update all input windows now that the window changes have stabilized. |
| 10856 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10857 | mInputMonitor.updateInputWindowsLw(); |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 10858 | |
Jeff Brown | 8e03b75 | 2010-06-13 19:16:55 -0700 | [diff] [blame] | 10859 | setHoldScreenLocked(holdScreen != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10860 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 10861 | mPowerManager.setScreenBrightnessOverride(-1); |
| 10862 | } else { |
| 10863 | mPowerManager.setScreenBrightnessOverride((int) |
| 10864 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 10865 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10866 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 10867 | mPowerManager.setButtonBrightnessOverride(-1); |
| 10868 | } else { |
| 10869 | mPowerManager.setButtonBrightnessOverride((int) |
| 10870 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 10871 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10872 | if (holdScreen != mHoldingScreenOn) { |
| 10873 | mHoldingScreenOn = holdScreen; |
| 10874 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 10875 | mH.sendMessage(m); |
| 10876 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10877 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10878 | if (mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10879 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10880 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 10881 | LocalPowerManager.BUTTON_EVENT, true); |
| 10882 | mTurnOnScreen = false; |
| 10883 | } |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 10884 | |
| 10885 | // Check to see if we are now in a state where the screen should |
| 10886 | // be enabled, because the window obscured flags have changed. |
| 10887 | enableScreenIfNeededLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10888 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 10889 | |
| 10890 | /** |
| 10891 | * Must be called with the main window manager lock held. |
| 10892 | */ |
| 10893 | void setHoldScreenLocked(boolean holding) { |
| 10894 | boolean state = mHoldingScreenWakeLock.isHeld(); |
| 10895 | if (holding != state) { |
| 10896 | if (holding) { |
| 10897 | mHoldingScreenWakeLock.acquire(); |
| 10898 | } else { |
| 10899 | mPolicy.screenOnStoppedLw(); |
| 10900 | mHoldingScreenWakeLock.release(); |
| 10901 | } |
| 10902 | } |
| 10903 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10904 | |
| 10905 | void requestAnimationLocked(long delay) { |
| 10906 | if (!mAnimationPending) { |
| 10907 | mAnimationPending = true; |
| 10908 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 10909 | } |
| 10910 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10911 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10912 | /** |
| 10913 | * Have the surface flinger show a surface, robustly dealing with |
| 10914 | * error conditions. In particular, if there is not enough memory |
| 10915 | * to show the surface, then we will try to get rid of other surfaces |
| 10916 | * in order to succeed. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10917 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10918 | * @return Returns true if the surface was successfully shown. |
| 10919 | */ |
| 10920 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 10921 | try { |
| 10922 | if (win.mSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10923 | win.mSurfaceShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10924 | win.mSurface.show(); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10925 | if (win.mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10926 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 10927 | "Show surface turning screen on: " + win); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10928 | win.mTurnOnScreen = false; |
| 10929 | mTurnOnScreen = true; |
| 10930 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10931 | } |
| 10932 | return true; |
| 10933 | } catch (RuntimeException e) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 10934 | Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10935 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10936 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10937 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10938 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10939 | return false; |
| 10940 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10941 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10942 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 10943 | final Surface surface = win.mSurface; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10944 | |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10945 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10946 | win.mSession.mPid, operation); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10947 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10948 | if (mForceRemoves == null) { |
| 10949 | mForceRemoves = new ArrayList<WindowState>(); |
| 10950 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10951 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10952 | long callingIdentity = Binder.clearCallingIdentity(); |
| 10953 | try { |
| 10954 | // There was some problem... first, do a sanity check of the |
| 10955 | // window list to make sure we haven't left any dangling surfaces |
| 10956 | // around. |
| 10957 | int N = mWindows.size(); |
| 10958 | boolean leakedSurface = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10959 | 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] | 10960 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10961 | WindowState ws = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10962 | if (ws.mSurface != null) { |
| 10963 | if (!mSessions.contains(ws.mSession)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10964 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10965 | + ws + " surface=" + ws.mSurface |
| 10966 | + " token=" + win.mToken |
| 10967 | + " pid=" + ws.mSession.mPid |
| 10968 | + " uid=" + ws.mSession.mUid); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 10969 | if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10970 | ws.mSurface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10971 | ws.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10972 | ws.mSurface = null; |
| 10973 | mForceRemoves.add(ws); |
| 10974 | i--; |
| 10975 | N--; |
| 10976 | leakedSurface = true; |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 10977 | } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10978 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10979 | + ws + " surface=" + ws.mSurface |
| 10980 | + " token=" + win.mAppToken); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 10981 | if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10982 | ws.mSurface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10983 | ws.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10984 | ws.mSurface = null; |
| 10985 | leakedSurface = true; |
| 10986 | } |
| 10987 | } |
| 10988 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10989 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10990 | boolean killedApps = false; |
| 10991 | if (!leakedSurface) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10992 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10993 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 10994 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10995 | WindowState ws = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10996 | if (ws.mSurface != null) { |
| 10997 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 10998 | } |
| 10999 | } |
| 11000 | if (pidCandidates.size() > 0) { |
| 11001 | int[] pids = new int[pidCandidates.size()]; |
| 11002 | for (int i=0; i<pids.length; i++) { |
| 11003 | pids[i] = pidCandidates.keyAt(i); |
| 11004 | } |
| 11005 | try { |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 11006 | if (mActivityManager.killPids(pids, "Free memory")) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11007 | killedApps = true; |
| 11008 | } |
| 11009 | } catch (RemoteException e) { |
| 11010 | } |
| 11011 | } |
| 11012 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11013 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11014 | if (leakedSurface || killedApps) { |
| 11015 | // We managed to reclaim some memory, so get rid of the trouble |
| 11016 | // surface and ask the app to request another one. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11017 | 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] | 11018 | if (surface != null) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 11019 | if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11020 | surface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11021 | win.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11022 | win.mSurface = null; |
| 11023 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11024 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11025 | try { |
| 11026 | win.mClient.dispatchGetNewSurface(); |
| 11027 | } catch (RemoteException e) { |
| 11028 | } |
| 11029 | } |
| 11030 | } finally { |
| 11031 | Binder.restoreCallingIdentity(callingIdentity); |
| 11032 | } |
| 11033 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11034 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 11035 | private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11036 | WindowState newFocus = computeFocusedWindowLocked(); |
| 11037 | if (mCurrentFocus != newFocus) { |
| 11038 | // This check makes sure that we don't already have the focus |
| 11039 | // change message pending. |
| 11040 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 11041 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11042 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11043 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 11044 | final WindowState oldFocus = mCurrentFocus; |
| 11045 | mCurrentFocus = newFocus; |
| 11046 | mLosingFocus.remove(newFocus); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11047 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11048 | final WindowState imWindow = mInputMethodWindow; |
| 11049 | if (newFocus != imWindow && oldFocus != imWindow) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11050 | if (moveInputMethodWindowsIfNeededLocked( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11051 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11052 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 11053 | mLayoutNeeded = true; |
| 11054 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11055 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 11056 | performLayoutLockedInner(true /*initial*/, updateInputWindows); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11057 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 11058 | // Client will do the layout, but we need to assign layers |
| 11059 | // for handleNewWindowLocked() below. |
| 11060 | assignLayersLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11061 | } |
| 11062 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11063 | |
| 11064 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 11065 | // If we defer assigning layers, then the caller is responsible for |
| 11066 | // doing this part. |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 11067 | finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11068 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11069 | return true; |
| 11070 | } |
| 11071 | return false; |
| 11072 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11073 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame^] | 11074 | private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) { |
| 11075 | mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11076 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11077 | |
| 11078 | private WindowState computeFocusedWindowLocked() { |
| 11079 | WindowState result = null; |
| 11080 | WindowState win; |
| 11081 | |
| 11082 | int i = mWindows.size() - 1; |
| 11083 | int nextAppIndex = mAppTokens.size()-1; |
| 11084 | WindowToken nextApp = nextAppIndex >= 0 |
| 11085 | ? mAppTokens.get(nextAppIndex) : null; |
| 11086 | |
| 11087 | while (i >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 11088 | win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11089 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11090 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11091 | TAG, "Looking for focus: " + i |
| 11092 | + " = " + win |
| 11093 | + ", flags=" + win.mAttrs.flags |
| 11094 | + ", canReceive=" + win.canReceiveKeys()); |
| 11095 | |
| 11096 | AppWindowToken thisApp = win.mAppToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11097 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11098 | // If this window's application has been removed, just skip it. |
| 11099 | if (thisApp != null && thisApp.removed) { |
| 11100 | i--; |
| 11101 | continue; |
| 11102 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11103 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11104 | // If there is a focused app, don't allow focus to go to any |
| 11105 | // windows below it. If this is an application window, step |
| 11106 | // through the app tokens until we find its app. |
| 11107 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 11108 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 11109 | int origAppIndex = nextAppIndex; |
| 11110 | while (nextAppIndex > 0) { |
| 11111 | if (nextApp == mFocusedApp) { |
| 11112 | // Whoops, we are below the focused app... no focus |
| 11113 | // for you! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11114 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11115 | TAG, "Reached focused app: " + mFocusedApp); |
| 11116 | return null; |
| 11117 | } |
| 11118 | nextAppIndex--; |
| 11119 | nextApp = mAppTokens.get(nextAppIndex); |
| 11120 | if (nextApp == thisApp) { |
| 11121 | break; |
| 11122 | } |
| 11123 | } |
| 11124 | if (thisApp != nextApp) { |
| 11125 | // Uh oh, the app token doesn't exist! This shouldn't |
| 11126 | // happen, but if it does we can get totally hosed... |
| 11127 | // so restart at the original app. |
| 11128 | nextAppIndex = origAppIndex; |
| 11129 | nextApp = mAppTokens.get(nextAppIndex); |
| 11130 | } |
| 11131 | } |
| 11132 | |
| 11133 | // Dispatch to this window if it is wants key events. |
| 11134 | if (win.canReceiveKeys()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11135 | if (DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11136 | TAG, "Found focus @ " + i + " = " + win); |
| 11137 | result = win; |
| 11138 | break; |
| 11139 | } |
| 11140 | |
| 11141 | i--; |
| 11142 | } |
| 11143 | |
| 11144 | return result; |
| 11145 | } |
| 11146 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 11147 | private void startFreezingDisplayLocked(boolean inTransaction) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11148 | if (mDisplayFrozen) { |
| 11149 | return; |
| 11150 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11151 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11152 | mScreenFrozenLock.acquire(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11153 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11154 | long now = SystemClock.uptimeMillis(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11155 | //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11156 | if (mFreezeGcPending != 0) { |
| 11157 | if (now > (mFreezeGcPending+1000)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11158 | //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11159 | mH.removeMessages(H.FORCE_GC); |
| 11160 | Runtime.getRuntime().gc(); |
| 11161 | mFreezeGcPending = now; |
| 11162 | } |
| 11163 | } else { |
| 11164 | mFreezeGcPending = now; |
| 11165 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11166 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11167 | mDisplayFrozen = true; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11168 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 11169 | mInputMonitor.freezeInputDispatchingLw(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11170 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 11171 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 11172 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11173 | mNextAppTransitionPackage = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11174 | mAppTransitionReady = true; |
| 11175 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11176 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11177 | if (PROFILE_ORIENTATION) { |
| 11178 | File file = new File("/data/system/frozen"); |
| 11179 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 11180 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11181 | |
| 11182 | if (CUSTOM_SCREEN_ROTATION) { |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 11183 | if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) { |
| 11184 | mScreenRotationAnimation.kill(); |
| 11185 | mScreenRotationAnimation = null; |
| 11186 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11187 | if (mScreenRotationAnimation == null) { |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 11188 | mScreenRotationAnimation = new ScreenRotationAnimation(mContext, |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 11189 | mDisplay, mFxSession, inTransaction); |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11190 | } |
| 11191 | } else { |
| 11192 | Surface.freezeDisplay(0); |
| 11193 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11194 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11195 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11196 | private void stopFreezingDisplayLocked() { |
| 11197 | if (!mDisplayFrozen) { |
| 11198 | return; |
| 11199 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11200 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11201 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) { |
| 11202 | return; |
| 11203 | } |
| 11204 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11205 | mDisplayFrozen = false; |
| 11206 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 11207 | if (PROFILE_ORIENTATION) { |
| 11208 | Debug.stopMethodTracing(); |
| 11209 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11210 | |
| 11211 | if (CUSTOM_SCREEN_ROTATION) { |
| 11212 | if (mScreenRotationAnimation != null) { |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 11213 | if (mScreenRotationAnimation.dismiss(MAX_ANIMATION_DURATION, |
| 11214 | mTransitionAnimationScale)) { |
| 11215 | requestAnimationLocked(0); |
| 11216 | } else { |
| 11217 | mScreenRotationAnimation = null; |
| 11218 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11219 | } |
| 11220 | } else { |
| 11221 | Surface.unfreezeDisplay(0); |
| 11222 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11223 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 11224 | mInputMonitor.thawInputDispatchingLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11225 | |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 11226 | // While the display is frozen we don't re-compute the orientation |
| 11227 | // to avoid inconsistent states. However, something interesting |
| 11228 | // could have actually changed during that time so re-evaluate it |
| 11229 | // now to catch that. |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 11230 | if (updateOrientationFromAppTokensLocked(false)) { |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 11231 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 11232 | } |
| 11233 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11234 | // A little kludge: a lot could have happened while the |
| 11235 | // display was frozen, so now that we are coming back we |
| 11236 | // do a gc so that any remote references the system |
| 11237 | // processes holds on others can be released if they are |
| 11238 | // no longer needed. |
| 11239 | mH.removeMessages(H.FORCE_GC); |
| 11240 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 11241 | 2000); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11242 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11243 | mScreenFrozenLock.release(); |
| 11244 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11245 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11246 | static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps, |
| 11247 | DisplayMetrics dm) { |
| 11248 | if (index < tokens.length) { |
| 11249 | String str = tokens[index]; |
| 11250 | if (str != null && str.length() > 0) { |
| 11251 | try { |
| 11252 | int val = Integer.parseInt(str); |
| 11253 | return val; |
| 11254 | } catch (Exception e) { |
| 11255 | } |
| 11256 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11257 | } |
| 11258 | if (defUnits == TypedValue.COMPLEX_UNIT_PX) { |
| 11259 | return defDps; |
| 11260 | } |
| 11261 | int val = (int)TypedValue.applyDimension(defUnits, defDps, dm); |
| 11262 | return val; |
| 11263 | } |
| 11264 | |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11265 | static class Watermark { |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11266 | final String[] mTokens; |
| 11267 | final String mText; |
| 11268 | final Paint mTextPaint; |
| 11269 | final int mTextWidth; |
| 11270 | final int mTextHeight; |
| 11271 | final int mTextAscent; |
| 11272 | final int mTextDescent; |
| 11273 | final int mDeltaX; |
| 11274 | final int mDeltaY; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11275 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11276 | Surface mSurface; |
| 11277 | int mLastDW; |
| 11278 | int mLastDH; |
| 11279 | boolean mDrawNeeded; |
| 11280 | |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11281 | Watermark(Display display, SurfaceSession session, String[] tokens) { |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11282 | final DisplayMetrics dm = new DisplayMetrics(); |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11283 | display.getMetrics(dm); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11284 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11285 | if (false) { |
| 11286 | Log.i(TAG, "*********************** WATERMARK"); |
| 11287 | for (int i=0; i<tokens.length; i++) { |
| 11288 | Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]); |
| 11289 | } |
| 11290 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11291 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11292 | mTokens = tokens; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11293 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11294 | StringBuilder builder = new StringBuilder(32); |
| 11295 | int len = mTokens[0].length(); |
| 11296 | len = len & ~1; |
| 11297 | for (int i=0; i<len; i+=2) { |
| 11298 | int c1 = mTokens[0].charAt(i); |
| 11299 | int c2 = mTokens[0].charAt(i+1); |
| 11300 | if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10; |
| 11301 | else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10; |
| 11302 | else c1 -= '0'; |
| 11303 | if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10; |
| 11304 | else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10; |
| 11305 | else c2 -= '0'; |
| 11306 | builder.append((char)(255-((c1*16)+c2))); |
| 11307 | } |
| 11308 | mText = builder.toString(); |
| 11309 | if (false) { |
| 11310 | Log.i(TAG, "Final text: " + mText); |
| 11311 | } |
| 11312 | |
| 11313 | int fontSize = getPropertyInt(tokens, 1, |
| 11314 | TypedValue.COMPLEX_UNIT_DIP, 20, dm); |
| 11315 | |
| 11316 | mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
| 11317 | mTextPaint.setTextSize(fontSize); |
| 11318 | mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD)); |
| 11319 | |
| 11320 | FontMetricsInt fm = mTextPaint.getFontMetricsInt(); |
| 11321 | mTextWidth = (int)mTextPaint.measureText(mText); |
| 11322 | mTextAscent = fm.ascent; |
| 11323 | mTextDescent = fm.descent; |
| 11324 | mTextHeight = fm.descent - fm.ascent; |
| 11325 | |
| 11326 | mDeltaX = getPropertyInt(tokens, 2, |
| 11327 | TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm); |
| 11328 | mDeltaY = getPropertyInt(tokens, 3, |
| 11329 | TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm); |
| 11330 | int shadowColor = getPropertyInt(tokens, 4, |
| 11331 | TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm); |
| 11332 | int color = getPropertyInt(tokens, 5, |
| 11333 | TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm); |
| 11334 | int shadowRadius = getPropertyInt(tokens, 6, |
| 11335 | TypedValue.COMPLEX_UNIT_PX, 7, dm); |
| 11336 | int shadowDx = getPropertyInt(tokens, 8, |
| 11337 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 11338 | int shadowDy = getPropertyInt(tokens, 9, |
| 11339 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 11340 | |
| 11341 | mTextPaint.setColor(color); |
| 11342 | mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11343 | |
| 11344 | try { |
| 11345 | mSurface = new Surface(session, 0, |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11346 | "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11347 | mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100); |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11348 | mSurface.setPosition(0, 0); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11349 | mSurface.show(); |
| 11350 | } catch (OutOfResourcesException e) { |
| 11351 | } |
| 11352 | } |
| 11353 | |
| 11354 | void positionSurface(int dw, int dh) { |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11355 | if (mLastDW != dw || mLastDH != dh) { |
| 11356 | mLastDW = dw; |
| 11357 | mLastDH = dh; |
| 11358 | mSurface.setSize(dw, dh); |
| 11359 | mDrawNeeded = true; |
| 11360 | } |
| 11361 | } |
| 11362 | |
| 11363 | void drawIfNeeded() { |
| 11364 | if (mDrawNeeded) { |
| 11365 | final int dw = mLastDW; |
| 11366 | final int dh = mLastDH; |
| 11367 | |
| 11368 | mDrawNeeded = false; |
| 11369 | Rect dirty = new Rect(0, 0, dw, dh); |
| 11370 | Canvas c = null; |
| 11371 | try { |
| 11372 | c = mSurface.lockCanvas(dirty); |
| 11373 | } catch (IllegalArgumentException e) { |
| 11374 | } catch (OutOfResourcesException e) { |
| 11375 | } |
| 11376 | if (c != null) { |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11377 | c.drawColor(0, PorterDuff.Mode.CLEAR); |
| 11378 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11379 | int deltaX = mDeltaX; |
| 11380 | int deltaY = mDeltaY; |
| 11381 | |
| 11382 | // deltaX shouldn't be close to a round fraction of our |
| 11383 | // x step, or else things will line up too much. |
| 11384 | int div = (dw+mTextWidth)/deltaX; |
| 11385 | int rem = (dw+mTextWidth) - (div*deltaX); |
| 11386 | int qdelta = deltaX/4; |
| 11387 | if (rem < qdelta || rem > (deltaX-qdelta)) { |
| 11388 | deltaX += deltaX/3; |
| 11389 | } |
| 11390 | |
| 11391 | int y = -mTextHeight; |
| 11392 | int x = -mTextWidth; |
| 11393 | while (y < (dh+mTextHeight)) { |
| 11394 | c.drawText(mText, x, y, mTextPaint); |
| 11395 | x += deltaX; |
| 11396 | if (x >= dw) { |
| 11397 | x -= (dw+mTextWidth); |
| 11398 | y += deltaY; |
| 11399 | } |
| 11400 | } |
| 11401 | mSurface.unlockCanvasAndPost(c); |
| 11402 | } |
| 11403 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11404 | } |
| 11405 | } |
| 11406 | |
| 11407 | void createWatermark() { |
| 11408 | if (mWatermark != null) { |
| 11409 | return; |
| 11410 | } |
| 11411 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11412 | File file = new File("/system/etc/setup.conf"); |
| 11413 | FileInputStream in = null; |
| 11414 | try { |
| 11415 | in = new FileInputStream(file); |
| 11416 | DataInputStream ind = new DataInputStream(in); |
| 11417 | String line = ind.readLine(); |
| 11418 | if (line != null) { |
| 11419 | String[] toks = line.split("%"); |
| 11420 | if (toks != null && toks.length > 0) { |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11421 | mWatermark = new Watermark(mDisplay, mFxSession, toks); |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11422 | } |
| 11423 | } |
| 11424 | } catch (FileNotFoundException e) { |
| 11425 | } catch (IOException e) { |
| 11426 | } finally { |
| 11427 | if (in != null) { |
| 11428 | try { |
| 11429 | in.close(); |
| 11430 | } catch (IOException e) { |
| 11431 | } |
| 11432 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11433 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11434 | } |
| 11435 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11436 | @Override |
| 11437 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 11438 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 11439 | != PackageManager.PERMISSION_GRANTED) { |
| 11440 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 11441 | + Binder.getCallingPid() |
| 11442 | + ", uid=" + Binder.getCallingUid()); |
| 11443 | return; |
| 11444 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11445 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 11446 | mInputManager.dump(pw); |
Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 11447 | pw.println(" "); |
| 11448 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11449 | synchronized(mWindowMap) { |
| 11450 | pw.println("Current Window Manager state:"); |
| 11451 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 11452 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11453 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 11454 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11455 | w.dump(pw, " "); |
| 11456 | } |
| 11457 | if (mInputMethodDialogs.size() > 0) { |
| 11458 | pw.println(" "); |
| 11459 | pw.println(" Input method dialogs:"); |
| 11460 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 11461 | WindowState w = mInputMethodDialogs.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11462 | 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] | 11463 | } |
| 11464 | } |
| 11465 | if (mPendingRemove.size() > 0) { |
| 11466 | pw.println(" "); |
| 11467 | pw.println(" Remove pending for:"); |
| 11468 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 11469 | WindowState w = mPendingRemove.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11470 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 11471 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11472 | w.dump(pw, " "); |
| 11473 | } |
| 11474 | } |
| 11475 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 11476 | pw.println(" "); |
| 11477 | pw.println(" Windows force removing:"); |
| 11478 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 11479 | WindowState w = mForceRemoves.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11480 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 11481 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11482 | w.dump(pw, " "); |
| 11483 | } |
| 11484 | } |
| 11485 | if (mDestroySurface.size() > 0) { |
| 11486 | pw.println(" "); |
| 11487 | pw.println(" Windows waiting to destroy their surface:"); |
| 11488 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 11489 | WindowState w = mDestroySurface.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11490 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 11491 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11492 | w.dump(pw, " "); |
| 11493 | } |
| 11494 | } |
| 11495 | if (mLosingFocus.size() > 0) { |
| 11496 | pw.println(" "); |
| 11497 | pw.println(" Windows losing focus:"); |
| 11498 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 11499 | WindowState w = mLosingFocus.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11500 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 11501 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11502 | w.dump(pw, " "); |
| 11503 | } |
| 11504 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11505 | if (mResizingWindows.size() > 0) { |
| 11506 | pw.println(" "); |
| 11507 | pw.println(" Windows waiting to resize:"); |
| 11508 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 11509 | WindowState w = mResizingWindows.get(i); |
| 11510 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 11511 | pw.print(w); pw.println(":"); |
| 11512 | w.dump(pw, " "); |
| 11513 | } |
| 11514 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11515 | if (mSessions.size() > 0) { |
| 11516 | pw.println(" "); |
| 11517 | pw.println(" All active sessions:"); |
| 11518 | Iterator<Session> it = mSessions.iterator(); |
| 11519 | while (it.hasNext()) { |
| 11520 | Session s = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11521 | pw.print(" Session "); pw.print(s); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11522 | s.dump(pw, " "); |
| 11523 | } |
| 11524 | } |
| 11525 | if (mTokenMap.size() > 0) { |
| 11526 | pw.println(" "); |
| 11527 | pw.println(" All tokens:"); |
| 11528 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 11529 | while (it.hasNext()) { |
| 11530 | WindowToken token = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11531 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11532 | token.dump(pw, " "); |
| 11533 | } |
| 11534 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 11535 | if (mWallpaperTokens.size() > 0) { |
| 11536 | pw.println(" "); |
| 11537 | pw.println(" Wallpaper tokens:"); |
| 11538 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 11539 | WindowToken token = mWallpaperTokens.get(i); |
| 11540 | pw.print(" Wallpaper #"); pw.print(i); |
| 11541 | pw.print(' '); pw.print(token); pw.println(':'); |
| 11542 | token.dump(pw, " "); |
| 11543 | } |
| 11544 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11545 | if (mAppTokens.size() > 0) { |
| 11546 | pw.println(" "); |
| 11547 | pw.println(" Application tokens in Z order:"); |
| 11548 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11549 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 11550 | pw.println(mAppTokens.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11551 | } |
| 11552 | } |
| 11553 | if (mFinishedStarting.size() > 0) { |
| 11554 | pw.println(" "); |
| 11555 | pw.println(" Finishing start of application tokens:"); |
| 11556 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 11557 | WindowToken token = mFinishedStarting.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11558 | pw.print(" Finished Starting #"); pw.print(i); |
| 11559 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11560 | token.dump(pw, " "); |
| 11561 | } |
| 11562 | } |
| 11563 | if (mExitingTokens.size() > 0) { |
| 11564 | pw.println(" "); |
| 11565 | pw.println(" Exiting tokens:"); |
| 11566 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 11567 | WindowToken token = mExitingTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11568 | pw.print(" Exiting #"); pw.print(i); |
| 11569 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11570 | token.dump(pw, " "); |
| 11571 | } |
| 11572 | } |
| 11573 | if (mExitingAppTokens.size() > 0) { |
| 11574 | pw.println(" "); |
| 11575 | pw.println(" Exiting application tokens:"); |
| 11576 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 11577 | WindowToken token = mExitingAppTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11578 | pw.print(" Exiting App #"); pw.print(i); |
| 11579 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11580 | token.dump(pw, " "); |
| 11581 | } |
| 11582 | } |
| 11583 | pw.println(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11584 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 11585 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 11586 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 11587 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 11588 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 11589 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11590 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 11591 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 11592 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 11593 | } |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 11594 | if (mWindowDetachedWallpaper != null) { |
| 11595 | pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper); |
| 11596 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11597 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 11598 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 11599 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11600 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 11601 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 11602 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 11603 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11604 | if (mDimAnimator != null) { |
| 11605 | mDimAnimator.printTo(pw); |
| 11606 | } else { |
Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 11607 | pw.println( " no DimAnimator "); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11608 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11609 | pw.print(" mInputMethodAnimLayerAdjustment="); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 11610 | pw.print(mInputMethodAnimLayerAdjustment); |
| 11611 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 11612 | pw.println(mWallpaperAnimLayerAdjustment); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11613 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 11614 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11615 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 11616 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11617 | pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); |
| 11618 | pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11619 | pw.print(" mRotation="); pw.print(mRotation); |
| 11620 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 11621 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 11622 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 11623 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 11624 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 11625 | pw.print(" mNextAppTransition=0x"); |
| 11626 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 11627 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11628 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11629 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11630 | if (mNextAppTransitionPackage != null) { |
| 11631 | pw.print(" mNextAppTransitionPackage="); |
| 11632 | pw.print(mNextAppTransitionPackage); |
| 11633 | pw.print(", mNextAppTransitionEnter=0x"); |
| 11634 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 11635 | pw.print(", mNextAppTransitionExit=0x"); |
| 11636 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 11637 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11638 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 11639 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
| 11640 | if (mOpeningApps.size() > 0) { |
| 11641 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 11642 | } |
| 11643 | if (mClosingApps.size() > 0) { |
| 11644 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 11645 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11646 | if (mToTopApps.size() > 0) { |
| 11647 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 11648 | } |
| 11649 | if (mToBottomApps.size() > 0) { |
| 11650 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 11651 | } |
Dianne Hackborn | 87fc308 | 2010-12-03 13:09:12 -0800 | [diff] [blame] | 11652 | if (mDisplay != null) { |
| 11653 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 11654 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
| 11655 | } else { |
| 11656 | pw.println(" NO DISPLAY"); |
| 11657 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 11658 | pw.println(" Policy:"); |
| 11659 | mPolicy.dump(" ", fd, pw, args); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11660 | } |
| 11661 | } |
| 11662 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11663 | // 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] | 11664 | public void monitor() { |
| 11665 | synchronized (mWindowMap) { } |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 11666 | synchronized (mKeyguardTokenWatcher) { } |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 11667 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11668 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11669 | /** |
| 11670 | * DimAnimator class that controls the dim animation. This holds the surface and |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11671 | * all state used for dim animation. |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11672 | */ |
| 11673 | private static class DimAnimator { |
| 11674 | Surface mDimSurface; |
| 11675 | boolean mDimShown = false; |
| 11676 | float mDimCurrentAlpha; |
| 11677 | float mDimTargetAlpha; |
| 11678 | float mDimDeltaPerMs; |
| 11679 | long mLastDimAnimTime; |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11680 | |
| 11681 | int mLastDimWidth, mLastDimHeight; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11682 | |
| 11683 | DimAnimator (SurfaceSession session) { |
| 11684 | if (mDimSurface == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11685 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11686 | + mDimSurface + ": CREATE"); |
| 11687 | try { |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 11688 | mDimSurface = new Surface(session, 0, |
| 11689 | "DimSurface", |
| 11690 | -1, 16, 16, PixelFormat.OPAQUE, |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11691 | Surface.FX_SURFACE_DIM); |
Maciej Białka | 9ee5c22 | 2010-03-24 10:25:40 +0100 | [diff] [blame] | 11692 | mDimSurface.setAlpha(0.0f); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11693 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11694 | Slog.e(TAG, "Exception creating Dim surface", e); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11695 | } |
| 11696 | } |
| 11697 | } |
| 11698 | |
| 11699 | /** |
| 11700 | * Show the dim surface. |
| 11701 | */ |
| 11702 | void show(int dw, int dh) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11703 | if (!mDimShown) { |
| 11704 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 11705 | dw + "x" + dh + ")"); |
| 11706 | mDimShown = true; |
| 11707 | try { |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11708 | mLastDimWidth = dw; |
| 11709 | mLastDimHeight = dh; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11710 | mDimSurface.setPosition(0, 0); |
| 11711 | mDimSurface.setSize(dw, dh); |
| 11712 | mDimSurface.show(); |
| 11713 | } catch (RuntimeException e) { |
| 11714 | Slog.w(TAG, "Failure showing dim surface", e); |
| 11715 | } |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11716 | } else if (mLastDimWidth != dw || mLastDimHeight != dh) { |
| 11717 | mLastDimWidth = dw; |
| 11718 | mLastDimHeight = dh; |
| 11719 | mDimSurface.setSize(dw, dh); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11720 | } |
| 11721 | } |
| 11722 | |
| 11723 | /** |
| 11724 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 11725 | * {@link updateSurface} after all windows are examined. |
| 11726 | */ |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 11727 | void updateParameters(Resources res, WindowState w, long currentTime) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11728 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 11729 | |
| 11730 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11731 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11732 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11733 | if (mDimTargetAlpha != target) { |
| 11734 | // If the desired dim level has changed, then |
| 11735 | // start an animation to it. |
| 11736 | mLastDimAnimTime = currentTime; |
| 11737 | long duration = (w.mAnimating && w.mAnimation != null) |
| 11738 | ? w.mAnimation.computeDurationHint() |
| 11739 | : DEFAULT_DIM_DURATION; |
| 11740 | if (target > mDimTargetAlpha) { |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 11741 | TypedValue tv = new TypedValue(); |
| 11742 | res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration, |
| 11743 | tv, true); |
| 11744 | if (tv.type == TypedValue.TYPE_FRACTION) { |
| 11745 | duration = (long)tv.getFraction((float)duration, (float)duration); |
| 11746 | } else if (tv.type >= TypedValue.TYPE_FIRST_INT |
| 11747 | && tv.type <= TypedValue.TYPE_LAST_INT) { |
| 11748 | duration = tv.data; |
| 11749 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11750 | } |
| 11751 | if (duration < 1) { |
| 11752 | // Don't divide by zero |
| 11753 | duration = 1; |
| 11754 | } |
| 11755 | mDimTargetAlpha = target; |
| 11756 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 11757 | } |
| 11758 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11759 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11760 | /** |
| 11761 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 11762 | * false when the animation is finished and the dim surface is hidden. |
| 11763 | */ |
| 11764 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 11765 | if (!dimming) { |
| 11766 | if (mDimTargetAlpha != 0) { |
| 11767 | mLastDimAnimTime = currentTime; |
| 11768 | mDimTargetAlpha = 0; |
| 11769 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 11770 | } |
| 11771 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11772 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11773 | boolean animating = false; |
| 11774 | if (mLastDimAnimTime != 0) { |
| 11775 | mDimCurrentAlpha += mDimDeltaPerMs |
| 11776 | * (currentTime-mLastDimAnimTime); |
| 11777 | boolean more = true; |
| 11778 | if (displayFrozen) { |
| 11779 | // If the display is frozen, there is no reason to animate. |
| 11780 | more = false; |
| 11781 | } else if (mDimDeltaPerMs > 0) { |
| 11782 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 11783 | more = false; |
| 11784 | } |
| 11785 | } else if (mDimDeltaPerMs < 0) { |
| 11786 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 11787 | more = false; |
| 11788 | } |
| 11789 | } else { |
| 11790 | more = false; |
| 11791 | } |
| 11792 | |
| 11793 | // Do we need to continue animating? |
| 11794 | if (more) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11795 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11796 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 11797 | mLastDimAnimTime = currentTime; |
| 11798 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11799 | animating = true; |
| 11800 | } else { |
| 11801 | mDimCurrentAlpha = mDimTargetAlpha; |
| 11802 | mLastDimAnimTime = 0; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11803 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11804 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 11805 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11806 | if (!dimming) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11807 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11808 | + ": HIDE"); |
| 11809 | try { |
| 11810 | mDimSurface.hide(); |
| 11811 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11812 | Slog.w(TAG, "Illegal argument exception hiding dim surface"); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11813 | } |
| 11814 | mDimShown = false; |
| 11815 | } |
| 11816 | } |
| 11817 | } |
| 11818 | return animating; |
| 11819 | } |
| 11820 | |
| 11821 | public void printTo(PrintWriter pw) { |
| 11822 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 11823 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 11824 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 11825 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 11826 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 11827 | } |
| 11828 | } |
| 11829 | |
| 11830 | /** |
| 11831 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 11832 | * This is used for opening/closing transition for apps in compatible mode. |
| 11833 | */ |
| 11834 | private static class FadeInOutAnimation extends Animation { |
| 11835 | int mWidth; |
| 11836 | boolean mFadeIn; |
| 11837 | |
| 11838 | public FadeInOutAnimation(boolean fadeIn) { |
| 11839 | setInterpolator(new AccelerateInterpolator()); |
| 11840 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 11841 | mFadeIn = fadeIn; |
| 11842 | } |
| 11843 | |
| 11844 | @Override |
| 11845 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 11846 | float x = interpolatedTime; |
| 11847 | if (!mFadeIn) { |
| 11848 | x = 1.0f - x; // reverse the interpolation for fade out |
| 11849 | } |
| 11850 | if (x < 0.5) { |
| 11851 | // move the window out of the screen. |
| 11852 | t.getMatrix().setTranslate(mWidth, 0); |
| 11853 | } else { |
| 11854 | t.getMatrix().setTranslate(0, 0);// show |
| 11855 | t.setAlpha((x - 0.5f) * 2); |
| 11856 | } |
| 11857 | } |
| 11858 | |
| 11859 | @Override |
| 11860 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 11861 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 11862 | mWidth = width; |
| 11863 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11864 | |
| 11865 | @Override |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 11866 | public int getZAdjustment() { |
| 11867 | return Animation.ZORDER_TOP; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11868 | } |
| 11869 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11870 | } |