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 | |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 17 | package com.android.server.wm; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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; |
| 22 | import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND; |
| 23 | import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 25 | import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 26 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 28 | import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 30 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 31 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 32 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 33 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | |
| 35 | import com.android.internal.app.IBatteryStats; |
| 36 | import com.android.internal.policy.PolicyManager; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 37 | import com.android.internal.policy.impl.PhoneWindowManager; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 38 | import com.android.internal.view.BaseInputHandler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import com.android.internal.view.IInputContext; |
| 40 | import com.android.internal.view.IInputMethodClient; |
| 41 | import com.android.internal.view.IInputMethodManager; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 42 | import com.android.internal.view.WindowManagerPolicyThread; |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 43 | import com.android.server.AttributeCache; |
| 44 | import com.android.server.EventLogTags; |
| 45 | import com.android.server.PowerManagerService; |
| 46 | import com.android.server.Watchdog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | import com.android.server.am.BatteryStatsService; |
| 48 | |
| 49 | import android.Manifest; |
| 50 | import android.app.ActivityManagerNative; |
| 51 | import android.app.IActivityManager; |
Joe Onorato | ac0ee89 | 2011-01-30 15:38:30 -0800 | [diff] [blame] | 52 | import android.app.StatusBarManager; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 53 | import android.app.admin.DevicePolicyManager; |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 54 | import android.content.BroadcastReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | import android.content.Context; |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 56 | import android.content.Intent; |
| 57 | import android.content.IntentFilter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | import android.content.pm.ActivityInfo; |
| 59 | import android.content.pm.PackageManager; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 60 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | import android.content.res.Configuration; |
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; |
| 65 | import android.graphics.PixelFormat; |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 66 | import android.graphics.Point; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | import android.graphics.Rect; |
| 68 | import android.graphics.Region; |
| 69 | import android.os.BatteryStats; |
| 70 | import android.os.Binder; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 71 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | import android.os.Debug; |
| 73 | import android.os.Handler; |
| 74 | import android.os.IBinder; |
| 75 | import android.os.LocalPowerManager; |
| 76 | import android.os.Looper; |
| 77 | import android.os.Message; |
| 78 | import android.os.Parcel; |
| 79 | import android.os.ParcelFileDescriptor; |
| 80 | import android.os.Power; |
| 81 | import android.os.PowerManager; |
| 82 | import android.os.Process; |
| 83 | import android.os.RemoteException; |
| 84 | import android.os.ServiceManager; |
Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 85 | import android.os.StrictMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | import android.os.SystemClock; |
| 87 | import android.os.SystemProperties; |
| 88 | import android.os.TokenWatcher; |
| 89 | import android.provider.Settings; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 90 | import android.util.DisplayMetrics; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | import android.util.EventLog; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 92 | import android.util.Log; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 93 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | import android.util.SparseIntArray; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 95 | import android.util.TypedValue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | import android.view.Display; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | import android.view.IApplicationToken; |
| 98 | import android.view.IOnKeyguardExitResult; |
| 99 | import android.view.IRotationWatcher; |
| 100 | import android.view.IWindow; |
| 101 | import android.view.IWindowManager; |
| 102 | import android.view.IWindowSession; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 103 | import android.view.InputChannel; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 104 | import android.view.InputDevice; |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 105 | import android.view.InputEvent; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 106 | import android.view.InputHandler; |
| 107 | import android.view.InputQueue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | import android.view.KeyEvent; |
| 109 | import android.view.MotionEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | import android.view.Surface; |
| 111 | import android.view.SurfaceSession; |
| 112 | import android.view.View; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | import android.view.WindowManager; |
| 114 | import android.view.WindowManagerImpl; |
| 115 | import android.view.WindowManagerPolicy; |
| 116 | import android.view.WindowManager.LayoutParams; |
| 117 | import android.view.animation.Animation; |
| 118 | import android.view.animation.AnimationUtils; |
| 119 | import android.view.animation.Transformation; |
| 120 | |
| 121 | import java.io.BufferedWriter; |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 122 | import java.io.DataInputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | import java.io.File; |
| 124 | import java.io.FileDescriptor; |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 125 | import java.io.FileInputStream; |
| 126 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | import java.io.IOException; |
| 128 | import java.io.OutputStream; |
| 129 | import java.io.OutputStreamWriter; |
| 130 | import java.io.PrintWriter; |
| 131 | import java.io.StringWriter; |
| 132 | import java.net.Socket; |
| 133 | import java.util.ArrayList; |
| 134 | import java.util.HashMap; |
| 135 | import java.util.HashSet; |
| 136 | import java.util.Iterator; |
| 137 | import java.util.List; |
| 138 | |
| 139 | /** {@hide} */ |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 140 | public class WindowManagerService extends IWindowManager.Stub |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 141 | implements Watchdog.Monitor { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | static final String TAG = "WindowManager"; |
| 143 | static final boolean DEBUG = false; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 144 | static final boolean DEBUG_ADD_REMOVE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | static final boolean DEBUG_FOCUS = false; |
| 146 | static final boolean DEBUG_ANIM = false; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 147 | static final boolean DEBUG_LAYOUT = false; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 148 | static final boolean DEBUG_RESIZE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | static final boolean DEBUG_LAYERS = false; |
| 150 | static final boolean DEBUG_INPUT = false; |
| 151 | static final boolean DEBUG_INPUT_METHOD = false; |
| 152 | static final boolean DEBUG_VISIBILITY = false; |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 153 | static final boolean DEBUG_WINDOW_MOVEMENT = false; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 154 | static final boolean DEBUG_TOKEN_MOVEMENT = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | static final boolean DEBUG_ORIENTATION = false; |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 156 | static final boolean DEBUG_CONFIGURATION = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 158 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 159 | static final boolean DEBUG_REORDER = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 160 | static final boolean DEBUG_WALLPAPER = false; |
Christopher Tate | 994ef92 | 2011-01-12 20:06:07 -0800 | [diff] [blame] | 161 | static final boolean DEBUG_DRAG = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | static final boolean SHOW_TRANSACTIONS = false; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 163 | static final boolean HIDE_STACK_CRAWLS = true; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 164 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | static final boolean PROFILE_ORIENTATION = false; |
| 166 | static final boolean BLUR = true; |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 167 | static final boolean localLOGV = DEBUG; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 168 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | /** How much to multiply the policy's type layer, to reserve room |
| 170 | * for multiple windows of the same type and Z-ordering adjustment |
| 171 | * with TYPE_LAYER_OFFSET. */ |
| 172 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 173 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 175 | * or below others in the same layer. */ |
| 176 | static final int TYPE_LAYER_OFFSET = 1000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 177 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | /** How much to increment the layer for each window, to reserve room |
| 179 | * for effect surfaces between them. |
| 180 | */ |
| 181 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 182 | |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 183 | /** |
| 184 | * Dim surface layer is immediately below target window. |
| 185 | */ |
| 186 | static final int LAYER_OFFSET_DIM = 1; |
| 187 | |
| 188 | /** |
| 189 | * Blur surface layer is immediately below dim layer. |
| 190 | */ |
| 191 | static final int LAYER_OFFSET_BLUR = 2; |
| 192 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | /** The maximum length we will accept for a loaded animation duration: |
| 194 | * this is 10 seconds. |
| 195 | */ |
| 196 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 197 | |
| 198 | /** Amount of time (in milliseconds) to animate the dim surface from one |
| 199 | * value to another, when no window animation is driving it. |
| 200 | */ |
| 201 | static final int DEFAULT_DIM_DURATION = 200; |
| 202 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 203 | /** Amount of time (in milliseconds) to animate the fade-in-out transition for |
| 204 | * compatible windows. |
| 205 | */ |
| 206 | static final int DEFAULT_FADE_IN_OUT_DURATION = 400; |
| 207 | |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 208 | /** |
| 209 | * If true, the window manager will do its own custom freezing and general |
| 210 | * management of the screen during rotation. |
| 211 | */ |
| 212 | static final boolean CUSTOM_SCREEN_ROTATION = true; |
| 213 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 214 | // Maximum number of milliseconds to wait for input event injection. |
| 215 | // FIXME is this value reasonable? |
| 216 | private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000; |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 217 | |
| 218 | // Maximum number of milliseconds to wait for input devices to be enumerated before |
| 219 | // proceding with safe mode detection. |
| 220 | 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] | 221 | |
| 222 | // Default input dispatching timeout in nanoseconds. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 223 | static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 224 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 226 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 227 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 228 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 229 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | private static final String SYSTEM_SECURE = "ro.secure"; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 231 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | |
| 233 | /** |
| 234 | * Condition waited on by {@link #reenableKeyguard} to know the call to |
| 235 | * the window policy has finished. |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 236 | * This is set to true only if mKeyguardTokenWatcher.acquired() has |
| 237 | * actually disabled the keyguard. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | */ |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 239 | private boolean mKeyguardDisabled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 241 | private static final int ALLOW_DISABLE_YES = 1; |
| 242 | private static final int ALLOW_DISABLE_NO = 0; |
| 243 | private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager |
| 244 | private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher |
| 245 | |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 246 | final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher( |
| 247 | new Handler(), "WindowManagerService.mKeyguardTokenWatcher") { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | public void acquired() { |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 249 | if (shouldAllowDisableKeyguard()) { |
| 250 | mPolicy.enableKeyguard(false); |
| 251 | mKeyguardDisabled = true; |
| 252 | } else { |
| 253 | Log.v(TAG, "Not disabling keyguard since device policy is enforced"); |
| 254 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | } |
| 256 | public void released() { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 257 | mPolicy.enableKeyguard(true); |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 258 | synchronized (mKeyguardTokenWatcher) { |
| 259 | mKeyguardDisabled = false; |
| 260 | mKeyguardTokenWatcher.notifyAll(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | } |
| 262 | } |
| 263 | }; |
| 264 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 265 | final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 266 | @Override |
| 267 | public void onReceive(Context context, Intent intent) { |
| 268 | mPolicy.enableKeyguard(true); |
| 269 | synchronized(mKeyguardTokenWatcher) { |
| 270 | // lazily evaluate this next time we're asked to disable keyguard |
| 271 | mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; |
| 272 | mKeyguardDisabled = false; |
| 273 | } |
| 274 | } |
| 275 | }; |
| 276 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 277 | final Context mContext; |
| 278 | |
| 279 | final boolean mHaveInputMethods; |
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 boolean mLimitedAlphaCompositing; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 282 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 283 | final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 284 | |
| 285 | final IActivityManager mActivityManager; |
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 | final IBatteryStats mBatteryStats; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 288 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 289 | /** |
| 290 | * All currently active sessions with clients. |
| 291 | */ |
| 292 | final HashSet<Session> mSessions = new HashSet<Session>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 293 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 294 | /** |
| 295 | * Mapping from an IWindow IBinder to the server's Window object. |
| 296 | * This is also used as the lock for all of our state. |
| 297 | */ |
| 298 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 299 | |
| 300 | /** |
| 301 | * Mapping from a token IBinder to a WindowToken object. |
| 302 | */ |
| 303 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 304 | new HashMap<IBinder, WindowToken>(); |
| 305 | |
| 306 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 307 | * Window tokens that are in the process of exiting, but still |
| 308 | * on screen for animations. |
| 309 | */ |
| 310 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 311 | |
| 312 | /** |
| 313 | * Z-ordered (bottom-most first) list of all application tokens, for |
| 314 | * controlling the ordering of windows in different applications. This |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 315 | * contains AppWindowToken objects. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 316 | */ |
| 317 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
| 318 | |
| 319 | /** |
| 320 | * Application tokens that are in the process of exiting, but still |
| 321 | * on screen for animations. |
| 322 | */ |
| 323 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 324 | |
| 325 | /** |
| 326 | * List of window tokens that have finished starting their application, |
| 327 | * and now need to have the policy remove their windows. |
| 328 | */ |
| 329 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 330 | |
| 331 | /** |
| 332 | * Z-ordered (bottom-most first) list of all Window objects. |
| 333 | */ |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 334 | final ArrayList<WindowState> mWindows = new ArrayList<WindowState>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 335 | |
| 336 | /** |
| 337 | * Windows that are being resized. Used so we can tell the client about |
| 338 | * the resize after closing the transaction in which we resized the |
| 339 | * underlying surface. |
| 340 | */ |
| 341 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 342 | |
| 343 | /** |
| 344 | * Windows whose animations have ended and now must be removed. |
| 345 | */ |
| 346 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 347 | |
| 348 | /** |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 349 | * Used when processing mPendingRemove to avoid working on the original array. |
| 350 | */ |
| 351 | WindowState[] mPendingRemoveTmp = new WindowState[20]; |
| 352 | |
| 353 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 354 | * Windows whose surface should be destroyed. |
| 355 | */ |
| 356 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 357 | |
| 358 | /** |
| 359 | * Windows that have lost input focus and are waiting for the new |
| 360 | * focus window to be displayed before they are told about this. |
| 361 | */ |
| 362 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 363 | |
| 364 | /** |
| 365 | * This is set when we have run out of memory, and will either be an empty |
| 366 | * list or contain windows that need to be force removed. |
| 367 | */ |
| 368 | ArrayList<WindowState> mForceRemoves; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 369 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 370 | /** |
| 371 | * Used when rebuilding window list to keep track of windows that have |
| 372 | * been removed. |
| 373 | */ |
| 374 | WindowState[] mRebuildTmp = new WindowState[20]; |
| 375 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | IInputMethodManager mInputMethodManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 377 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | SurfaceSession mFxSession; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 379 | private DimAnimator mDimAnimator = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | Surface mBlurSurface; |
| 381 | boolean mBlurShown; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 382 | Watermark mWatermark; |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 383 | StrictModeFlash mStrictModeFlash; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 384 | ScreenRotationAnimation mScreenRotationAnimation; |
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 | int mTransactionSequence = 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 387 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | final float[] mTmpFloats = new float[9]; |
| 389 | |
| 390 | boolean mSafeMode; |
| 391 | boolean mDisplayEnabled = false; |
| 392 | boolean mSystemBooted = false; |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 393 | int mInitialDisplayWidth = 0; |
| 394 | int mInitialDisplayHeight = 0; |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 395 | int mCurDisplayWidth = 0; |
| 396 | int mCurDisplayHeight = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | int mRotation = 0; |
| 398 | int mRequestedRotation = 0; |
| 399 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 400 | boolean mAltOrientation = false; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 401 | int mLastRotationFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | ArrayList<IRotationWatcher> mRotationWatchers |
| 403 | = new ArrayList<IRotationWatcher>(); |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 404 | int mDeferredRotation; |
| 405 | int mDeferredRotationAnimFlags; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 406 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 407 | boolean mLayoutNeeded = true; |
| 408 | boolean mAnimationPending = false; |
| 409 | boolean mDisplayFrozen = false; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 410 | boolean mWaitingForConfig = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | boolean mWindowsFreezingScreen = false; |
| 412 | long mFreezeGcPending = 0; |
| 413 | int mAppsFreezingScreen = 0; |
| 414 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 415 | int mLayoutSeq = 0; |
| 416 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 417 | // State while inside of layoutAndPlaceSurfacesLocked(). |
| 418 | boolean mFocusMayChange; |
| 419 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 420 | Configuration mCurConfiguration = new Configuration(); |
| 421 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 422 | // This is held as long as we have the screen frozen, to give us time to |
| 423 | // perform a rotation animation when turning off shows the lock screen which |
| 424 | // changes the orientation. |
| 425 | PowerManager.WakeLock mScreenFrozenLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 426 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 427 | // State management of app transitions. When we are preparing for a |
| 428 | // transition, mNextAppTransition will be the kind of transition to |
| 429 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 430 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 431 | // made visible or hidden at the next transition. |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 432 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 433 | String mNextAppTransitionPackage; |
| 434 | int mNextAppTransitionEnter; |
| 435 | int mNextAppTransitionExit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 436 | boolean mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 437 | boolean mAppTransitionRunning = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 438 | boolean mAppTransitionTimeout = false; |
| 439 | boolean mStartingIconInTransition = false; |
| 440 | boolean mSkipAppTransitionAnimation = false; |
| 441 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 442 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 443 | final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>(); |
| 444 | final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>(); |
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 | Display mDisplay; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 447 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | H mH = new H(); |
| 449 | |
| 450 | WindowState mCurrentFocus = null; |
| 451 | WindowState mLastFocus = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 452 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 453 | // This just indicates the window the input method is on top of, not |
| 454 | // necessarily the window its input is going to. |
| 455 | WindowState mInputMethodTarget = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 456 | boolean mInputMethodTargetWaitingAnim; |
| 457 | int mInputMethodAnimLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 458 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 459 | WindowState mInputMethodWindow = null; |
| 460 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 461 | |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 462 | boolean mHardKeyboardAvailable; |
| 463 | boolean mHardKeyboardEnabled; |
| 464 | OnHardKeyboardStatusChangeListener mHardKeyboardStatusChangeListener; |
| 465 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 466 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 467 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 468 | // If non-null, this is the currently visible window that is associated |
| 469 | // with the wallpaper. |
| 470 | WindowState mWallpaperTarget = null; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 471 | // If non-null, we are in the middle of animating from one wallpaper target |
| 472 | // to another, and this is the lower one in Z-order. |
| 473 | WindowState mLowerWallpaperTarget = null; |
| 474 | // If non-null, we are in the middle of animating from one wallpaper target |
| 475 | // to another, and this is the higher one in Z-order. |
| 476 | WindowState mUpperWallpaperTarget = null; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 477 | // Window currently running an animation that has requested it be detached |
| 478 | // from the wallpaper. This means we need to ensure the wallpaper is |
| 479 | // visible behind it in case it animates in a way that would allow it to be |
| 480 | // seen. |
| 481 | WindowState mWindowDetachedWallpaper = null; |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 482 | DimSurface mWindowAnimationBackgroundSurface = null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 483 | int mWallpaperAnimLayerAdjustment; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 484 | float mLastWallpaperX = -1; |
| 485 | float mLastWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 486 | float mLastWallpaperXStep = -1; |
| 487 | float mLastWallpaperYStep = -1; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 488 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 489 | // changing its scroll position. |
| 490 | WindowState mWaitingOnWallpaper; |
| 491 | // The last time we had a timeout when waiting for a wallpaper. |
| 492 | long mLastWallpaperTimeoutTime; |
| 493 | // We give a wallpaper up to 150ms to finish scrolling. |
| 494 | static final long WALLPAPER_TIMEOUT = 150; |
| 495 | // Time we wait after a timeout before trying to wait again. |
| 496 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 497 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 498 | AppWindowToken mFocusedApp = null; |
| 499 | |
| 500 | PowerManagerService mPowerManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 501 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 502 | float mWindowAnimationScale = 1.0f; |
| 503 | float mTransitionAnimationScale = 1.0f; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 504 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 505 | final InputManager mInputManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 506 | |
| 507 | // Who is holding the screen on. |
| 508 | Session mHoldingScreenOn; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 509 | PowerManager.WakeLock mHoldingScreenWakeLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 510 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 511 | boolean mTurnOnScreen; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 512 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 513 | DragState mDragState = null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 514 | final InputHandler mDragInputHandler = new BaseInputHandler() { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 515 | @Override |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 516 | public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) { |
| 517 | boolean handled = false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 518 | try { |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 519 | if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0 |
| 520 | && mDragState != null) { |
| 521 | boolean endDrag = false; |
| 522 | final float newX = event.getRawX(); |
| 523 | final float newY = event.getRawY(); |
| 524 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 525 | switch (event.getAction()) { |
| 526 | case MotionEvent.ACTION_DOWN: { |
| 527 | if (DEBUG_DRAG) { |
| 528 | Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer"); |
| 529 | } |
| 530 | } break; |
| 531 | |
| 532 | case MotionEvent.ACTION_MOVE: { |
| 533 | synchronized (mWindowMap) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 534 | // move the surface and tell the involved window(s) where we are |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 535 | mDragState.notifyMoveLw(newX, newY); |
| 536 | } |
| 537 | } break; |
| 538 | |
| 539 | case MotionEvent.ACTION_UP: { |
| 540 | if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at " |
| 541 | + newX + "," + newY); |
| 542 | synchronized (mWindowMap) { |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 543 | endDrag = mDragState.notifyDropLw(newX, newY); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 544 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 545 | } break; |
| 546 | |
| 547 | case MotionEvent.ACTION_CANCEL: { |
| 548 | if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!"); |
| 549 | endDrag = true; |
| 550 | } break; |
| 551 | } |
| 552 | |
| 553 | if (endDrag) { |
| 554 | if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state"); |
| 555 | // tell all the windows that the drag has ended |
Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 556 | synchronized (mWindowMap) { |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 557 | mDragState.endDragLw(); |
Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 558 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 559 | } |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 560 | |
| 561 | handled = true; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 562 | } |
| 563 | } catch (Exception e) { |
| 564 | Slog.e(TAG, "Exception caught by drag handleMotion", e); |
| 565 | } finally { |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 566 | finishedCallback.finished(handled); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 567 | } |
| 568 | } |
| 569 | }; |
| 570 | |
| 571 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 572 | * Whether the UI is currently running in touch mode (not showing |
| 573 | * navigational focus because the user is directly pressing the screen). |
| 574 | */ |
| 575 | boolean mInTouchMode = false; |
| 576 | |
| 577 | private ViewServer mViewServer; |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 578 | private ArrayList<WindowChangeListener> mWindowChangeListeners = |
| 579 | new ArrayList<WindowChangeListener>(); |
| 580 | private boolean mWindowsChanged = false; |
| 581 | |
| 582 | public interface WindowChangeListener { |
| 583 | public void windowsChanged(); |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 584 | public void focusChanged(); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 585 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 586 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 587 | final Configuration mTempConfiguration = new Configuration(); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 588 | |
| 589 | // The frame use to limit the size of the app running in compatibility mode. |
| 590 | Rect mCompatibleScreenFrame = new Rect(); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 591 | float mCompatibleScreenScale; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 592 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 593 | Surface mBackgroundFillerSurface = null; |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 594 | WindowState mBackgroundFillerTarget = null; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 595 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 596 | public static WindowManagerService main(Context context, |
| 597 | PowerManagerService pm, boolean haveInputMethods) { |
| 598 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 599 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 600 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 601 | synchronized (thr) { |
| 602 | while (thr.mService == null) { |
| 603 | try { |
| 604 | thr.wait(); |
| 605 | } catch (InterruptedException e) { |
| 606 | } |
| 607 | } |
Jozef BABJAK | 06e57b5 | 2011-01-20 08:09:25 +0100 | [diff] [blame] | 608 | return thr.mService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 609 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 610 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 611 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 612 | static class WMThread extends Thread { |
| 613 | WindowManagerService mService; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 614 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 615 | private final Context mContext; |
| 616 | private final PowerManagerService mPM; |
| 617 | private final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 618 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 619 | public WMThread(Context context, PowerManagerService pm, |
| 620 | boolean haveInputMethods) { |
| 621 | super("WindowManager"); |
| 622 | mContext = context; |
| 623 | mPM = pm; |
| 624 | mHaveInputMethods = haveInputMethods; |
| 625 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 626 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 627 | public void run() { |
| 628 | Looper.prepare(); |
| 629 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 630 | mHaveInputMethods); |
| 631 | android.os.Process.setThreadPriority( |
| 632 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 633 | android.os.Process.setCanSelfBackground(false); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 634 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 635 | synchronized (this) { |
| 636 | mService = s; |
| 637 | notifyAll(); |
| 638 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 639 | |
Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 640 | // For debug builds, log event loop stalls to dropbox for analysis. |
| 641 | if (StrictMode.conditionallyEnableDebugLogging()) { |
| 642 | Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper"); |
| 643 | } |
| 644 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 645 | Looper.loop(); |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | static class PolicyThread extends Thread { |
| 650 | private final WindowManagerPolicy mPolicy; |
| 651 | private final WindowManagerService mService; |
| 652 | private final Context mContext; |
| 653 | private final PowerManagerService mPM; |
| 654 | boolean mRunning = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 655 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 656 | public PolicyThread(WindowManagerPolicy policy, |
| 657 | WindowManagerService service, Context context, |
| 658 | PowerManagerService pm) { |
| 659 | super("WindowManagerPolicy"); |
| 660 | mPolicy = policy; |
| 661 | mService = service; |
| 662 | mContext = context; |
| 663 | mPM = pm; |
| 664 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 665 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 666 | public void run() { |
| 667 | Looper.prepare(); |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 668 | WindowManagerPolicyThread.set(this, Looper.myLooper()); |
| 669 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 670 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 671 | // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 672 | android.os.Process.setThreadPriority( |
| 673 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 674 | android.os.Process.setCanSelfBackground(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 675 | mPolicy.init(mContext, mService, mPM); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 676 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 677 | synchronized (this) { |
| 678 | mRunning = true; |
| 679 | notifyAll(); |
| 680 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 681 | |
Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 682 | // For debug builds, log event loop stalls to dropbox for analysis. |
| 683 | if (StrictMode.conditionallyEnableDebugLogging()) { |
| 684 | Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper"); |
| 685 | } |
| 686 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 687 | Looper.loop(); |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | private WindowManagerService(Context context, PowerManagerService pm, |
| 692 | boolean haveInputMethods) { |
| 693 | mContext = context; |
| 694 | mHaveInputMethods = haveInputMethods; |
| 695 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 696 | com.android.internal.R.bool.config_sf_limitedAlpha); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 697 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 698 | mPowerManager = pm; |
| 699 | mPowerManager.setPolicy(mPolicy); |
| 700 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 701 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 702 | "SCREEN_FROZEN"); |
| 703 | mScreenFrozenLock.setReferenceCounted(false); |
| 704 | |
| 705 | mActivityManager = ActivityManagerNative.getDefault(); |
| 706 | mBatteryStats = BatteryStatsService.getService(); |
| 707 | |
| 708 | // Get persisted window scale setting |
| 709 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 710 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 711 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 712 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 713 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 714 | // Track changes to DevicePolicyManager state so we can enable/disable keyguard. |
| 715 | IntentFilter filter = new IntentFilter(); |
| 716 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 717 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 718 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 719 | mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 720 | "KEEP_SCREEN_ON_FLAG"); |
| 721 | mHoldingScreenWakeLock.setReferenceCounted(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 722 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 723 | mInputManager = new InputManager(context, this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 724 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 725 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 726 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 727 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 728 | synchronized (thr) { |
| 729 | while (!thr.mRunning) { |
| 730 | try { |
| 731 | thr.wait(); |
| 732 | } catch (InterruptedException e) { |
| 733 | } |
| 734 | } |
| 735 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 736 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 737 | mInputManager.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 738 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 739 | // Add ourself to the Watchdog monitors. |
| 740 | Watchdog.getInstance().addMonitor(this); |
| 741 | } |
| 742 | |
| 743 | @Override |
| 744 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 745 | throws RemoteException { |
| 746 | try { |
| 747 | return super.onTransact(code, data, reply, flags); |
| 748 | } catch (RuntimeException e) { |
| 749 | // The window manager only throws security exceptions, so let's |
| 750 | // log all others. |
| 751 | if (!(e instanceof SecurityException)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 752 | Slog.e(TAG, "Window Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 753 | } |
| 754 | throw e; |
| 755 | } |
| 756 | } |
| 757 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 758 | private void placeWindowAfter(WindowState pos, WindowState window) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 759 | final int i = mWindows.indexOf(pos); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 760 | 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] | 761 | TAG, "Adding window " + window + " at " |
| 762 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 763 | mWindows.add(i+1, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 764 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 765 | } |
| 766 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 767 | private void placeWindowBefore(WindowState pos, WindowState window) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 768 | final int i = mWindows.indexOf(pos); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 769 | 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] | 770 | TAG, "Adding window " + window + " at " |
| 771 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 772 | mWindows.add(i, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 773 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | //This method finds out the index of a window that has the same app token as |
| 777 | //win. used for z ordering the windows in mWindows |
| 778 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 779 | //use a local variable to cache mWindows |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 780 | ArrayList<WindowState> localmWindows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 781 | int jmax = localmWindows.size(); |
| 782 | if(jmax == 0) { |
| 783 | return -1; |
| 784 | } |
| 785 | for(int j = (jmax-1); j >= 0; j--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 786 | WindowState wentry = localmWindows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 787 | if(wentry.mAppToken == win.mAppToken) { |
| 788 | return j; |
| 789 | } |
| 790 | } |
| 791 | return -1; |
| 792 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 793 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 794 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 795 | final IWindow client = win.mClient; |
| 796 | final WindowToken token = win.mToken; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 797 | final ArrayList<WindowState> localmWindows = mWindows; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 798 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 799 | final int N = localmWindows.size(); |
| 800 | final WindowState attached = win.mAttachedWindow; |
| 801 | int i; |
| 802 | if (attached == null) { |
| 803 | int tokenWindowsPos = token.windows.size(); |
| 804 | if (token.appWindowToken != null) { |
| 805 | int index = tokenWindowsPos-1; |
| 806 | if (index >= 0) { |
| 807 | // If this application has existing windows, we |
| 808 | // simply place the new window on top of them... but |
| 809 | // keep the starting window on top. |
| 810 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 811 | // Base windows go behind everything else. |
| 812 | placeWindowBefore(token.windows.get(0), win); |
| 813 | tokenWindowsPos = 0; |
| 814 | } else { |
| 815 | AppWindowToken atoken = win.mAppToken; |
| 816 | if (atoken != null && |
| 817 | token.windows.get(index) == atoken.startingWindow) { |
| 818 | placeWindowBefore(token.windows.get(index), win); |
| 819 | tokenWindowsPos--; |
| 820 | } else { |
| 821 | int newIdx = findIdxBasedOnAppTokens(win); |
| 822 | if(newIdx != -1) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 823 | //there is a window above this one associated with the same |
| 824 | //apptoken note that the window could be a floating window |
| 825 | //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] | 826 | //windows associated with this token. |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 827 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 828 | Slog.v(TAG, "Adding window " + win + " at " |
| 829 | + (newIdx+1) + " of " + N); |
| 830 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 831 | localmWindows.add(newIdx+1, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 832 | mWindowsChanged = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 833 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 834 | } |
| 835 | } |
| 836 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 837 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 838 | TAG, "Figuring out where to add app window " |
| 839 | + client.asBinder() + " (token=" + token + ")"); |
| 840 | // Figure out where the window should go, based on the |
| 841 | // order of applications. |
| 842 | final int NA = mAppTokens.size(); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 843 | WindowState pos = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 844 | for (i=NA-1; i>=0; i--) { |
| 845 | AppWindowToken t = mAppTokens.get(i); |
| 846 | if (t == token) { |
| 847 | i--; |
| 848 | break; |
| 849 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 850 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 851 | // We haven't reached the token yet; if this token |
| 852 | // is not going to the bottom and has windows, we can |
| 853 | // use it as an anchor for when we do reach the token. |
| 854 | if (!t.sendingToBottom && t.windows.size() > 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 855 | pos = t.windows.get(0); |
| 856 | } |
| 857 | } |
| 858 | // We now know the index into the apps. If we found |
| 859 | // an app window above, that gives us the position; else |
| 860 | // we need to look some more. |
| 861 | if (pos != null) { |
| 862 | // Move behind any windows attached to this one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 863 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 864 | if (atoken != null) { |
| 865 | final int NC = atoken.windows.size(); |
| 866 | if (NC > 0) { |
| 867 | WindowState bottom = atoken.windows.get(0); |
| 868 | if (bottom.mSubLayer < 0) { |
| 869 | pos = bottom; |
| 870 | } |
| 871 | } |
| 872 | } |
| 873 | placeWindowBefore(pos, win); |
| 874 | } else { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 875 | // Continue looking down until we find the first |
| 876 | // token that has windows. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 877 | while (i >= 0) { |
| 878 | AppWindowToken t = mAppTokens.get(i); |
| 879 | final int NW = t.windows.size(); |
| 880 | if (NW > 0) { |
| 881 | pos = t.windows.get(NW-1); |
| 882 | break; |
| 883 | } |
| 884 | i--; |
| 885 | } |
| 886 | if (pos != null) { |
| 887 | // Move in front of any windows attached to this |
| 888 | // one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 889 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 890 | if (atoken != null) { |
| 891 | final int NC = atoken.windows.size(); |
| 892 | if (NC > 0) { |
| 893 | WindowState top = atoken.windows.get(NC-1); |
| 894 | if (top.mSubLayer >= 0) { |
| 895 | pos = top; |
| 896 | } |
| 897 | } |
| 898 | } |
| 899 | placeWindowAfter(pos, win); |
| 900 | } else { |
| 901 | // Just search for the start of this layer. |
| 902 | final int myLayer = win.mBaseLayer; |
| 903 | for (i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 904 | WindowState w = localmWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 905 | if (w.mBaseLayer > myLayer) { |
| 906 | break; |
| 907 | } |
| 908 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 909 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 910 | Slog.v(TAG, "Adding window " + win + " at " |
| 911 | + i + " of " + N); |
| 912 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 913 | localmWindows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 914 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 915 | } |
| 916 | } |
| 917 | } |
| 918 | } else { |
| 919 | // Figure out where window should go, based on layer. |
| 920 | final int myLayer = win.mBaseLayer; |
| 921 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 922 | if (localmWindows.get(i).mBaseLayer <= myLayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 923 | i++; |
| 924 | break; |
| 925 | } |
| 926 | } |
| 927 | if (i < 0) i = 0; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 928 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 929 | TAG, "Adding window " + win + " at " |
| 930 | + i + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 931 | localmWindows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 932 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 933 | } |
| 934 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 935 | 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] | 936 | token.windows.add(tokenWindowsPos, win); |
| 937 | } |
| 938 | |
| 939 | } else { |
| 940 | // Figure out this window's ordering relative to the window |
| 941 | // it is attached to. |
| 942 | final int NA = token.windows.size(); |
| 943 | final int sublayer = win.mSubLayer; |
| 944 | int largestSublayer = Integer.MIN_VALUE; |
| 945 | WindowState windowWithLargestSublayer = null; |
| 946 | for (i=0; i<NA; i++) { |
| 947 | WindowState w = token.windows.get(i); |
| 948 | final int wSublayer = w.mSubLayer; |
| 949 | if (wSublayer >= largestSublayer) { |
| 950 | largestSublayer = wSublayer; |
| 951 | windowWithLargestSublayer = w; |
| 952 | } |
| 953 | if (sublayer < 0) { |
| 954 | // For negative sublayers, we go below all windows |
| 955 | // in the same sublayer. |
| 956 | if (wSublayer >= sublayer) { |
| 957 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 958 | 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] | 959 | token.windows.add(i, win); |
| 960 | } |
| 961 | placeWindowBefore( |
| 962 | wSublayer >= 0 ? attached : w, win); |
| 963 | break; |
| 964 | } |
| 965 | } else { |
| 966 | // For positive sublayers, we go above all windows |
| 967 | // in the same sublayer. |
| 968 | if (wSublayer > sublayer) { |
| 969 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 970 | 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] | 971 | token.windows.add(i, win); |
| 972 | } |
| 973 | placeWindowBefore(w, win); |
| 974 | break; |
| 975 | } |
| 976 | } |
| 977 | } |
| 978 | if (i >= NA) { |
| 979 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 980 | 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] | 981 | token.windows.add(win); |
| 982 | } |
| 983 | if (sublayer < 0) { |
| 984 | placeWindowBefore(attached, win); |
| 985 | } else { |
| 986 | placeWindowAfter(largestSublayer >= 0 |
| 987 | ? windowWithLargestSublayer |
| 988 | : attached, |
| 989 | win); |
| 990 | } |
| 991 | } |
| 992 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 993 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 994 | if (win.mAppToken != null && addToToken) { |
| 995 | win.mAppToken.allAppWindows.add(win); |
| 996 | } |
| 997 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 998 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 999 | static boolean canBeImeTarget(WindowState w) { |
| 1000 | final int fl = w.mAttrs.flags |
| 1001 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1002 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM) |
| 1003 | || w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 1004 | if (DEBUG_INPUT_METHOD) { |
| 1005 | Slog.i(TAG, "isVisibleOrAdding " + w + ": " + w.isVisibleOrAdding()); |
| 1006 | if (!w.isVisibleOrAdding()) { |
| 1007 | Slog.i(TAG, " mSurface=" + w.mSurface + " reportDestroy=" + w.mReportDestroySurface |
| 1008 | + " relayoutCalled=" + w.mRelayoutCalled + " viewVis=" + w.mViewVisibility |
| 1009 | + " policyVis=" + w.mPolicyVisibility + " attachHid=" + w.mAttachedHidden |
| 1010 | + " exiting=" + w.mExiting + " destroying=" + w.mDestroying); |
| 1011 | if (w.mAppToken != null) { |
| 1012 | Slog.i(TAG, " mAppToken.hiddenRequested=" + w.mAppToken.hiddenRequested); |
| 1013 | } |
| 1014 | } |
| 1015 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1016 | return w.isVisibleOrAdding(); |
| 1017 | } |
| 1018 | return false; |
| 1019 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1020 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1021 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1022 | final ArrayList<WindowState> localmWindows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1023 | final int N = localmWindows.size(); |
| 1024 | WindowState w = null; |
| 1025 | int i = N; |
| 1026 | while (i > 0) { |
| 1027 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1028 | w = localmWindows.get(i); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1029 | |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1030 | if (DEBUG_INPUT_METHOD && willMove) Slog.i(TAG, "Checking window @" + i |
| 1031 | + " " + w + " fl=0x" + Integer.toHexString(w.mAttrs.flags)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1032 | if (canBeImeTarget(w)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1033 | //Slog.i(TAG, "Putting input method here!"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1034 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1035 | // Yet more tricksyness! If this window is a "starting" |
| 1036 | // window, we do actually want to be on top of it, but |
| 1037 | // it is not -really- where input will go. So if the caller |
| 1038 | // is not actually looking to move the IME, look down below |
| 1039 | // for a real window to target... |
| 1040 | if (!willMove |
| 1041 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 1042 | && i > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1043 | WindowState wb = localmWindows.get(i-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1044 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 1045 | i--; |
| 1046 | w = wb; |
| 1047 | } |
| 1048 | } |
| 1049 | break; |
| 1050 | } |
| 1051 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1052 | |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1053 | if (DEBUG_INPUT_METHOD && willMove) Slog.v(TAG, "Proposed new IME target: " + w); |
| 1054 | |
Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1055 | // Now, a special case -- if the last target's window is in the |
| 1056 | // process of exiting, and is above the new target, keep on the |
| 1057 | // last target to avoid flicker. Consider for example a Dialog with |
| 1058 | // the IME shown: when the Dialog is dismissed, we want to keep |
| 1059 | // the IME above it until it is completely gone so it doesn't drop |
| 1060 | // behind the dialog or its full-screen scrim. |
| 1061 | if (mInputMethodTarget != null && w != null |
| 1062 | && mInputMethodTarget.isDisplayedLw() |
| 1063 | && mInputMethodTarget.mExiting) { |
| 1064 | if (mInputMethodTarget.mAnimLayer > w.mAnimLayer) { |
| 1065 | w = mInputMethodTarget; |
| 1066 | i = localmWindows.indexOf(w); |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1067 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Current target higher, switching to: " + w); |
Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1068 | } |
| 1069 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1070 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1071 | 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] | 1072 | + w + " willMove=" + willMove); |
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 | if (willMove && w != null) { |
| 1075 | final WindowState curTarget = mInputMethodTarget; |
| 1076 | if (curTarget != null && curTarget.mAppToken != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1077 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1078 | // Now some fun for dealing with window animations that |
| 1079 | // modify the Z order. We need to look at all windows below |
| 1080 | // the current target that are in this app, finding the highest |
| 1081 | // visible one in layering. |
| 1082 | AppWindowToken token = curTarget.mAppToken; |
| 1083 | WindowState highestTarget = null; |
| 1084 | int highestPos = 0; |
| 1085 | if (token.animating || token.animation != null) { |
| 1086 | int pos = 0; |
| 1087 | pos = localmWindows.indexOf(curTarget); |
| 1088 | while (pos >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1089 | WindowState win = localmWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1090 | if (win.mAppToken != token) { |
| 1091 | break; |
| 1092 | } |
| 1093 | if (!win.mRemoved) { |
| 1094 | if (highestTarget == null || win.mAnimLayer > |
| 1095 | highestTarget.mAnimLayer) { |
| 1096 | highestTarget = win; |
| 1097 | highestPos = pos; |
| 1098 | } |
| 1099 | } |
| 1100 | pos--; |
| 1101 | } |
| 1102 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1103 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1104 | if (highestTarget != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1105 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1106 | + mNextAppTransition + " " + highestTarget |
| 1107 | + " animating=" + highestTarget.isAnimating() |
| 1108 | + " layer=" + highestTarget.mAnimLayer |
| 1109 | + " new layer=" + w.mAnimLayer); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1110 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1111 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1112 | // If we are currently setting up for an animation, |
| 1113 | // hold everything until we can find out what will happen. |
| 1114 | mInputMethodTargetWaitingAnim = true; |
| 1115 | mInputMethodTarget = highestTarget; |
| 1116 | return highestPos + 1; |
| 1117 | } else if (highestTarget.isAnimating() && |
| 1118 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 1119 | // If the window we are currently targeting is involved |
| 1120 | // with an animation, and it is on top of the next target |
| 1121 | // we will be over, then hold off on moving until |
| 1122 | // that is done. |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1123 | mInputMethodTargetWaitingAnim = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1124 | mInputMethodTarget = highestTarget; |
| 1125 | return highestPos + 1; |
| 1126 | } |
| 1127 | } |
| 1128 | } |
| 1129 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1130 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1131 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1132 | if (w != null) { |
| 1133 | if (willMove) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1134 | if (DEBUG_INPUT_METHOD) { |
| 1135 | RuntimeException e = null; |
| 1136 | if (!HIDE_STACK_CRAWLS) { |
| 1137 | e = new RuntimeException(); |
| 1138 | e.fillInStackTrace(); |
| 1139 | } |
| 1140 | Slog.w(TAG, "Moving IM target from " |
| 1141 | + mInputMethodTarget + " to " + w, e); |
| 1142 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1143 | mInputMethodTarget = w; |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1144 | mInputMethodTargetWaitingAnim = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1145 | if (w.mAppToken != null) { |
| 1146 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 1147 | } else { |
| 1148 | setInputMethodAnimLayerAdjustment(0); |
| 1149 | } |
| 1150 | } |
| 1151 | return i+1; |
| 1152 | } |
| 1153 | if (willMove) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1154 | if (DEBUG_INPUT_METHOD) { |
| 1155 | RuntimeException e = null; |
| 1156 | if (!HIDE_STACK_CRAWLS) { |
| 1157 | e = new RuntimeException(); |
| 1158 | e.fillInStackTrace(); |
| 1159 | } |
| 1160 | Slog.w(TAG, "Moving IM target from " |
| 1161 | + mInputMethodTarget + " to null", e); |
| 1162 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1163 | mInputMethodTarget = null; |
| 1164 | setInputMethodAnimLayerAdjustment(0); |
| 1165 | } |
| 1166 | return -1; |
| 1167 | } |
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 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1170 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1171 | if (pos >= 0) { |
| 1172 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1173 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1174 | TAG, "Adding input method window " + win + " at " + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1175 | mWindows.add(pos, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1176 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1177 | moveInputMethodDialogsLocked(pos+1); |
| 1178 | return; |
| 1179 | } |
| 1180 | win.mTargetAppToken = null; |
| 1181 | addWindowToListInOrderLocked(win, true); |
| 1182 | moveInputMethodDialogsLocked(pos); |
| 1183 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1184 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1185 | void setInputMethodAnimLayerAdjustment(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1186 | 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] | 1187 | mInputMethodAnimLayerAdjustment = adj; |
| 1188 | WindowState imw = mInputMethodWindow; |
| 1189 | if (imw != null) { |
| 1190 | imw.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1191 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1192 | + " anim layer: " + imw.mAnimLayer); |
| 1193 | int wi = imw.mChildWindows.size(); |
| 1194 | while (wi > 0) { |
| 1195 | wi--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1196 | WindowState cw = imw.mChildWindows.get(wi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1197 | cw.mAnimLayer = cw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1198 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1199 | + " anim layer: " + cw.mAnimLayer); |
| 1200 | } |
| 1201 | } |
| 1202 | int di = mInputMethodDialogs.size(); |
| 1203 | while (di > 0) { |
| 1204 | di --; |
| 1205 | imw = mInputMethodDialogs.get(di); |
| 1206 | imw.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1207 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1208 | + " anim layer: " + imw.mAnimLayer); |
| 1209 | } |
| 1210 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1211 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1212 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1213 | int wpos = mWindows.indexOf(win); |
| 1214 | if (wpos >= 0) { |
| 1215 | if (wpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1216 | 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] | 1217 | mWindows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1218 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1219 | int NC = win.mChildWindows.size(); |
| 1220 | while (NC > 0) { |
| 1221 | NC--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1222 | WindowState cw = win.mChildWindows.get(NC); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1223 | int cpos = mWindows.indexOf(cw); |
| 1224 | if (cpos >= 0) { |
| 1225 | if (cpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1226 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1227 | + cpos + ": " + cw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1228 | mWindows.remove(cpos); |
| 1229 | } |
| 1230 | } |
| 1231 | } |
| 1232 | return interestingPos; |
| 1233 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1234 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1235 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1236 | addWindowToListInOrderLocked(win, false); |
| 1237 | // This is a hack to get all of the child windows added as well |
| 1238 | // at the right position. Child windows should be rare and |
| 1239 | // this case should be rare, so it shouldn't be that big a deal. |
| 1240 | int wpos = mWindows.indexOf(win); |
| 1241 | if (wpos >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1242 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1243 | + ": " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1244 | mWindows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1245 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1246 | reAddWindowLocked(wpos, win); |
| 1247 | } |
| 1248 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1249 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1250 | void logWindowList(String prefix) { |
| 1251 | int N = mWindows.size(); |
| 1252 | while (N > 0) { |
| 1253 | N--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1254 | Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1255 | } |
| 1256 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1257 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1258 | void moveInputMethodDialogsLocked(int pos) { |
| 1259 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1260 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1261 | final int N = dialogs.size(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1262 | 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] | 1263 | for (int i=0; i<N; i++) { |
| 1264 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1265 | } |
| 1266 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1267 | Slog.v(TAG, "Window list w/pos=" + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1268 | logWindowList(" "); |
| 1269 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1270 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1271 | if (pos >= 0) { |
| 1272 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1273 | if (pos < mWindows.size()) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1274 | WindowState wp = mWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1275 | if (wp == mInputMethodWindow) { |
| 1276 | pos++; |
| 1277 | } |
| 1278 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1279 | 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] | 1280 | for (int i=0; i<N; i++) { |
| 1281 | WindowState win = dialogs.get(i); |
| 1282 | win.mTargetAppToken = targetAppToken; |
| 1283 | pos = reAddWindowLocked(pos, win); |
| 1284 | } |
| 1285 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1286 | Slog.v(TAG, "Final window list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1287 | logWindowList(" "); |
| 1288 | } |
| 1289 | return; |
| 1290 | } |
| 1291 | for (int i=0; i<N; i++) { |
| 1292 | WindowState win = dialogs.get(i); |
| 1293 | win.mTargetAppToken = null; |
| 1294 | reAddWindowToListInOrderLocked(win); |
| 1295 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1296 | Slog.v(TAG, "No IM target, final list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1297 | logWindowList(" "); |
| 1298 | } |
| 1299 | } |
| 1300 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1301 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1302 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1303 | final WindowState imWin = mInputMethodWindow; |
| 1304 | final int DN = mInputMethodDialogs.size(); |
| 1305 | if (imWin == null && DN == 0) { |
| 1306 | return false; |
| 1307 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1308 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1309 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1310 | if (imPos >= 0) { |
| 1311 | // In this case, the input method windows are to be placed |
| 1312 | // immediately above the window they are targeting. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1313 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1314 | // First check to see if the input method windows are already |
| 1315 | // located here, and contiguous. |
| 1316 | final int N = mWindows.size(); |
| 1317 | WindowState firstImWin = imPos < N |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1318 | ? mWindows.get(imPos) : null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1319 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1320 | // Figure out the actual input method window that should be |
| 1321 | // at the bottom of their stack. |
| 1322 | WindowState baseImWin = imWin != null |
| 1323 | ? imWin : mInputMethodDialogs.get(0); |
| 1324 | if (baseImWin.mChildWindows.size() > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1325 | WindowState cw = baseImWin.mChildWindows.get(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1326 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 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 (firstImWin == baseImWin) { |
| 1330 | // The windows haven't moved... but are they still contiguous? |
| 1331 | // First find the top IM window. |
| 1332 | int pos = imPos+1; |
| 1333 | while (pos < N) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1334 | if (!(mWindows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1335 | break; |
| 1336 | } |
| 1337 | pos++; |
| 1338 | } |
| 1339 | pos++; |
| 1340 | // Now there should be no more input method windows above. |
| 1341 | while (pos < N) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1342 | if ((mWindows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1343 | break; |
| 1344 | } |
| 1345 | pos++; |
| 1346 | } |
| 1347 | if (pos >= N) { |
| 1348 | // All is good! |
| 1349 | return false; |
| 1350 | } |
| 1351 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1352 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1353 | if (imWin != null) { |
| 1354 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1355 | Slog.v(TAG, "Moving IM from " + imPos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1356 | logWindowList(" "); |
| 1357 | } |
| 1358 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1359 | if (DEBUG_INPUT_METHOD) { |
Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1360 | 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] | 1361 | logWindowList(" "); |
| 1362 | } |
| 1363 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1364 | reAddWindowLocked(imPos, imWin); |
| 1365 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1366 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1367 | logWindowList(" "); |
| 1368 | } |
| 1369 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1370 | } else { |
| 1371 | moveInputMethodDialogsLocked(imPos); |
| 1372 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1373 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1374 | } else { |
| 1375 | // In this case, the input method windows go in a fixed layer, |
| 1376 | // because they aren't currently associated with a focus window. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1377 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1378 | if (imWin != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1379 | 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] | 1380 | tmpRemoveWindowLocked(0, imWin); |
| 1381 | imWin.mTargetAppToken = null; |
| 1382 | reAddWindowToListInOrderLocked(imWin); |
| 1383 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1384 | Slog.v(TAG, "List with no IM target:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1385 | logWindowList(" "); |
| 1386 | } |
| 1387 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1388 | } else { |
| 1389 | moveInputMethodDialogsLocked(-1);; |
| 1390 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1391 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1392 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1393 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1394 | if (needAssignLayers) { |
| 1395 | assignLayersLocked(); |
| 1396 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1397 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1398 | return true; |
| 1399 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1400 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1401 | void adjustInputMethodDialogsLocked() { |
| 1402 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1403 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1404 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1405 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1406 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured=" |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1407 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1408 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1409 | ? wallpaperTarget.mAppToken.animation : null) |
| 1410 | + " upper=" + mUpperWallpaperTarget |
| 1411 | + " lower=" + mLowerWallpaperTarget); |
| 1412 | return (wallpaperTarget != null |
| 1413 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1414 | && wallpaperTarget.mAppToken.animation != null))) |
| 1415 | || mUpperWallpaperTarget != null |
| 1416 | || mLowerWallpaperTarget != null; |
| 1417 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1418 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1419 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1420 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1421 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1422 | int adjustWallpaperWindowsLocked() { |
| 1423 | int changed = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1424 | |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 1425 | final int dw = mCurDisplayWidth; |
| 1426 | final int dh = mCurDisplayHeight; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1427 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1428 | // First find top-most window that has asked to be on top of the |
| 1429 | // wallpaper; all wallpapers go behind it. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1430 | final ArrayList<WindowState> localmWindows = mWindows; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1431 | int N = localmWindows.size(); |
| 1432 | WindowState w = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1433 | WindowState foundW = null; |
| 1434 | int foundI = 0; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1435 | WindowState topCurW = null; |
| 1436 | int topCurI = 0; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1437 | int windowDetachedI = -1; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1438 | int i = N; |
| 1439 | while (i > 0) { |
| 1440 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1441 | w = localmWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1442 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1443 | if (topCurW == null) { |
| 1444 | topCurW = w; |
| 1445 | topCurI = i; |
| 1446 | } |
| 1447 | continue; |
| 1448 | } |
| 1449 | topCurW = null; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1450 | if (w != mWindowDetachedWallpaper && w.mAppToken != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1451 | // If this window's app token is hidden and not animating, |
| 1452 | // it is of no interest to us. |
| 1453 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1454 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1455 | "Skipping not hidden or animating token: " + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1456 | continue; |
| 1457 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1458 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1459 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay=" |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1460 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1461 | + " commitdrawpending=" + w.mCommitDrawPending); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1462 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1463 | && (mWallpaperTarget == w |
| 1464 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1465 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1466 | "Found wallpaper activity: #" + i + "=" + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1467 | foundW = w; |
| 1468 | foundI = i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1469 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1470 | && w.mAppToken.animation != null) |
| 1471 | || w.mAnimation != null)) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1472 | // The current wallpaper target is animating, so we'll |
| 1473 | // look behind it for another possible target and figure |
| 1474 | // out what is going on below. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1475 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1476 | + ": token animating, looking behind."); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1477 | continue; |
| 1478 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1479 | break; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1480 | } else if (w == mWindowDetachedWallpaper) { |
| 1481 | windowDetachedI = i; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1482 | } |
| 1483 | } |
| 1484 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1485 | if (foundW == null && windowDetachedI >= 0) { |
| 1486 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 1487 | "Found animating detached wallpaper activity: #" + i + "=" + w); |
| 1488 | foundW = w; |
| 1489 | foundI = windowDetachedI; |
| 1490 | } |
| 1491 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1492 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1493 | // If we are currently waiting for an app transition, and either |
| 1494 | // the current target or the next target are involved with it, |
| 1495 | // then hold off on doing anything with the wallpaper. |
| 1496 | // Note that we are checking here for just whether the target |
| 1497 | // is part of an app token... which is potentially overly aggressive |
| 1498 | // (the app token may not be involved in the transition), but good |
| 1499 | // enough (we'll just wait until whatever transition is pending |
| 1500 | // executes). |
| 1501 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1502 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1503 | "Wallpaper not changing: waiting for app anim in current target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1504 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1505 | } |
| 1506 | if (foundW != null && foundW.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1507 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1508 | "Wallpaper not changing: waiting for app anim in found target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1509 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1510 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1511 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1512 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1513 | if (mWallpaperTarget != foundW) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1514 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1515 | Slog.v(TAG, "New wallpaper target: " + foundW |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1516 | + " oldTarget: " + mWallpaperTarget); |
| 1517 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1518 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1519 | mLowerWallpaperTarget = null; |
| 1520 | mUpperWallpaperTarget = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1521 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1522 | WindowState oldW = mWallpaperTarget; |
| 1523 | mWallpaperTarget = foundW; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1524 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1525 | // Now what is happening... if the current and new targets are |
| 1526 | // animating, then we are in our super special mode! |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1527 | if (foundW != null && oldW != null) { |
| 1528 | boolean oldAnim = oldW.mAnimation != null |
| 1529 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1530 | boolean foundAnim = foundW.mAnimation != null |
| 1531 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1532 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1533 | Slog.v(TAG, "New animation: " + foundAnim |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1534 | + " old animation: " + oldAnim); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1535 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1536 | if (foundAnim && oldAnim) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1537 | int oldI = localmWindows.indexOf(oldW); |
| 1538 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1539 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1540 | } |
| 1541 | if (oldI >= 0) { |
| 1542 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1543 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1544 | + "=" + oldW + "; new#" + foundI |
| 1545 | + "=" + foundW); |
| 1546 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1547 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1548 | // Set the new target correctly. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1549 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1550 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1551 | Slog.v(TAG, "Old wallpaper still the target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1552 | } |
| 1553 | mWallpaperTarget = oldW; |
| 1554 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1555 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1556 | // Now set the upper and lower wallpaper targets |
| 1557 | // correctly, and make sure that we are positioning |
| 1558 | // the wallpaper below the lower. |
| 1559 | if (foundI > oldI) { |
| 1560 | // The new target is on top of the old one. |
| 1561 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1562 | Slog.v(TAG, "Found target above old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1563 | } |
| 1564 | mUpperWallpaperTarget = foundW; |
| 1565 | mLowerWallpaperTarget = oldW; |
| 1566 | foundW = oldW; |
| 1567 | foundI = oldI; |
| 1568 | } else { |
| 1569 | // The new target is below the old one. |
| 1570 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1571 | Slog.v(TAG, "Found target below old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1572 | } |
| 1573 | mUpperWallpaperTarget = oldW; |
| 1574 | mLowerWallpaperTarget = foundW; |
| 1575 | } |
| 1576 | } |
| 1577 | } |
| 1578 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1579 | |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1580 | } else if (mLowerWallpaperTarget != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1581 | // Is it time to stop animating? |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1582 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1583 | || (mLowerWallpaperTarget.mAppToken != null |
| 1584 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1585 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1586 | || (mUpperWallpaperTarget.mAppToken != null |
| 1587 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1588 | if (!lowerAnimating || !upperAnimating) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1589 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1590 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1591 | } |
| 1592 | mLowerWallpaperTarget = null; |
| 1593 | mUpperWallpaperTarget = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1594 | } |
| 1595 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1596 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1597 | boolean visible = foundW != null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1598 | if (visible) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1599 | // The window is visible to the compositor... but is it visible |
| 1600 | // to the user? That is what the wallpaper cares about. |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1601 | visible = isWallpaperVisible(foundW); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1602 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1603 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1604 | // If the wallpaper target is animating, we may need to copy |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1605 | // its layer adjustment. Only do this if we are not transfering |
| 1606 | // between two wallpaper targets. |
| 1607 | mWallpaperAnimLayerAdjustment = |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1608 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1609 | ? foundW.mAppToken.animLayerAdjustment : 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1610 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1611 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1612 | * TYPE_LAYER_MULTIPLIER |
| 1613 | + TYPE_LAYER_OFFSET; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1614 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1615 | // Now w is the window we are supposed to be behind... but we |
| 1616 | // 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] | 1617 | // AND any starting window associated with it, AND below the |
| 1618 | // maximum layer the policy allows for wallpapers. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1619 | while (foundI > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1620 | WindowState wb = localmWindows.get(foundI-1); |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1621 | if (wb.mBaseLayer < maxLayer && |
| 1622 | wb.mAttachedWindow != foundW && |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 1623 | (foundW.mAttachedWindow == null || |
| 1624 | wb.mAttachedWindow != foundW.mAttachedWindow) && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1625 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 1626 | foundW.mToken == null || wb.mToken != foundW.mToken)) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1627 | // This window is not related to the previous one in any |
| 1628 | // interesting way, so stop here. |
| 1629 | break; |
| 1630 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1631 | foundW = wb; |
| 1632 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1633 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1634 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1635 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1636 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1637 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1638 | if (foundW == null && topCurW != null) { |
| 1639 | // There is no wallpaper target, so it goes at the bottom. |
| 1640 | // We will assume it is the same place as last time, if known. |
| 1641 | foundW = topCurW; |
| 1642 | foundI = topCurI+1; |
| 1643 | } else { |
| 1644 | // Okay i is the position immediately above the wallpaper. Look at |
| 1645 | // what is below it for later. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1646 | foundW = foundI > 0 ? localmWindows.get(foundI-1) : null; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1647 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1648 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1649 | if (visible) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1650 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1651 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1652 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1653 | } |
| 1654 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1655 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1656 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1657 | } |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1658 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1659 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1660 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1661 | // are correctly placed. |
| 1662 | int curTokenIndex = mWallpaperTokens.size(); |
| 1663 | while (curTokenIndex > 0) { |
| 1664 | curTokenIndex--; |
| 1665 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1666 | if (token.hidden == visible) { |
| 1667 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1668 | token.hidden = !visible; |
| 1669 | // Need to do a layout to ensure the wallpaper now has the |
| 1670 | // correct size. |
| 1671 | mLayoutNeeded = true; |
| 1672 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1673 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1674 | int curWallpaperIndex = token.windows.size(); |
| 1675 | while (curWallpaperIndex > 0) { |
| 1676 | curWallpaperIndex--; |
| 1677 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1678 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1679 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1680 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1681 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1682 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1683 | // First, make sure the client has the current visibility |
| 1684 | // state. |
| 1685 | if (wallpaper.mWallpaperVisible != visible) { |
| 1686 | wallpaper.mWallpaperVisible = visible; |
| 1687 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1688 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1689 | "Setting visibility of wallpaper " + wallpaper |
| 1690 | + ": " + visible); |
| 1691 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1692 | } catch (RemoteException e) { |
| 1693 | } |
| 1694 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1695 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1696 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1697 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1698 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1699 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1700 | // First, if this window is at the current index, then all |
| 1701 | // is well. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1702 | if (wallpaper == foundW) { |
| 1703 | foundI--; |
| 1704 | foundW = foundI > 0 |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1705 | ? localmWindows.get(foundI-1) : null; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1706 | continue; |
| 1707 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1708 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1709 | // The window didn't match... the current wallpaper window, |
| 1710 | // wherever it is, is in the wrong place, so make sure it is |
| 1711 | // not in the list. |
| 1712 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 1713 | if (oldIndex >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1714 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1715 | + oldIndex + ": " + wallpaper); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1716 | localmWindows.remove(oldIndex); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1717 | mWindowsChanged = true; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1718 | if (oldIndex < foundI) { |
| 1719 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1720 | } |
| 1721 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1722 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1723 | // Now stick it in. |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1724 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 1725 | Slog.v(TAG, "Moving wallpaper " + wallpaper |
| 1726 | + " from " + oldIndex + " to " + foundI); |
| 1727 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1728 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1729 | localmWindows.add(foundI, wallpaper); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1730 | mWindowsChanged = true; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1731 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1732 | } |
| 1733 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1734 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1735 | return changed; |
| 1736 | } |
| 1737 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1738 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1739 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1740 | "Setting wallpaper layer adj to " + adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1741 | mWallpaperAnimLayerAdjustment = adj; |
| 1742 | int curTokenIndex = mWallpaperTokens.size(); |
| 1743 | while (curTokenIndex > 0) { |
| 1744 | curTokenIndex--; |
| 1745 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1746 | int curWallpaperIndex = token.windows.size(); |
| 1747 | while (curWallpaperIndex > 0) { |
| 1748 | curWallpaperIndex--; |
| 1749 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1750 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1751 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1752 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1753 | } |
| 1754 | } |
| 1755 | } |
| 1756 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1757 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 1758 | boolean sync) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1759 | boolean changed = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1760 | boolean rawChanged = false; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1761 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1762 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1763 | int availw = wallpaperWin.mScaledFrame.right-wallpaperWin.mScaledFrame.left-dw; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1764 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 1765 | changed = wallpaperWin.mXOffset != offset; |
| 1766 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1767 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1768 | + wallpaperWin + " x: " + offset); |
| 1769 | wallpaperWin.mXOffset = offset; |
| 1770 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1771 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1772 | wallpaperWin.mWallpaperX = wpx; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1773 | wallpaperWin.mWallpaperXStep = wpxs; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1774 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1775 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1776 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1777 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1778 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1779 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 1780 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 1781 | if (wallpaperWin.mYOffset != offset) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1782 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1783 | + wallpaperWin + " y: " + offset); |
| 1784 | changed = true; |
| 1785 | wallpaperWin.mYOffset = offset; |
| 1786 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1787 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1788 | wallpaperWin.mWallpaperY = wpy; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1789 | wallpaperWin.mWallpaperYStep = wpys; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1790 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1791 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1792 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1793 | if (rawChanged) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1794 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1795 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1796 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 1797 | + " y=" + wallpaperWin.mWallpaperY); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1798 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1799 | mWaitingOnWallpaper = wallpaperWin; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1800 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1801 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1802 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 1803 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1804 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1805 | if (mWaitingOnWallpaper != null) { |
| 1806 | long start = SystemClock.uptimeMillis(); |
| 1807 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 1808 | < start) { |
| 1809 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1810 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1811 | "Waiting for offset complete..."); |
| 1812 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 1813 | } catch (InterruptedException e) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1814 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1815 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1816 | if ((start+WALLPAPER_TIMEOUT) |
| 1817 | < SystemClock.uptimeMillis()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1818 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1819 | + wallpaperWin); |
| 1820 | mLastWallpaperTimeoutTime = start; |
| 1821 | } |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1822 | } |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1823 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1824 | } |
| 1825 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1826 | } catch (RemoteException e) { |
| 1827 | } |
| 1828 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1829 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1830 | return changed; |
| 1831 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1832 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1833 | void wallpaperOffsetsComplete(IBinder window) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1834 | synchronized (mWindowMap) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1835 | if (mWaitingOnWallpaper != null && |
| 1836 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 1837 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1838 | mWindowMap.notifyAll(); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1839 | } |
| 1840 | } |
| 1841 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1842 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1843 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 1844 | final int dw = mCurDisplayWidth; |
| 1845 | final int dh = mCurDisplayHeight; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1846 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1847 | boolean changed = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1848 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1849 | WindowState target = mWallpaperTarget; |
| 1850 | if (target != null) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1851 | if (target.mWallpaperX >= 0) { |
| 1852 | mLastWallpaperX = target.mWallpaperX; |
| 1853 | } else if (changingTarget.mWallpaperX >= 0) { |
| 1854 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 1855 | } |
| 1856 | if (target.mWallpaperY >= 0) { |
| 1857 | mLastWallpaperY = target.mWallpaperY; |
| 1858 | } else if (changingTarget.mWallpaperY >= 0) { |
| 1859 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 1860 | } |
| 1861 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1862 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1863 | int curTokenIndex = mWallpaperTokens.size(); |
| 1864 | while (curTokenIndex > 0) { |
| 1865 | curTokenIndex--; |
| 1866 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1867 | int curWallpaperIndex = token.windows.size(); |
| 1868 | while (curWallpaperIndex > 0) { |
| 1869 | curWallpaperIndex--; |
| 1870 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1871 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 1872 | wallpaper.computeShownFrameLocked(); |
| 1873 | changed = true; |
| 1874 | // We only want to be synchronous with one wallpaper. |
| 1875 | sync = false; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1876 | } |
| 1877 | } |
| 1878 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1879 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1880 | return changed; |
| 1881 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1882 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1883 | void updateWallpaperVisibilityLocked() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1884 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 1885 | final int dw = mCurDisplayWidth; |
| 1886 | final int dh = mCurDisplayHeight; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1887 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1888 | int curTokenIndex = mWallpaperTokens.size(); |
| 1889 | while (curTokenIndex > 0) { |
| 1890 | curTokenIndex--; |
| 1891 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1892 | if (token.hidden == visible) { |
| 1893 | token.hidden = !visible; |
| 1894 | // Need to do a layout to ensure the wallpaper now has the |
| 1895 | // correct size. |
| 1896 | mLayoutNeeded = true; |
| 1897 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1898 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1899 | int curWallpaperIndex = token.windows.size(); |
| 1900 | while (curWallpaperIndex > 0) { |
| 1901 | curWallpaperIndex--; |
| 1902 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1903 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1904 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1905 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1906 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1907 | if (wallpaper.mWallpaperVisible != visible) { |
| 1908 | wallpaper.mWallpaperVisible = visible; |
| 1909 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1910 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1911 | "Updating visibility of wallpaper " + wallpaper |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1912 | + ": " + visible); |
| 1913 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1914 | } catch (RemoteException e) { |
| 1915 | } |
| 1916 | } |
| 1917 | } |
| 1918 | } |
| 1919 | } |
Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 1920 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1921 | public int addWindow(Session session, IWindow client, |
| 1922 | WindowManager.LayoutParams attrs, int viewVisibility, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1923 | Rect outContentInsets, InputChannel outInputChannel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1924 | int res = mPolicy.checkAddPermission(attrs); |
| 1925 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1926 | return res; |
| 1927 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1928 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1929 | boolean reportNewConfig = false; |
| 1930 | WindowState attachedWindow = null; |
| 1931 | WindowState win = null; |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 1932 | long origId; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1933 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1934 | synchronized(mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1935 | if (mDisplay == null) { |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 1936 | throw new IllegalStateException("Display has not been initialialized"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1937 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1938 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1939 | if (mWindowMap.containsKey(client.asBinder())) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1940 | Slog.w(TAG, "Window " + client + " is already added"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1941 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 1942 | } |
| 1943 | |
| 1944 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1945 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1946 | if (attachedWindow == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1947 | 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] | 1948 | + attrs.token + ". Aborting."); |
| 1949 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1950 | } |
| 1951 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 1952 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1953 | 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] | 1954 | + attrs.token + ". Aborting."); |
| 1955 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1956 | } |
| 1957 | } |
| 1958 | |
| 1959 | boolean addToken = false; |
| 1960 | WindowToken token = mTokenMap.get(attrs.token); |
| 1961 | if (token == null) { |
| 1962 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1963 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1964 | 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] | 1965 | + attrs.token + ". Aborting."); |
| 1966 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1967 | } |
| 1968 | if (attrs.type == TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1969 | 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] | 1970 | + attrs.token + ". Aborting."); |
| 1971 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1972 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1973 | if (attrs.type == TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1974 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1975 | + attrs.token + ". Aborting."); |
| 1976 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1977 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1978 | token = new WindowToken(this, attrs.token, -1, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1979 | addToken = true; |
| 1980 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1981 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 1982 | AppWindowToken atoken = token.appWindowToken; |
| 1983 | if (atoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1984 | 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] | 1985 | + token + ". Aborting."); |
| 1986 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 1987 | } else if (atoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1988 | 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] | 1989 | + token + ". Aborting."); |
| 1990 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1991 | } |
| 1992 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 1993 | // No need for this guy! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1994 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1995 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 1996 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 1997 | } |
| 1998 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 1999 | if (token.windowType != TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2000 | 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] | 2001 | + attrs.token + ". Aborting."); |
| 2002 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2003 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2004 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 2005 | if (token.windowType != TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2006 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2007 | + attrs.token + ". Aborting."); |
| 2008 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2009 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2010 | } |
| 2011 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2012 | win = new WindowState(this, session, client, token, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2013 | attachedWindow, attrs, viewVisibility); |
| 2014 | if (win.mDeathRecipient == null) { |
| 2015 | // Client has apparently died, so there is no reason to |
| 2016 | // continue. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2017 | Slog.w(TAG, "Adding window client " + client.asBinder() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2018 | + " that is dead, aborting."); |
| 2019 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2020 | } |
| 2021 | |
| 2022 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2023 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2024 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 2025 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2026 | return res; |
| 2027 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2028 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2029 | if (outInputChannel != null) { |
| 2030 | String name = win.makeInputChannelName(); |
| 2031 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 2032 | win.mInputChannel = inputChannels[0]; |
| 2033 | inputChannels[1].transferToBinderOutParameter(outInputChannel); |
| 2034 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 2035 | mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2036 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2037 | |
| 2038 | // From now on, no exceptions or errors allowed! |
| 2039 | |
| 2040 | res = WindowManagerImpl.ADD_OKAY; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2041 | |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2042 | origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2043 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2044 | if (addToken) { |
| 2045 | mTokenMap.put(attrs.token, token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2046 | } |
| 2047 | win.attach(); |
| 2048 | mWindowMap.put(client.asBinder(), win); |
| 2049 | |
| 2050 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 2051 | token.appWindowToken != null) { |
| 2052 | token.appWindowToken.startingWindow = win; |
| 2053 | } |
| 2054 | |
| 2055 | boolean imMayMove = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2056 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2057 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 2058 | mInputMethodWindow = win; |
| 2059 | addInputMethodWindowToListLocked(win); |
| 2060 | imMayMove = false; |
| 2061 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2062 | mInputMethodDialogs.add(win); |
| 2063 | addWindowToListInOrderLocked(win, true); |
| 2064 | adjustInputMethodDialogsLocked(); |
| 2065 | imMayMove = false; |
| 2066 | } else { |
| 2067 | addWindowToListInOrderLocked(win, true); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2068 | if (attrs.type == TYPE_WALLPAPER) { |
| 2069 | mLastWallpaperTimeoutTime = 0; |
| 2070 | adjustWallpaperWindowsLocked(); |
| 2071 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2072 | adjustWallpaperWindowsLocked(); |
| 2073 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2074 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2075 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2076 | win.mEnterAnimationPending = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2077 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2078 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2079 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2080 | if (mInTouchMode) { |
| 2081 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 2082 | } |
| 2083 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 2084 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 2085 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2086 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2087 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 2088 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2089 | boolean focusChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2090 | if (win.canReceiveKeys()) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2091 | focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS, |
| 2092 | false /*updateInputWindows*/); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2093 | if (focusChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2094 | imMayMove = false; |
| 2095 | } |
| 2096 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2097 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2098 | if (imMayMove) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2099 | moveInputMethodWindowsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2100 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2101 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2102 | assignLayersLocked(); |
| 2103 | // Don't do layout here, the window must call |
| 2104 | // relayout to be displayed, so we'll do it there. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2105 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2106 | //dump(); |
| 2107 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2108 | if (focusChanged) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2109 | finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2110 | } |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2111 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2112 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2113 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2114 | TAG, "New client " + client.asBinder() |
| 2115 | + ": window=" + win); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2116 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2117 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2118 | reportNewConfig = true; |
| 2119 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2120 | } |
| 2121 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2122 | if (reportNewConfig) { |
| 2123 | sendNewConfiguration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2124 | } |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2125 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2126 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2127 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2128 | return res; |
| 2129 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2130 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2131 | public void removeWindow(Session session, IWindow client) { |
| 2132 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2133 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2134 | if (win == null) { |
| 2135 | return; |
| 2136 | } |
| 2137 | removeWindowLocked(session, win); |
| 2138 | } |
| 2139 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2141 | public void removeWindowLocked(Session session, WindowState win) { |
| 2142 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2143 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2144 | TAG, "Remove " + win + " client=" |
| 2145 | + Integer.toHexString(System.identityHashCode( |
| 2146 | win.mClient.asBinder())) |
| 2147 | + ", surface=" + win.mSurface); |
| 2148 | |
| 2149 | final long origId = Binder.clearCallingIdentity(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2150 | |
| 2151 | win.disposeInputChannel(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2152 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2153 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2154 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2155 | + " mExiting=" + win.mExiting |
| 2156 | + " isAnimating=" + win.isAnimating() |
| 2157 | + " app-animation=" |
| 2158 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2159 | + " inPendingTransaction=" |
| 2160 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2161 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2162 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2163 | boolean wasVisible = false; |
| 2164 | // First, see if we need to run an animation. If we do, we have |
| 2165 | // to hold off on removing the window until the animation is done. |
| 2166 | // If the display is frozen, just remove immediately, since the |
| 2167 | // animation wouldn't be seen. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2168 | if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2169 | // If we are not currently running the exit animation, we |
| 2170 | // need to see about starting one. |
| 2171 | if (wasVisible=win.isWinVisibleLw()) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2172 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2173 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2174 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2175 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2176 | } |
| 2177 | // Try starting an animation. |
| 2178 | if (applyAnimationLocked(win, transit, false)) { |
| 2179 | win.mExiting = true; |
| 2180 | } |
| 2181 | } |
| 2182 | if (win.mExiting || win.isAnimating()) { |
| 2183 | // The exit animation is running... wait for it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2184 | //Slog.i(TAG, "*** Running exit animation..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2185 | win.mExiting = true; |
| 2186 | win.mRemoveOnExit = true; |
| 2187 | mLayoutNeeded = true; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2188 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 2189 | false /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2190 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2191 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2192 | if (win.mAppToken != null) { |
| 2193 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2194 | } |
| 2195 | //dump(); |
| 2196 | Binder.restoreCallingIdentity(origId); |
| 2197 | return; |
| 2198 | } |
| 2199 | } |
| 2200 | |
| 2201 | removeWindowInnerLocked(session, win); |
| 2202 | // Removing a visible window will effect the computed orientation |
| 2203 | // So just update orientation if needed. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2204 | if (wasVisible && computeForcedAppOrientationLocked() |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2205 | != mForcedAppOrientation |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2206 | && updateOrientationFromAppTokensLocked(false)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2207 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2208 | } |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2209 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2210 | Binder.restoreCallingIdentity(origId); |
| 2211 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2212 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2213 | private void removeWindowInnerLocked(Session session, WindowState win) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2214 | if (win.mRemoved) { |
| 2215 | // Nothing to do. |
| 2216 | return; |
| 2217 | } |
| 2218 | |
| 2219 | for (int i=win.mChildWindows.size()-1; i>=0; i--) { |
| 2220 | WindowState cwin = win.mChildWindows.get(i); |
| 2221 | Slog.w(TAG, "Force-removing child win " + cwin + " from container " |
| 2222 | + win); |
| 2223 | removeWindowInnerLocked(cwin.mSession, cwin); |
| 2224 | } |
| 2225 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2226 | win.mRemoved = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2227 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2228 | if (mInputMethodTarget == win) { |
| 2229 | moveInputMethodWindowsIfNeededLocked(false); |
| 2230 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2231 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2232 | if (false) { |
| 2233 | RuntimeException e = new RuntimeException("here"); |
| 2234 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2235 | Slog.w(TAG, "Removing window " + win, e); |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2236 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2237 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2238 | mPolicy.removeWindowLw(win); |
| 2239 | win.removeLocked(); |
| 2240 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2241 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2242 | mWindowMap.remove(win.mClient.asBinder()); |
| 2243 | mWindows.remove(win); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2244 | mPendingRemove.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2245 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2246 | 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] | 2247 | |
| 2248 | if (mInputMethodWindow == win) { |
| 2249 | mInputMethodWindow = null; |
| 2250 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2251 | mInputMethodDialogs.remove(win); |
| 2252 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2253 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2254 | final WindowToken token = win.mToken; |
| 2255 | final AppWindowToken atoken = win.mAppToken; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2256 | 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] | 2257 | token.windows.remove(win); |
| 2258 | if (atoken != null) { |
| 2259 | atoken.allAppWindows.remove(win); |
| 2260 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2261 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2262 | TAG, "**** Removing window " + win + ": count=" |
| 2263 | + token.windows.size()); |
| 2264 | if (token.windows.size() == 0) { |
| 2265 | if (!token.explicit) { |
| 2266 | mTokenMap.remove(token.token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2267 | } else if (atoken != null) { |
| 2268 | atoken.firstWindowDrawn = false; |
| 2269 | } |
| 2270 | } |
| 2271 | |
| 2272 | if (atoken != null) { |
| 2273 | if (atoken.startingWindow == win) { |
| 2274 | atoken.startingWindow = null; |
| 2275 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2276 | // If this is the last window and we had requested a starting |
| 2277 | // transition window, well there is no point now. |
| 2278 | atoken.startingData = null; |
| 2279 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2280 | // If this is the last window except for a starting transition |
| 2281 | // window, we need to get rid of the starting transition. |
| 2282 | if (DEBUG_STARTING_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2283 | Slog.v(TAG, "Schedule remove starting " + token |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2284 | + ": no more real windows"); |
| 2285 | } |
| 2286 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2287 | mH.sendMessage(m); |
| 2288 | } |
| 2289 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2290 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2291 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2292 | mLastWallpaperTimeoutTime = 0; |
| 2293 | adjustWallpaperWindowsLocked(); |
| 2294 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2295 | adjustWallpaperWindowsLocked(); |
| 2296 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2297 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2298 | if (!mInLayout) { |
| 2299 | assignLayersLocked(); |
| 2300 | mLayoutNeeded = true; |
| 2301 | performLayoutAndPlaceSurfacesLocked(); |
| 2302 | if (win.mAppToken != null) { |
| 2303 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2304 | } |
| 2305 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2306 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2307 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2308 | } |
| 2309 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2310 | static void logSurface(WindowState w, String msg, RuntimeException where) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2311 | String str = " SURFACE " + Integer.toHexString(w.hashCode()) |
| 2312 | + ": " + msg + " / " + w.mAttrs.getTitle(); |
| 2313 | if (where != null) { |
| 2314 | Slog.i(TAG, str, where); |
| 2315 | } else { |
| 2316 | Slog.i(TAG, str); |
| 2317 | } |
| 2318 | } |
| 2319 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2320 | void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2321 | long origId = Binder.clearCallingIdentity(); |
| 2322 | try { |
| 2323 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2324 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2325 | if ((w != null) && (w.mSurface != null)) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2326 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 2327 | ">>> OPEN TRANSACTION setTransparentRegion"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2328 | Surface.openTransaction(); |
| 2329 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2330 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 2331 | "transparentRegionHint=" + region, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2332 | w.mSurface.setTransparentRegionHint(region); |
| 2333 | } finally { |
| 2334 | Surface.closeTransaction(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2335 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 2336 | "<<< CLOSE TRANSACTION setTransparentRegion"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2337 | } |
| 2338 | } |
| 2339 | } |
| 2340 | } finally { |
| 2341 | Binder.restoreCallingIdentity(origId); |
| 2342 | } |
| 2343 | } |
| 2344 | |
| 2345 | void setInsetsWindow(Session session, IWindow client, |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2346 | int touchableInsets, Rect contentInsets, |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2347 | Rect visibleInsets, Region touchableRegion) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2348 | long origId = Binder.clearCallingIdentity(); |
| 2349 | try { |
| 2350 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2351 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2352 | if (w != null) { |
| 2353 | w.mGivenInsetsPending = false; |
| 2354 | w.mGivenContentInsets.set(contentInsets); |
| 2355 | w.mGivenVisibleInsets.set(visibleInsets); |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2356 | w.mGivenTouchableRegion.set(touchableRegion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2357 | w.mTouchableInsets = touchableInsets; |
| 2358 | mLayoutNeeded = true; |
| 2359 | performLayoutAndPlaceSurfacesLocked(); |
| 2360 | } |
| 2361 | } |
| 2362 | } finally { |
| 2363 | Binder.restoreCallingIdentity(origId); |
| 2364 | } |
| 2365 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2366 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2367 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2368 | Rect outDisplayFrame) { |
| 2369 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2370 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2371 | if (win == null) { |
| 2372 | outDisplayFrame.setEmpty(); |
| 2373 | return; |
| 2374 | } |
| 2375 | outDisplayFrame.set(win.mDisplayFrame); |
| 2376 | } |
| 2377 | } |
| 2378 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2379 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2380 | float xStep, float yStep) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2381 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2382 | window.mWallpaperX = x; |
| 2383 | window.mWallpaperY = y; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2384 | window.mWallpaperXStep = xStep; |
| 2385 | window.mWallpaperYStep = yStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2386 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2387 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2388 | } |
| 2389 | } |
| 2390 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2391 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2392 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2393 | synchronized (mWindowMap) { |
| 2394 | if (mWaitingOnWallpaper != null && |
| 2395 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2396 | mWaitingOnWallpaper = null; |
| 2397 | mWindowMap.notifyAll(); |
| 2398 | } |
| 2399 | } |
| 2400 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2401 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2402 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2403 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2404 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2405 | || window == mUpperWallpaperTarget) { |
| 2406 | boolean doWait = sync; |
| 2407 | int curTokenIndex = mWallpaperTokens.size(); |
| 2408 | while (curTokenIndex > 0) { |
| 2409 | curTokenIndex--; |
| 2410 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2411 | int curWallpaperIndex = token.windows.size(); |
| 2412 | while (curWallpaperIndex > 0) { |
| 2413 | curWallpaperIndex--; |
| 2414 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2415 | try { |
| 2416 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2417 | x, y, z, extras, sync); |
| 2418 | // We only want to be synchronous with one wallpaper. |
| 2419 | sync = false; |
| 2420 | } catch (RemoteException e) { |
| 2421 | } |
| 2422 | } |
| 2423 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2424 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2425 | if (doWait) { |
| 2426 | // XXX Need to wait for result. |
| 2427 | } |
| 2428 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2429 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2430 | return null; |
| 2431 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2432 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2433 | public int relayoutWindow(Session session, IWindow client, |
| 2434 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2435 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2436 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2437 | Configuration outConfig, Surface outSurface) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2438 | boolean displayed = false; |
| 2439 | boolean inTouchMode; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2440 | boolean configChanged; |
Joe Onorato | ac0ee89 | 2011-01-30 15:38:30 -0800 | [diff] [blame] | 2441 | |
| 2442 | // if they don't have this permission, mask out the status bar bits |
| 2443 | if (attrs != null) { |
| 2444 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR) |
| 2445 | != PackageManager.PERMISSION_GRANTED) { |
| 2446 | attrs.systemUiVisibility &= ~StatusBarManager.DISABLE_MASK; |
| 2447 | attrs.subtreeSystemUiVisibility &= ~StatusBarManager.DISABLE_MASK; |
| 2448 | } |
| 2449 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2450 | long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2451 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2452 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2453 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2454 | if (win == null) { |
| 2455 | return 0; |
| 2456 | } |
| 2457 | win.mRequestedWidth = requestedWidth; |
| 2458 | win.mRequestedHeight = requestedHeight; |
| 2459 | |
| 2460 | if (attrs != null) { |
| 2461 | mPolicy.adjustWindowParamsLw(attrs); |
| 2462 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2463 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2464 | int attrChanges = 0; |
| 2465 | int flagChanges = 0; |
| 2466 | if (attrs != null) { |
| 2467 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2468 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2469 | } |
| 2470 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2471 | 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] | 2472 | |
| 2473 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2474 | win.mAlpha = attrs.alpha; |
| 2475 | } |
| 2476 | |
| 2477 | final boolean scaledWindow = |
| 2478 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2479 | |
| 2480 | if (scaledWindow) { |
| 2481 | // requested{Width|Height} Surface's physical size |
| 2482 | // attrs.{width|height} Size on screen |
| 2483 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2484 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2485 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2486 | (attrs.height / (float)requestedHeight) : 1.0f; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2487 | } else { |
| 2488 | win.mHScale = win.mVScale = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2489 | } |
| 2490 | |
| 2491 | boolean imMayMove = (flagChanges&( |
| 2492 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2493 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2494 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2495 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2496 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2497 | || (!win.mRelayoutCalled); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2498 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2499 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2500 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2501 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2502 | win.mRelayoutCalled = true; |
| 2503 | final int oldVisibility = win.mViewVisibility; |
| 2504 | win.mViewVisibility = viewVisibility; |
| 2505 | if (viewVisibility == View.VISIBLE && |
| 2506 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2507 | displayed = !win.isVisibleLw(); |
| 2508 | if (win.mExiting) { |
| 2509 | win.mExiting = false; |
Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 2510 | if (win.mAnimation != null) { |
| 2511 | win.mAnimation.cancel(); |
| 2512 | win.mAnimation = null; |
| 2513 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2514 | } |
| 2515 | if (win.mDestroying) { |
| 2516 | win.mDestroying = false; |
| 2517 | mDestroySurface.remove(win); |
| 2518 | } |
| 2519 | if (oldVisibility == View.GONE) { |
| 2520 | win.mEnterAnimationPending = true; |
| 2521 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2522 | if (displayed) { |
| 2523 | if (win.mSurface != null && !win.mDrawPending |
| 2524 | && !win.mCommitDrawPending && !mDisplayFrozen |
| 2525 | && mPolicy.isScreenOn()) { |
| 2526 | applyEnterAnimationLocked(win); |
| 2527 | } |
| 2528 | if ((win.mAttrs.flags |
| 2529 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2530 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2531 | "Relayout window turning screen on: " + win); |
| 2532 | win.mTurnOnScreen = true; |
| 2533 | } |
| 2534 | int diff = 0; |
| 2535 | if (win.mConfiguration != mCurConfiguration |
| 2536 | && (win.mConfiguration == null |
| 2537 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2538 | win.mConfiguration = mCurConfiguration; |
| 2539 | if (DEBUG_CONFIGURATION) { |
| 2540 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2541 | + win.mConfiguration + " / 0x" |
| 2542 | + Integer.toHexString(diff)); |
| 2543 | } |
| 2544 | outConfig.setTo(mCurConfiguration); |
| 2545 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2546 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2547 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2548 | // To change the format, we need to re-build the surface. |
| 2549 | win.destroySurfaceLocked(); |
| 2550 | displayed = true; |
| 2551 | } |
| 2552 | try { |
| 2553 | Surface surface = win.createSurfaceLocked(); |
| 2554 | if (surface != null) { |
| 2555 | outSurface.copyFrom(surface); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2556 | win.mReportDestroySurface = false; |
| 2557 | win.mSurfacePendingDestroy = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2558 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2559 | " OUT SURFACE " + outSurface + ": copied"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2560 | } else { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2561 | // For some reason there isn't a surface. Clear the |
| 2562 | // caller's object so they see the same state. |
| 2563 | outSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2564 | } |
| 2565 | } catch (Exception e) { |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2566 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2567 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2568 | Slog.w(TAG, "Exception thrown when creating surface for client " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2569 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2570 | e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2571 | Binder.restoreCallingIdentity(origId); |
| 2572 | return 0; |
| 2573 | } |
| 2574 | if (displayed) { |
| 2575 | focusMayChange = true; |
| 2576 | } |
| 2577 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2578 | && mInputMethodWindow == null) { |
| 2579 | mInputMethodWindow = win; |
| 2580 | imMayMove = true; |
| 2581 | } |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2582 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2583 | && win.mAppToken != null |
| 2584 | && win.mAppToken.startingWindow != null) { |
| 2585 | // Special handling of starting window over the base |
| 2586 | // window of the app: propagate lock screen flags to it, |
| 2587 | // to provide the correct semantics while starting. |
| 2588 | final int mask = |
| 2589 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2590 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2591 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2592 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2593 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2594 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2595 | } else { |
| 2596 | win.mEnterAnimationPending = false; |
| 2597 | if (win.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2598 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2599 | + ": mExiting=" + win.mExiting |
| 2600 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2601 | // If we are not currently running the exit animation, we |
| 2602 | // need to see about starting one. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2603 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2604 | // Try starting an animation; if there isn't one, we |
| 2605 | // can destroy the surface right away. |
| 2606 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2607 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2608 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2609 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2610 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2611 | applyAnimationLocked(win, transit, false)) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2612 | focusMayChange = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2613 | win.mExiting = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2614 | } else if (win.isAnimating()) { |
| 2615 | // Currently in a hide animation... turn this into |
| 2616 | // an exit. |
| 2617 | win.mExiting = true; |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2618 | } else if (win == mWallpaperTarget) { |
| 2619 | // If the wallpaper is currently behind this |
| 2620 | // window, we need to change both of them inside |
| 2621 | // of a transaction to avoid artifacts. |
| 2622 | win.mExiting = true; |
| 2623 | win.mAnimating = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2624 | } else { |
| 2625 | if (mInputMethodWindow == win) { |
| 2626 | mInputMethodWindow = null; |
| 2627 | } |
| 2628 | win.destroySurfaceLocked(); |
| 2629 | } |
| 2630 | } |
| 2631 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2632 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2633 | if (win.mSurface == null || (win.getAttrs().flags |
| 2634 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2635 | || win.mSurfacePendingDestroy) { |
| 2636 | // We are being called from a local process, which |
| 2637 | // means outSurface holds its current surface. Ensure the |
| 2638 | // surface object is cleared, but we don't want it actually |
| 2639 | // destroyed at this point. |
| 2640 | win.mSurfacePendingDestroy = false; |
| 2641 | outSurface.release(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2642 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2643 | } else if (win.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2644 | if (DEBUG_VISIBILITY) Slog.i(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2645 | "Keeping surface, will report destroy: " + win); |
| 2646 | win.mReportDestroySurface = true; |
| 2647 | outSurface.copyFrom(win.mSurface); |
| 2648 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2649 | } |
| 2650 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2651 | if (focusMayChange) { |
| 2652 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2653 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 2654 | false /*updateInputWindows*/)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2655 | imMayMove = false; |
| 2656 | } |
| 2657 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2658 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2659 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2660 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2661 | // reassign them at this point if the IM window state gets shuffled |
| 2662 | boolean assignLayers = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2663 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2664 | if (imMayMove) { |
Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2665 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2666 | // Little hack here -- we -should- be able to rely on the |
| 2667 | // function to return true if the IME has moved and needs |
| 2668 | // its layer recomputed. However, if the IME was hidden |
| 2669 | // and isn't actually moved in the list, its layer may be |
| 2670 | // 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] | 2671 | assignLayers = true; |
| 2672 | } |
| 2673 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2674 | if (wallpaperMayMove) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2675 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2676 | assignLayers = true; |
| 2677 | } |
| 2678 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2679 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2680 | mLayoutNeeded = true; |
| 2681 | win.mGivenInsetsPending = insetsPending; |
| 2682 | if (assignLayers) { |
| 2683 | assignLayersLocked(); |
| 2684 | } |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2685 | configChanged = updateOrientationFromAppTokensLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2686 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2687 | if (displayed && win.mIsWallpaper) { |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 2688 | updateWallpaperOffsetLocked(win, mCurDisplayWidth, mCurDisplayHeight, false); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2689 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2690 | if (win.mAppToken != null) { |
| 2691 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2692 | } |
| 2693 | outFrame.set(win.mFrame); |
| 2694 | outContentInsets.set(win.mContentInsets); |
| 2695 | outVisibleInsets.set(win.mVisibleInsets); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2696 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2697 | TAG, "Relayout given client " + client.asBinder() |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2698 | + ", requestedWidth=" + requestedWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2699 | + ", requestedHeight=" + requestedHeight |
| 2700 | + ", viewVisibility=" + viewVisibility |
| 2701 | + "\nRelayout returning frame=" + outFrame |
| 2702 | + ", surface=" + outSurface); |
| 2703 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2704 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2705 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2706 | |
| 2707 | inTouchMode = mInTouchMode; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2708 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2709 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2710 | } |
| 2711 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2712 | if (configChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2713 | sendNewConfiguration(); |
| 2714 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2715 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2716 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2717 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2718 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 2719 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 2720 | } |
| 2721 | |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 2722 | public boolean outOfMemoryWindow(Session session, IWindow client) { |
| 2723 | long origId = Binder.clearCallingIdentity(); |
| 2724 | |
| 2725 | try { |
| 2726 | synchronized(mWindowMap) { |
| 2727 | WindowState win = windowForClientLocked(session, client, false); |
| 2728 | if (win == null) { |
| 2729 | return false; |
| 2730 | } |
| 2731 | return reclaimSomeSurfaceMemoryLocked(win, "from-client", false); |
| 2732 | } |
| 2733 | } finally { |
| 2734 | Binder.restoreCallingIdentity(origId); |
| 2735 | } |
| 2736 | } |
| 2737 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2738 | public void finishDrawingWindow(Session session, IWindow client) { |
| 2739 | final long origId = Binder.clearCallingIdentity(); |
| 2740 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2741 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2742 | if (win != null && win.finishDrawingLocked()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2743 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 2744 | adjustWallpaperWindowsLocked(); |
| 2745 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2746 | mLayoutNeeded = true; |
| 2747 | performLayoutAndPlaceSurfacesLocked(); |
| 2748 | } |
| 2749 | } |
| 2750 | Binder.restoreCallingIdentity(origId); |
| 2751 | } |
| 2752 | |
| 2753 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 2754 | 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] | 2755 | + (lp != null ? lp.packageName : null) |
| 2756 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 2757 | if (lp != null && lp.windowAnimations != 0) { |
| 2758 | // If this is a system resource, don't try to load it from the |
| 2759 | // application resources. It is nice to avoid loading application |
| 2760 | // resources if we can. |
| 2761 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 2762 | int resId = lp.windowAnimations; |
| 2763 | if ((resId&0xFF000000) == 0x01000000) { |
| 2764 | packageName = "android"; |
| 2765 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2766 | 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] | 2767 | + packageName); |
| 2768 | return AttributeCache.instance().get(packageName, resId, |
| 2769 | com.android.internal.R.styleable.WindowAnimation); |
| 2770 | } |
| 2771 | return null; |
| 2772 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2773 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2774 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 2775 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2776 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 2777 | if (packageName != null) { |
| 2778 | if ((resId&0xFF000000) == 0x01000000) { |
| 2779 | packageName = "android"; |
| 2780 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2781 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2782 | + packageName); |
| 2783 | return AttributeCache.instance().get(packageName, resId, |
| 2784 | com.android.internal.R.styleable.WindowAnimation); |
| 2785 | } |
| 2786 | return null; |
| 2787 | } |
| 2788 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2789 | void applyEnterAnimationLocked(WindowState win) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2790 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 2791 | if (win.mEnterAnimationPending) { |
| 2792 | win.mEnterAnimationPending = false; |
| 2793 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 2794 | } |
| 2795 | |
| 2796 | applyAnimationLocked(win, transit, true); |
| 2797 | } |
| 2798 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2799 | boolean applyAnimationLocked(WindowState win, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2800 | int transit, boolean isEntrance) { |
| 2801 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 2802 | // If we are trying to apply an animation, but already running |
| 2803 | // an animation of the same type, then just leave that one alone. |
| 2804 | return true; |
| 2805 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2806 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2807 | // Only apply an animation if the display isn't frozen. If it is |
| 2808 | // frozen, there is no reason to animate and it can cause strange |
| 2809 | // artifacts when we unfreeze the display if some different animation |
| 2810 | // is running. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2811 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2812 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 2813 | int attr = -1; |
| 2814 | Animation a = null; |
| 2815 | if (anim != 0) { |
| 2816 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 2817 | } else { |
| 2818 | switch (transit) { |
| 2819 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 2820 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 2821 | break; |
| 2822 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 2823 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 2824 | break; |
| 2825 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 2826 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 2827 | break; |
| 2828 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 2829 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 2830 | break; |
| 2831 | } |
| 2832 | if (attr >= 0) { |
| 2833 | a = loadAnimation(win.mAttrs, attr); |
| 2834 | } |
| 2835 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2836 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2837 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 2838 | + " mAnimation=" + win.mAnimation |
| 2839 | + " isEntrance=" + isEntrance); |
| 2840 | if (a != null) { |
| 2841 | if (DEBUG_ANIM) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2842 | RuntimeException e = null; |
| 2843 | if (!HIDE_STACK_CRAWLS) { |
| 2844 | e = new RuntimeException(); |
| 2845 | e.fillInStackTrace(); |
| 2846 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2847 | Slog.v(TAG, "Loaded animation " + a + " for " + win, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2848 | } |
| 2849 | win.setAnimation(a); |
| 2850 | win.mAnimationIsEntrance = isEntrance; |
| 2851 | } |
| 2852 | } else { |
| 2853 | win.clearAnimation(); |
| 2854 | } |
| 2855 | |
| 2856 | return win.mAnimation != null; |
| 2857 | } |
| 2858 | |
| 2859 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 2860 | int anim = 0; |
| 2861 | Context context = mContext; |
| 2862 | if (animAttr >= 0) { |
| 2863 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 2864 | if (ent != null) { |
| 2865 | context = ent.context; |
| 2866 | anim = ent.array.getResourceId(animAttr, 0); |
| 2867 | } |
| 2868 | } |
| 2869 | if (anim != 0) { |
| 2870 | return AnimationUtils.loadAnimation(context, anim); |
| 2871 | } |
| 2872 | return null; |
| 2873 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2874 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2875 | private Animation loadAnimation(String packageName, int resId) { |
| 2876 | int anim = 0; |
| 2877 | Context context = mContext; |
| 2878 | if (resId >= 0) { |
| 2879 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 2880 | if (ent != null) { |
| 2881 | context = ent.context; |
| 2882 | anim = resId; |
| 2883 | } |
| 2884 | } |
| 2885 | if (anim != 0) { |
| 2886 | return AnimationUtils.loadAnimation(context, anim); |
| 2887 | } |
| 2888 | return null; |
| 2889 | } |
| 2890 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2891 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2892 | WindowManager.LayoutParams lp, int transit, boolean enter, boolean bgFiller) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2893 | // Only apply an animation if the display isn't frozen. If it is |
| 2894 | // frozen, there is no reason to animate and it can cause strange |
| 2895 | // artifacts when we unfreeze the display if some different animation |
| 2896 | // is running. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2897 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2898 | Animation a; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2899 | if (bgFiller) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2900 | a = new FadeInOutAnimation(enter); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2901 | if (DEBUG_ANIM) Slog.v(TAG, |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2902 | "applying FadeInOutAnimation for a window in compatibility mode"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2903 | } else if (mNextAppTransitionPackage != null) { |
| 2904 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 2905 | mNextAppTransitionEnter : mNextAppTransitionExit); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2906 | } else { |
| 2907 | int animAttr = 0; |
| 2908 | switch (transit) { |
| 2909 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 2910 | animAttr = enter |
| 2911 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 2912 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 2913 | break; |
| 2914 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 2915 | animAttr = enter |
| 2916 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 2917 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 2918 | break; |
| 2919 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 2920 | animAttr = enter |
| 2921 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 2922 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 2923 | break; |
| 2924 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 2925 | animAttr = enter |
| 2926 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 2927 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 2928 | break; |
| 2929 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 2930 | animAttr = enter |
| 2931 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 2932 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 2933 | break; |
| 2934 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 2935 | animAttr = enter |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 2936 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2937 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 2938 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2939 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2940 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2941 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 2942 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2943 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2944 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2945 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2946 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 2947 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 2948 | break; |
| 2949 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 2950 | animAttr = enter |
| 2951 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 2952 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 2953 | break; |
| 2954 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 2955 | animAttr = enter |
| 2956 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 2957 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2958 | break; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2959 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 2960 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2961 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2962 | + " anim=" + a |
| 2963 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 2964 | + " transit=" + transit); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2965 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2966 | if (a != null) { |
| 2967 | if (DEBUG_ANIM) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2968 | RuntimeException e = null; |
| 2969 | if (!HIDE_STACK_CRAWLS) { |
| 2970 | e = new RuntimeException(); |
| 2971 | e.fillInStackTrace(); |
| 2972 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2973 | Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2974 | } |
| 2975 | wtoken.setAnimation(a); |
| 2976 | } |
| 2977 | } else { |
| 2978 | wtoken.clearAnimation(); |
| 2979 | } |
| 2980 | |
| 2981 | return wtoken.animation != null; |
| 2982 | } |
| 2983 | |
| 2984 | // ------------------------------------------------------------- |
| 2985 | // Application Window Tokens |
| 2986 | // ------------------------------------------------------------- |
| 2987 | |
| 2988 | public void validateAppTokens(List tokens) { |
| 2989 | int v = tokens.size()-1; |
| 2990 | int m = mAppTokens.size()-1; |
| 2991 | while (v >= 0 && m >= 0) { |
| 2992 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2993 | if (wtoken.removed) { |
| 2994 | m--; |
| 2995 | continue; |
| 2996 | } |
| 2997 | if (tokens.get(v) != wtoken.token) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2998 | 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] | 2999 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 3000 | } |
| 3001 | v--; |
| 3002 | m--; |
| 3003 | } |
| 3004 | while (v >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3005 | 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] | 3006 | v--; |
| 3007 | } |
| 3008 | while (m >= 0) { |
| 3009 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3010 | if (!wtoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3011 | Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3012 | } |
| 3013 | m--; |
| 3014 | } |
| 3015 | } |
| 3016 | |
| 3017 | boolean checkCallingPermission(String permission, String func) { |
| 3018 | // Quick check: if the calling permission is me, it's all okay. |
| 3019 | if (Binder.getCallingPid() == Process.myPid()) { |
| 3020 | return true; |
| 3021 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3022 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3023 | if (mContext.checkCallingPermission(permission) |
| 3024 | == PackageManager.PERMISSION_GRANTED) { |
| 3025 | return true; |
| 3026 | } |
| 3027 | String msg = "Permission Denial: " + func + " from pid=" |
| 3028 | + Binder.getCallingPid() |
| 3029 | + ", uid=" + Binder.getCallingUid() |
| 3030 | + " requires " + permission; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3031 | Slog.w(TAG, msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3032 | return false; |
| 3033 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3034 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3035 | AppWindowToken findAppWindowToken(IBinder token) { |
| 3036 | WindowToken wtoken = mTokenMap.get(token); |
| 3037 | if (wtoken == null) { |
| 3038 | return null; |
| 3039 | } |
| 3040 | return wtoken.appWindowToken; |
| 3041 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3042 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3043 | public void addWindowToken(IBinder token, int type) { |
| 3044 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3045 | "addWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3046 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3047 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3048 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3049 | synchronized(mWindowMap) { |
| 3050 | WindowToken wtoken = mTokenMap.get(token); |
| 3051 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3052 | 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] | 3053 | return; |
| 3054 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3055 | wtoken = new WindowToken(this, token, type, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3056 | mTokenMap.put(token, wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3057 | if (type == TYPE_WALLPAPER) { |
| 3058 | mWallpaperTokens.add(wtoken); |
| 3059 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3060 | } |
| 3061 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3062 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3063 | public void removeWindowToken(IBinder token) { |
| 3064 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3065 | "removeWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3066 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3067 | } |
| 3068 | |
| 3069 | final long origId = Binder.clearCallingIdentity(); |
| 3070 | synchronized(mWindowMap) { |
| 3071 | WindowToken wtoken = mTokenMap.remove(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3072 | if (wtoken != null) { |
| 3073 | boolean delayed = false; |
| 3074 | if (!wtoken.hidden) { |
| 3075 | wtoken.hidden = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3076 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3077 | final int N = wtoken.windows.size(); |
| 3078 | boolean changed = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3079 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3080 | for (int i=0; i<N; i++) { |
| 3081 | WindowState win = wtoken.windows.get(i); |
| 3082 | |
| 3083 | if (win.isAnimating()) { |
| 3084 | delayed = true; |
| 3085 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3086 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3087 | if (win.isVisibleNow()) { |
| 3088 | applyAnimationLocked(win, |
| 3089 | WindowManagerPolicy.TRANSIT_EXIT, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3090 | changed = true; |
| 3091 | } |
| 3092 | } |
| 3093 | |
| 3094 | if (changed) { |
| 3095 | mLayoutNeeded = true; |
| 3096 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3097 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, |
| 3098 | false /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3099 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3100 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3101 | if (delayed) { |
| 3102 | mExitingTokens.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3103 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 3104 | mWallpaperTokens.remove(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3105 | } |
| 3106 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3107 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 3108 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3109 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3110 | 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] | 3111 | } |
| 3112 | } |
| 3113 | Binder.restoreCallingIdentity(origId); |
| 3114 | } |
| 3115 | |
| 3116 | public void addAppToken(int addPos, IApplicationToken token, |
| 3117 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 3118 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3119 | "addAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3120 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3121 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3122 | |
| 3123 | // Get the dispatching timeout here while we are not holding any locks so that it |
| 3124 | // can be cached by the AppWindowToken. The timeout value is used later by the |
| 3125 | // input dispatcher in code that does hold locks. If we did not cache the value |
| 3126 | // here we would run the chance of introducing a deadlock between the window manager |
| 3127 | // (which holds locks while updating the input dispatcher state) and the activity manager |
| 3128 | // (which holds locks while querying the application token). |
| 3129 | long inputDispatchingTimeoutNanos; |
| 3130 | try { |
| 3131 | inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L; |
| 3132 | } catch (RemoteException ex) { |
| 3133 | Slog.w(TAG, "Could not get dispatching timeout.", ex); |
| 3134 | inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 3135 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3136 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3137 | synchronized(mWindowMap) { |
| 3138 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3139 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3140 | 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] | 3141 | return; |
| 3142 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3143 | wtoken = new AppWindowToken(this, token); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3144 | wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3145 | wtoken.groupId = groupId; |
| 3146 | wtoken.appFullscreen = fullscreen; |
| 3147 | wtoken.requestedOrientation = requestedOrientation; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3148 | 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] | 3149 | mAppTokens.add(addPos, wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3150 | mTokenMap.put(token.asBinder(), wtoken); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3151 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3152 | // Application tokens start out hidden. |
| 3153 | wtoken.hidden = true; |
| 3154 | wtoken.hiddenRequested = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3155 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3156 | //dump(); |
| 3157 | } |
| 3158 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3159 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3160 | public void setAppGroupId(IBinder token, int groupId) { |
| 3161 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3162 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3163 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3164 | } |
| 3165 | |
| 3166 | synchronized(mWindowMap) { |
| 3167 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3168 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3169 | 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] | 3170 | return; |
| 3171 | } |
| 3172 | wtoken.groupId = groupId; |
| 3173 | } |
| 3174 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3175 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3176 | public int getOrientationFromWindowsLocked() { |
| 3177 | int pos = mWindows.size() - 1; |
| 3178 | while (pos >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3179 | WindowState wtoken = mWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3180 | pos--; |
| 3181 | if (wtoken.mAppToken != null) { |
| 3182 | // We hit an application window. so the orientation will be determined by the |
| 3183 | // app window. No point in continuing further. |
| 3184 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3185 | } |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3186 | if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3187 | continue; |
| 3188 | } |
| 3189 | int req = wtoken.mAttrs.screenOrientation; |
| 3190 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 3191 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 3192 | continue; |
| 3193 | } else { |
| 3194 | return req; |
| 3195 | } |
| 3196 | } |
| 3197 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3198 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3199 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3200 | public int getOrientationFromAppTokensLocked() { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3201 | int pos = mAppTokens.size() - 1; |
| 3202 | int curGroup = 0; |
| 3203 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3204 | boolean findingBehind = false; |
| 3205 | boolean haveGroup = false; |
| 3206 | boolean lastFullscreen = false; |
| 3207 | while (pos >= 0) { |
| 3208 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 3209 | pos--; |
| 3210 | // if we're about to tear down this window and not seek for |
| 3211 | // the behind activity, don't use it for orientation |
| 3212 | if (!findingBehind |
| 3213 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| 3214 | continue; |
| 3215 | } |
| 3216 | |
| 3217 | if (!haveGroup) { |
| 3218 | // We ignore any hidden applications on the top. |
| 3219 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3220 | continue; |
| 3221 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3222 | haveGroup = true; |
| 3223 | curGroup = wtoken.groupId; |
| 3224 | lastOrientation = wtoken.requestedOrientation; |
| 3225 | } else if (curGroup != wtoken.groupId) { |
| 3226 | // If we have hit a new application group, and the bottom |
| 3227 | // of the previous group didn't explicitly say to use |
| 3228 | // the orientation behind it, and the last app was |
| 3229 | // full screen, then we'll stick with the |
| 3230 | // user's orientation. |
| 3231 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3232 | && lastFullscreen) { |
| 3233 | return lastOrientation; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3234 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3235 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3236 | int or = wtoken.requestedOrientation; |
| 3237 | // If this application is fullscreen, and didn't explicitly say |
| 3238 | // to use the orientation behind it, then just take whatever |
| 3239 | // orientation it has and ignores whatever is under it. |
| 3240 | lastFullscreen = wtoken.appFullscreen; |
| 3241 | if (lastFullscreen |
| 3242 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| 3243 | return or; |
| 3244 | } |
| 3245 | // If this application has requested an explicit orientation, |
| 3246 | // then use it. |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 3247 | if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 3248 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3249 | return or; |
| 3250 | } |
| 3251 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| 3252 | } |
| 3253 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3254 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3255 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3256 | public Configuration updateOrientationFromAppTokens( |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3257 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3258 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3259 | "updateOrientationFromAppTokens()")) { |
| 3260 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3261 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3262 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3263 | Configuration config = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3264 | long ident = Binder.clearCallingIdentity(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3265 | |
| 3266 | synchronized(mWindowMap) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3267 | if (updateOrientationFromAppTokensLocked(false)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3268 | if (freezeThisOneIfNeeded != null) { |
| 3269 | AppWindowToken wtoken = findAppWindowToken( |
| 3270 | freezeThisOneIfNeeded); |
| 3271 | if (wtoken != null) { |
| 3272 | startAppFreezingScreenLocked(wtoken, |
| 3273 | ActivityInfo.CONFIG_ORIENTATION); |
| 3274 | } |
| 3275 | } |
| 3276 | config = computeNewConfigurationLocked(); |
| 3277 | |
| 3278 | } else if (currentConfig != null) { |
| 3279 | // No obvious action we need to take, but if our current |
Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3280 | // state mismatches the activity manager's, update it, |
| 3281 | // disregarding font scale, which should remain set to |
| 3282 | // the value of the previous configuration. |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3283 | mTempConfiguration.setToDefaults(); |
Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3284 | mTempConfiguration.fontScale = currentConfig.fontScale; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3285 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3286 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3287 | mWaitingForConfig = true; |
| 3288 | mLayoutNeeded = true; |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3289 | startFreezingDisplayLocked(false); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3290 | config = new Configuration(mTempConfiguration); |
| 3291 | } |
| 3292 | } |
| 3293 | } |
| 3294 | } |
| 3295 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3296 | Binder.restoreCallingIdentity(ident); |
| 3297 | return config; |
| 3298 | } |
| 3299 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3300 | /* |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3301 | * Determine the new desired orientation of the display, returning |
| 3302 | * a non-null new Configuration if it has changed from the current |
| 3303 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3304 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3305 | * SCREEN. This will typically be done for you if you call |
| 3306 | * sendNewConfiguration(). |
| 3307 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3308 | * The orientation is computed from non-application windows first. If none of |
| 3309 | * the non-application windows specify orientation, the orientation is computed from |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3310 | * application tokens. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3311 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3312 | * android.os.IBinder) |
| 3313 | */ |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3314 | boolean updateOrientationFromAppTokensLocked(boolean inTransaction) { |
| 3315 | if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) { |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3316 | // If the display is frozen, some activities may be in the middle |
| 3317 | // of restarting, and thus have removed their old window. If the |
| 3318 | // window has the flag to hide the lock screen, then the lock screen |
| 3319 | // can re-appear and inflict its own orientation on us. Keep the |
| 3320 | // orientation stable until this all settles down. |
| 3321 | return false; |
| 3322 | } |
| 3323 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3324 | boolean changed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3325 | long ident = Binder.clearCallingIdentity(); |
| 3326 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3327 | int req = computeForcedAppOrientationLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3328 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3329 | if (req != mForcedAppOrientation) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3330 | mForcedAppOrientation = req; |
| 3331 | //send a message to Policy indicating orientation change to take |
| 3332 | //action like disabling/enabling sensors etc., |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3333 | mPolicy.setCurrentOrientationLw(req); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3334 | if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION, |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3335 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE, |
| 3336 | inTransaction)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3337 | changed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3338 | } |
| 3339 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3340 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3341 | return changed; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3342 | } finally { |
| 3343 | Binder.restoreCallingIdentity(ident); |
| 3344 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3345 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3346 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3347 | int computeForcedAppOrientationLocked() { |
| 3348 | int req = getOrientationFromWindowsLocked(); |
| 3349 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3350 | req = getOrientationFromAppTokensLocked(); |
| 3351 | } |
| 3352 | return req; |
| 3353 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3354 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3355 | public void setNewConfiguration(Configuration config) { |
| 3356 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3357 | "setNewConfiguration()")) { |
| 3358 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3359 | } |
| 3360 | |
| 3361 | synchronized(mWindowMap) { |
| 3362 | mCurConfiguration = new Configuration(config); |
| 3363 | mWaitingForConfig = false; |
| 3364 | performLayoutAndPlaceSurfacesLocked(); |
| 3365 | } |
| 3366 | } |
| 3367 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3368 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3369 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3370 | "setAppOrientation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3371 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3372 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3373 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3374 | synchronized(mWindowMap) { |
| 3375 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3376 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3377 | 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] | 3378 | return; |
| 3379 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3380 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3381 | wtoken.requestedOrientation = requestedOrientation; |
| 3382 | } |
| 3383 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3384 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3385 | public int getAppOrientation(IApplicationToken token) { |
| 3386 | synchronized(mWindowMap) { |
| 3387 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3388 | if (wtoken == null) { |
| 3389 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3390 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3391 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3392 | return wtoken.requestedOrientation; |
| 3393 | } |
| 3394 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3395 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3396 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3397 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3398 | "setFocusedApp()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3399 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3400 | } |
| 3401 | |
| 3402 | synchronized(mWindowMap) { |
| 3403 | boolean changed = false; |
| 3404 | if (token == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3405 | 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] | 3406 | changed = mFocusedApp != null; |
| 3407 | mFocusedApp = null; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3408 | if (changed) { |
| 3409 | mInputMonitor.setFocusedAppLw(null); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3410 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3411 | } else { |
| 3412 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3413 | if (newFocus == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3414 | 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] | 3415 | return; |
| 3416 | } |
| 3417 | changed = mFocusedApp != newFocus; |
| 3418 | mFocusedApp = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3419 | if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3420 | if (changed) { |
| 3421 | mInputMonitor.setFocusedAppLw(newFocus); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3422 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3423 | } |
| 3424 | |
| 3425 | if (moveFocusNow && changed) { |
| 3426 | final long origId = Binder.clearCallingIdentity(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3427 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3428 | Binder.restoreCallingIdentity(origId); |
| 3429 | } |
| 3430 | } |
| 3431 | } |
| 3432 | |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 3433 | public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3434 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3435 | "prepareAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3436 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3437 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3438 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3439 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3440 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3441 | TAG, "Prepare app transition: transit=" + transit |
| 3442 | + " mNextAppTransition=" + mNextAppTransition); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3443 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3444 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3445 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3446 | mNextAppTransition = transit; |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 3447 | } else if (!alwaysKeepCurrent) { |
| 3448 | if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3449 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3450 | // Opening a new task always supersedes a close for the anim. |
| 3451 | mNextAppTransition = transit; |
| 3452 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3453 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3454 | // Opening a new activity always supersedes a close for the anim. |
| 3455 | mNextAppTransition = transit; |
| 3456 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3457 | } |
| 3458 | mAppTransitionReady = false; |
| 3459 | mAppTransitionTimeout = false; |
| 3460 | mStartingIconInTransition = false; |
| 3461 | mSkipAppTransitionAnimation = false; |
| 3462 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3463 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3464 | 5000); |
| 3465 | } |
| 3466 | } |
| 3467 | } |
| 3468 | |
| 3469 | public int getPendingAppTransition() { |
| 3470 | return mNextAppTransition; |
| 3471 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3472 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3473 | public void overridePendingAppTransition(String packageName, |
| 3474 | int enterAnim, int exitAnim) { |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3475 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3476 | mNextAppTransitionPackage = packageName; |
| 3477 | mNextAppTransitionEnter = enterAnim; |
| 3478 | mNextAppTransitionExit = exitAnim; |
| 3479 | } |
| 3480 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3481 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3482 | public void executeAppTransition() { |
| 3483 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3484 | "executeAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3485 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3486 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3487 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3488 | synchronized(mWindowMap) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3489 | if (DEBUG_APP_TRANSITIONS) { |
| 3490 | RuntimeException e = new RuntimeException("here"); |
| 3491 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3492 | Slog.w(TAG, "Execute app transition: mNextAppTransition=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3493 | + mNextAppTransition, e); |
| 3494 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3495 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3496 | mAppTransitionReady = true; |
| 3497 | final long origId = Binder.clearCallingIdentity(); |
| 3498 | performLayoutAndPlaceSurfacesLocked(); |
| 3499 | Binder.restoreCallingIdentity(origId); |
| 3500 | } |
| 3501 | } |
| 3502 | } |
| 3503 | |
| 3504 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3505 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 3506 | int windowFlags, IBinder transferFrom, boolean createIfNeeded) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3507 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3508 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3509 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3510 | } |
| 3511 | |
| 3512 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3513 | if (DEBUG_STARTING_WINDOW) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3514 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3515 | + " transferFrom=" + transferFrom); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3516 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3517 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3518 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3519 | 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] | 3520 | return; |
| 3521 | } |
| 3522 | |
| 3523 | // If the display is frozen, we won't do anything until the |
| 3524 | // actual window is displayed so there is no reason to put in |
| 3525 | // the starting window. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3526 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3527 | return; |
| 3528 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3529 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3530 | if (wtoken.startingData != null) { |
| 3531 | return; |
| 3532 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3533 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3534 | if (transferFrom != null) { |
| 3535 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3536 | if (ttoken != null) { |
| 3537 | WindowState startingWindow = ttoken.startingWindow; |
| 3538 | if (startingWindow != null) { |
| 3539 | if (mStartingIconInTransition) { |
| 3540 | // In this case, the starting icon has already |
| 3541 | // been displayed, so start letting windows get |
| 3542 | // shown immediately without any more transitions. |
| 3543 | mSkipAppTransitionAnimation = true; |
| 3544 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3545 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3546 | "Moving existing starting from " + ttoken |
| 3547 | + " to " + wtoken); |
| 3548 | final long origId = Binder.clearCallingIdentity(); |
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 | // Transfer the starting window over to the new |
| 3551 | // token. |
| 3552 | wtoken.startingData = ttoken.startingData; |
| 3553 | wtoken.startingView = ttoken.startingView; |
| 3554 | wtoken.startingWindow = startingWindow; |
| 3555 | ttoken.startingData = null; |
| 3556 | ttoken.startingView = null; |
| 3557 | ttoken.startingWindow = null; |
| 3558 | ttoken.startingMoved = true; |
| 3559 | startingWindow.mToken = wtoken; |
Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3560 | startingWindow.mRootToken = wtoken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3561 | startingWindow.mAppToken = wtoken; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3562 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3563 | "Removing starting window: " + startingWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3564 | mWindows.remove(startingWindow); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3565 | mWindowsChanged = true; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3566 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing starting " + startingWindow |
| 3567 | + " from " + ttoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3568 | ttoken.windows.remove(startingWindow); |
| 3569 | ttoken.allAppWindows.remove(startingWindow); |
| 3570 | addWindowToListInOrderLocked(startingWindow, true); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3571 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3572 | // Propagate other interesting state between the |
| 3573 | // tokens. If the old token is displayed, we should |
| 3574 | // immediately force the new one to be displayed. If |
| 3575 | // it is animating, we need to move that animation to |
| 3576 | // the new one. |
| 3577 | if (ttoken.allDrawn) { |
| 3578 | wtoken.allDrawn = true; |
| 3579 | } |
| 3580 | if (ttoken.firstWindowDrawn) { |
| 3581 | wtoken.firstWindowDrawn = true; |
| 3582 | } |
| 3583 | if (!ttoken.hidden) { |
| 3584 | wtoken.hidden = false; |
| 3585 | wtoken.hiddenRequested = false; |
| 3586 | wtoken.willBeHidden = false; |
| 3587 | } |
| 3588 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3589 | wtoken.clientHidden = ttoken.clientHidden; |
| 3590 | wtoken.sendAppVisibilityToClients(); |
| 3591 | } |
| 3592 | if (ttoken.animation != null) { |
| 3593 | wtoken.animation = ttoken.animation; |
| 3594 | wtoken.animating = ttoken.animating; |
| 3595 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3596 | ttoken.animation = null; |
| 3597 | ttoken.animLayerAdjustment = 0; |
| 3598 | wtoken.updateLayers(); |
| 3599 | ttoken.updateLayers(); |
| 3600 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3601 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3602 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 3603 | true /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3604 | mLayoutNeeded = true; |
| 3605 | performLayoutAndPlaceSurfacesLocked(); |
| 3606 | Binder.restoreCallingIdentity(origId); |
| 3607 | return; |
| 3608 | } else if (ttoken.startingData != null) { |
| 3609 | // The previous app was getting ready to show a |
| 3610 | // starting window, but hasn't yet done so. Steal it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3611 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3612 | "Moving pending starting from " + ttoken |
| 3613 | + " to " + wtoken); |
| 3614 | wtoken.startingData = ttoken.startingData; |
| 3615 | ttoken.startingData = null; |
| 3616 | ttoken.startingMoved = true; |
| 3617 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3618 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3619 | // want to process the message ASAP, before any other queued |
| 3620 | // messages. |
| 3621 | mH.sendMessageAtFrontOfQueue(m); |
| 3622 | return; |
| 3623 | } |
| 3624 | } |
| 3625 | } |
| 3626 | |
| 3627 | // There is no existing starting window, and the caller doesn't |
| 3628 | // want us to create one, so that's it! |
| 3629 | if (!createIfNeeded) { |
| 3630 | return; |
| 3631 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3632 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3633 | // If this is a translucent or wallpaper window, then don't |
| 3634 | // show a starting window -- the current effect (a full-screen |
| 3635 | // opaque starting window that fades away to the real contents |
| 3636 | // when it is ready) does not work for this. |
| 3637 | if (theme != 0) { |
| 3638 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3639 | com.android.internal.R.styleable.Window); |
| 3640 | if (ent.array.getBoolean( |
| 3641 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3642 | return; |
| 3643 | } |
| 3644 | if (ent.array.getBoolean( |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3645 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3646 | return; |
| 3647 | } |
| 3648 | if (ent.array.getBoolean( |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3649 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3650 | return; |
| 3651 | } |
| 3652 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3653 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3654 | mStartingIconInTransition = true; |
| 3655 | wtoken.startingData = new StartingData( |
| 3656 | pkg, theme, nonLocalizedLabel, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 3657 | labelRes, icon, windowFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3658 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3659 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3660 | // want to process the message ASAP, before any other queued |
| 3661 | // messages. |
| 3662 | mH.sendMessageAtFrontOfQueue(m); |
| 3663 | } |
| 3664 | } |
| 3665 | |
| 3666 | public void setAppWillBeHidden(IBinder token) { |
| 3667 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3668 | "setAppWillBeHidden()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3669 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3670 | } |
| 3671 | |
| 3672 | AppWindowToken wtoken; |
| 3673 | |
| 3674 | synchronized(mWindowMap) { |
| 3675 | wtoken = findAppWindowToken(token); |
| 3676 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3677 | 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] | 3678 | return; |
| 3679 | } |
| 3680 | wtoken.willBeHidden = true; |
| 3681 | } |
| 3682 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3683 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3684 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3685 | boolean visible, int transit, boolean performLayout, boolean bgFiller) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3686 | boolean delayed = false; |
| 3687 | |
| 3688 | if (wtoken.clientHidden == visible) { |
| 3689 | wtoken.clientHidden = !visible; |
| 3690 | wtoken.sendAppVisibilityToClients(); |
| 3691 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3692 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3693 | wtoken.willBeHidden = false; |
| 3694 | if (wtoken.hidden == visible) { |
| 3695 | final int N = wtoken.allAppWindows.size(); |
| 3696 | boolean changed = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3697 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3698 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3699 | + " performLayout=" + performLayout); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3700 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3701 | boolean runningAppAnimation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3702 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3703 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3704 | if (wtoken.animation == sDummyAnimation) { |
| 3705 | wtoken.animation = null; |
| 3706 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3707 | applyAnimationLocked(wtoken, lp, transit, visible, bgFiller); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3708 | changed = true; |
| 3709 | if (wtoken.animation != null) { |
| 3710 | delayed = runningAppAnimation = true; |
| 3711 | } |
| 3712 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3713 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3714 | for (int i=0; i<N; i++) { |
| 3715 | WindowState win = wtoken.allAppWindows.get(i); |
| 3716 | if (win == wtoken.startingWindow) { |
| 3717 | continue; |
| 3718 | } |
| 3719 | |
| 3720 | if (win.isAnimating()) { |
| 3721 | delayed = true; |
| 3722 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3723 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3724 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3725 | //win.dump(" "); |
| 3726 | if (visible) { |
| 3727 | if (!win.isVisibleNow()) { |
| 3728 | if (!runningAppAnimation) { |
| 3729 | applyAnimationLocked(win, |
| 3730 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 3731 | } |
| 3732 | changed = true; |
| 3733 | } |
| 3734 | } else if (win.isVisibleNow()) { |
| 3735 | if (!runningAppAnimation) { |
| 3736 | applyAnimationLocked(win, |
| 3737 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 3738 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3739 | changed = true; |
| 3740 | } |
| 3741 | } |
| 3742 | |
| 3743 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 3744 | if (!visible) { |
| 3745 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3746 | } else { |
| 3747 | // If we are being set visible, and the starting window is |
| 3748 | // not yet displayed, then make sure it doesn't get displayed. |
| 3749 | WindowState swin = wtoken.startingWindow; |
| 3750 | if (swin != null && (swin.mDrawPending |
| 3751 | || swin.mCommitDrawPending)) { |
| 3752 | swin.mPolicyVisibility = false; |
| 3753 | swin.mPolicyVisibilityAfterAnim = false; |
| 3754 | } |
| 3755 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3756 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3757 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3758 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 3759 | + wtoken.hiddenRequested); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3760 | |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3761 | if (changed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3762 | mLayoutNeeded = true; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3763 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3764 | if (performLayout) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3765 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 3766 | false /*updateInputWindows*/); |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3767 | performLayoutAndPlaceSurfacesLocked(); |
| 3768 | } |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 3769 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3770 | } |
| 3771 | } |
| 3772 | |
| 3773 | if (wtoken.animation != null) { |
| 3774 | delayed = true; |
| 3775 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3776 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3777 | return delayed; |
| 3778 | } |
| 3779 | |
| 3780 | public void setAppVisibility(IBinder token, boolean visible) { |
| 3781 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3782 | "setAppVisibility()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3783 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3784 | } |
| 3785 | |
| 3786 | AppWindowToken wtoken; |
| 3787 | |
| 3788 | synchronized(mWindowMap) { |
| 3789 | wtoken = findAppWindowToken(token); |
| 3790 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3791 | 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] | 3792 | return; |
| 3793 | } |
| 3794 | |
| 3795 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3796 | RuntimeException e = null; |
| 3797 | if (!HIDE_STACK_CRAWLS) { |
| 3798 | e = new RuntimeException(); |
| 3799 | e.fillInStackTrace(); |
| 3800 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3801 | Slog.v(TAG, "setAppVisibility(" + token + ", " + visible |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3802 | + "): mNextAppTransition=" + mNextAppTransition |
| 3803 | + " hidden=" + wtoken.hidden |
| 3804 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 3805 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3806 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3807 | // If we are preparing an app transition, then delay changing |
| 3808 | // the visibility of this token until we execute that transition. |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3809 | if (!mDisplayFrozen && mPolicy.isScreenOn() |
| 3810 | && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3811 | // Already in requested state, don't do anything more. |
| 3812 | if (wtoken.hiddenRequested != visible) { |
| 3813 | return; |
| 3814 | } |
| 3815 | wtoken.hiddenRequested = !visible; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3816 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3817 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3818 | TAG, "Setting dummy animation on: " + wtoken); |
| 3819 | wtoken.setDummyAnimation(); |
| 3820 | mOpeningApps.remove(wtoken); |
| 3821 | mClosingApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3822 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3823 | wtoken.inPendingTransaction = true; |
| 3824 | if (visible) { |
| 3825 | mOpeningApps.add(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3826 | wtoken.startingDisplayed = false; |
| 3827 | wtoken.startingMoved = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3828 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3829 | // If the token is currently hidden (should be the |
| 3830 | // common case), then we need to set up to wait for |
| 3831 | // its windows to be ready. |
| 3832 | if (wtoken.hidden) { |
| 3833 | wtoken.allDrawn = false; |
| 3834 | wtoken.waitingToShow = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3835 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3836 | if (wtoken.clientHidden) { |
| 3837 | // In the case where we are making an app visible |
| 3838 | // but holding off for a transition, we still need |
| 3839 | // to tell the client to make its windows visible so |
| 3840 | // they get drawn. Otherwise, we will wait on |
| 3841 | // performing the transition until all windows have |
| 3842 | // been drawn, they never will be, and we are sad. |
| 3843 | wtoken.clientHidden = false; |
| 3844 | wtoken.sendAppVisibilityToClients(); |
| 3845 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3846 | } |
| 3847 | } else { |
| 3848 | mClosingApps.add(wtoken); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3849 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3850 | // If the token is currently visible (should be the |
| 3851 | // common case), then set up to wait for it to be hidden. |
| 3852 | if (!wtoken.hidden) { |
| 3853 | wtoken.waitingToHide = true; |
| 3854 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3855 | } |
| 3856 | return; |
| 3857 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3858 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3859 | final long origId = Binder.clearCallingIdentity(); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3860 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, |
| 3861 | true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3862 | wtoken.updateReportedVisibilityLocked(); |
| 3863 | Binder.restoreCallingIdentity(origId); |
| 3864 | } |
| 3865 | } |
| 3866 | |
| 3867 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3868 | boolean unfreezeSurfaceNow, boolean force) { |
| 3869 | if (wtoken.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3870 | 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] | 3871 | + " force=" + force); |
| 3872 | final int N = wtoken.allAppWindows.size(); |
| 3873 | boolean unfrozeWindows = false; |
| 3874 | for (int i=0; i<N; i++) { |
| 3875 | WindowState w = wtoken.allAppWindows.get(i); |
| 3876 | if (w.mAppFreezing) { |
| 3877 | w.mAppFreezing = false; |
| 3878 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 3879 | w.mOrientationChanging = true; |
| 3880 | } |
| 3881 | unfrozeWindows = true; |
| 3882 | } |
| 3883 | } |
| 3884 | if (force || unfrozeWindows) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3885 | 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] | 3886 | wtoken.freezingScreen = false; |
| 3887 | mAppsFreezingScreen--; |
| 3888 | } |
| 3889 | if (unfreezeSurfaceNow) { |
| 3890 | if (unfrozeWindows) { |
| 3891 | mLayoutNeeded = true; |
| 3892 | performLayoutAndPlaceSurfacesLocked(); |
| 3893 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3894 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3895 | } |
| 3896 | } |
| 3897 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3898 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3899 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3900 | int configChanges) { |
| 3901 | if (DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3902 | RuntimeException e = null; |
| 3903 | if (!HIDE_STACK_CRAWLS) { |
| 3904 | e = new RuntimeException(); |
| 3905 | e.fillInStackTrace(); |
| 3906 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3907 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3908 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 3909 | + wtoken.freezingScreen, e); |
| 3910 | } |
| 3911 | if (!wtoken.hiddenRequested) { |
| 3912 | if (!wtoken.freezingScreen) { |
| 3913 | wtoken.freezingScreen = true; |
| 3914 | mAppsFreezingScreen++; |
| 3915 | if (mAppsFreezingScreen == 1) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3916 | startFreezingDisplayLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3917 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 3918 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 3919 | 5000); |
| 3920 | } |
| 3921 | } |
| 3922 | final int N = wtoken.allAppWindows.size(); |
| 3923 | for (int i=0; i<N; i++) { |
| 3924 | WindowState w = wtoken.allAppWindows.get(i); |
| 3925 | w.mAppFreezing = true; |
| 3926 | } |
| 3927 | } |
| 3928 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3929 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3930 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 3931 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3932 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3933 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3934 | } |
| 3935 | |
| 3936 | synchronized(mWindowMap) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3937 | if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3938 | 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] | 3939 | return; |
| 3940 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3941 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3942 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3943 | if (wtoken == null || wtoken.appToken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3944 | 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] | 3945 | return; |
| 3946 | } |
| 3947 | final long origId = Binder.clearCallingIdentity(); |
| 3948 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 3949 | Binder.restoreCallingIdentity(origId); |
| 3950 | } |
| 3951 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3952 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3953 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 3954 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3955 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3956 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3957 | } |
| 3958 | |
| 3959 | synchronized(mWindowMap) { |
| 3960 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3961 | if (wtoken == null || wtoken.appToken == null) { |
| 3962 | return; |
| 3963 | } |
| 3964 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3965 | 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] | 3966 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 3967 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 3968 | Binder.restoreCallingIdentity(origId); |
| 3969 | } |
| 3970 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3971 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3972 | public void removeAppToken(IBinder token) { |
| 3973 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3974 | "removeAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3975 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3976 | } |
| 3977 | |
| 3978 | AppWindowToken wtoken = null; |
| 3979 | AppWindowToken startingToken = null; |
| 3980 | boolean delayed = false; |
| 3981 | |
| 3982 | final long origId = Binder.clearCallingIdentity(); |
| 3983 | synchronized(mWindowMap) { |
| 3984 | WindowToken basewtoken = mTokenMap.remove(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3985 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3986 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3987 | delayed = setTokenVisibilityLocked(wtoken, null, false, |
| 3988 | WindowManagerPolicy.TRANSIT_UNSET, true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3989 | wtoken.inPendingTransaction = false; |
| 3990 | mOpeningApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3991 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3992 | if (mClosingApps.contains(wtoken)) { |
| 3993 | delayed = true; |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3994 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3995 | mClosingApps.add(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3996 | wtoken.waitingToHide = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3997 | delayed = true; |
| 3998 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3999 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4000 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 4001 | + " animation=" + wtoken.animation |
| 4002 | + " animating=" + wtoken.animating); |
| 4003 | if (delayed) { |
| 4004 | // 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] | 4005 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4006 | "removeAppToken make exiting: " + wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4007 | mExitingAppTokens.add(wtoken); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 4008 | } else { |
| 4009 | // Make sure there is no animation running on this token, |
| 4010 | // so any windows associated with it will be removed as |
| 4011 | // soon as their animations are complete |
| 4012 | wtoken.animation = null; |
| 4013 | wtoken.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4014 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4015 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4016 | "removeAppToken: " + wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4017 | mAppTokens.remove(wtoken); |
| 4018 | wtoken.removed = true; |
| 4019 | if (wtoken.startingData != null) { |
| 4020 | startingToken = wtoken; |
| 4021 | } |
| 4022 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 4023 | if (mFocusedApp == wtoken) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4024 | 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] | 4025 | mFocusedApp = null; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4026 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4027 | mInputMonitor.setFocusedAppLw(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4028 | } |
| 4029 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4030 | 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] | 4031 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4032 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4033 | if (!delayed && wtoken != null) { |
| 4034 | wtoken.updateReportedVisibilityLocked(); |
| 4035 | } |
| 4036 | } |
| 4037 | Binder.restoreCallingIdentity(origId); |
| 4038 | |
| 4039 | if (startingToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4040 | 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] | 4041 | + startingToken + ": app token removed"); |
| 4042 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 4043 | mH.sendMessage(m); |
| 4044 | } |
| 4045 | } |
| 4046 | |
| 4047 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 4048 | final int NW = token.windows.size(); |
| 4049 | for (int i=0; i<NW; i++) { |
| 4050 | WindowState win = token.windows.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4051 | 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] | 4052 | mWindows.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4053 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4054 | int j = win.mChildWindows.size(); |
| 4055 | while (j > 0) { |
| 4056 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4057 | WindowState cwin = win.mChildWindows.get(j); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4058 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4059 | "Tmp removing child window " + cwin); |
| 4060 | mWindows.remove(cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4061 | } |
| 4062 | } |
| 4063 | return NW > 0; |
| 4064 | } |
| 4065 | |
| 4066 | void dumpAppTokensLocked() { |
| 4067 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4068 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4069 | } |
| 4070 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4071 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4072 | void dumpWindowsLocked() { |
| 4073 | for (int i=mWindows.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4074 | Slog.v(TAG, " #" + i + ": " + mWindows.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4075 | } |
| 4076 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4077 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4078 | private int findWindowOffsetLocked(int tokenPos) { |
| 4079 | final int NW = mWindows.size(); |
| 4080 | |
| 4081 | if (tokenPos >= mAppTokens.size()) { |
| 4082 | int i = NW; |
| 4083 | while (i > 0) { |
| 4084 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4085 | WindowState win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4086 | if (win.getAppToken() != null) { |
| 4087 | return i+1; |
| 4088 | } |
| 4089 | } |
| 4090 | } |
| 4091 | |
| 4092 | while (tokenPos > 0) { |
| 4093 | // Find the first app token below the new position that has |
| 4094 | // a window displayed. |
| 4095 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4096 | 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] | 4097 | + tokenPos + " -- " + wtoken.token); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4098 | if (wtoken.sendingToBottom) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4099 | if (DEBUG_REORDER) Slog.v(TAG, |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4100 | "Skipping token -- currently sending to bottom"); |
| 4101 | tokenPos--; |
| 4102 | continue; |
| 4103 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4104 | int i = wtoken.windows.size(); |
| 4105 | while (i > 0) { |
| 4106 | i--; |
| 4107 | WindowState win = wtoken.windows.get(i); |
| 4108 | int j = win.mChildWindows.size(); |
| 4109 | while (j > 0) { |
| 4110 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4111 | WindowState cwin = win.mChildWindows.get(j); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4112 | if (cwin.mSubLayer >= 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4113 | for (int pos=NW-1; pos>=0; pos--) { |
| 4114 | if (mWindows.get(pos) == cwin) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4115 | if (DEBUG_REORDER) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4116 | "Found child win @" + (pos+1)); |
| 4117 | return pos+1; |
| 4118 | } |
| 4119 | } |
| 4120 | } |
| 4121 | } |
| 4122 | for (int pos=NW-1; pos>=0; pos--) { |
| 4123 | if (mWindows.get(pos) == win) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4124 | 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] | 4125 | return pos+1; |
| 4126 | } |
| 4127 | } |
| 4128 | } |
| 4129 | tokenPos--; |
| 4130 | } |
| 4131 | |
| 4132 | return 0; |
| 4133 | } |
| 4134 | |
| 4135 | private final int reAddWindowLocked(int index, WindowState win) { |
| 4136 | final int NCW = win.mChildWindows.size(); |
| 4137 | boolean added = false; |
| 4138 | for (int j=0; j<NCW; j++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4139 | WindowState cwin = win.mChildWindows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4140 | if (!added && cwin.mSubLayer >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4141 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4142 | + index + ": " + cwin); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4143 | win.mRebuilding = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4144 | mWindows.add(index, win); |
| 4145 | index++; |
| 4146 | added = true; |
| 4147 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4148 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4149 | + index + ": " + cwin); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4150 | cwin.mRebuilding = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4151 | mWindows.add(index, cwin); |
| 4152 | index++; |
| 4153 | } |
| 4154 | if (!added) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4155 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4156 | + index + ": " + win); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4157 | win.mRebuilding = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4158 | mWindows.add(index, win); |
| 4159 | index++; |
| 4160 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4161 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4162 | return index; |
| 4163 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4164 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4165 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 4166 | final int NW = token.windows.size(); |
| 4167 | for (int i=0; i<NW; i++) { |
| 4168 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 4169 | } |
| 4170 | return index; |
| 4171 | } |
| 4172 | |
| 4173 | public void moveAppToken(int index, IBinder token) { |
| 4174 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4175 | "moveAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4176 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4177 | } |
| 4178 | |
| 4179 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4180 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4181 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 4182 | final AppWindowToken wtoken = findAppWindowToken(token); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4183 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG, |
| 4184 | "Start moving token " + wtoken + " initially at " |
| 4185 | + mAppTokens.indexOf(wtoken)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4186 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4187 | 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] | 4188 | + token + " (" + wtoken + ")"); |
| 4189 | return; |
| 4190 | } |
| 4191 | mAppTokens.add(index, wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4192 | if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4193 | 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] | 4194 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4195 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4196 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4197 | 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] | 4198 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4199 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4200 | 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] | 4201 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4202 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4203 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4204 | if (DEBUG_REORDER) dumpWindowsLocked(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4205 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4206 | false /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4207 | mLayoutNeeded = true; |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4208 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4209 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4210 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4211 | } |
| 4212 | Binder.restoreCallingIdentity(origId); |
| 4213 | } |
| 4214 | } |
| 4215 | |
| 4216 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 4217 | // XXX This should be done more efficiently! |
| 4218 | // (take advantage of the fact that both lists should be |
| 4219 | // ordered in the same way.) |
| 4220 | int N = tokens.size(); |
| 4221 | for (int i=0; i<N; i++) { |
| 4222 | IBinder token = tokens.get(i); |
| 4223 | final AppWindowToken wtoken = findAppWindowToken(token); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4224 | if (DEBUG_REORDER || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4225 | "Temporarily removing " + wtoken + " from " + mAppTokens.indexOf(wtoken)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4226 | if (!mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4227 | 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] | 4228 | + token + " (" + wtoken + ")"); |
| 4229 | i--; |
| 4230 | N--; |
| 4231 | } |
| 4232 | } |
| 4233 | } |
| 4234 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4235 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 4236 | boolean updateFocusAndLayout) { |
| 4237 | // First remove all of the windows from the list. |
| 4238 | tmpRemoveAppWindowsLocked(wtoken); |
| 4239 | |
| 4240 | // Where to start adding? |
| 4241 | int pos = findWindowOffsetLocked(tokenPos); |
| 4242 | |
| 4243 | // And now add them back at the correct place. |
| 4244 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 4245 | |
| 4246 | if (updateFocusAndLayout) { |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4247 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4248 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4249 | false /*updateInputWindows*/)) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4250 | assignLayersLocked(); |
| 4251 | } |
| 4252 | mLayoutNeeded = true; |
| 4253 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4254 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4255 | } |
| 4256 | } |
| 4257 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4258 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 4259 | // First remove all of the windows from the list. |
| 4260 | final int N = tokens.size(); |
| 4261 | int i; |
| 4262 | for (i=0; i<N; i++) { |
| 4263 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4264 | if (token != null) { |
| 4265 | tmpRemoveAppWindowsLocked(token); |
| 4266 | } |
| 4267 | } |
| 4268 | |
| 4269 | // Where to start adding? |
| 4270 | int pos = findWindowOffsetLocked(tokenPos); |
| 4271 | |
| 4272 | // And now add them back at the correct place. |
| 4273 | for (i=0; i<N; i++) { |
| 4274 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4275 | if (token != null) { |
| 4276 | pos = reAddAppWindowsLocked(pos, token); |
| 4277 | } |
| 4278 | } |
| 4279 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4280 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4281 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4282 | false /*updateInputWindows*/)) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4283 | assignLayersLocked(); |
| 4284 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4285 | mLayoutNeeded = true; |
| 4286 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4287 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4288 | |
| 4289 | //dump(); |
| 4290 | } |
| 4291 | |
| 4292 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4293 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4294 | "moveAppTokensToTop()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4295 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4296 | } |
| 4297 | |
| 4298 | final long origId = Binder.clearCallingIdentity(); |
| 4299 | synchronized(mWindowMap) { |
| 4300 | removeAppTokensLocked(tokens); |
| 4301 | final int N = tokens.size(); |
| 4302 | for (int i=0; i<N; i++) { |
| 4303 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4304 | if (wt != null) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4305 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG, |
| 4306 | "Adding next to top: " + wt); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4307 | mAppTokens.add(wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4308 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4309 | mToTopApps.remove(wt); |
| 4310 | mToBottomApps.remove(wt); |
| 4311 | mToTopApps.add(wt); |
| 4312 | wt.sendingToBottom = false; |
| 4313 | wt.sendingToTop = true; |
| 4314 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4315 | } |
| 4316 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4317 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4318 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4319 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4320 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4321 | } |
| 4322 | Binder.restoreCallingIdentity(origId); |
| 4323 | } |
| 4324 | |
| 4325 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4326 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4327 | "moveAppTokensToBottom()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4328 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4329 | } |
| 4330 | |
| 4331 | final long origId = Binder.clearCallingIdentity(); |
| 4332 | synchronized(mWindowMap) { |
| 4333 | removeAppTokensLocked(tokens); |
| 4334 | final int N = tokens.size(); |
| 4335 | int pos = 0; |
| 4336 | for (int i=0; i<N; i++) { |
| 4337 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4338 | if (wt != null) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4339 | if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4340 | "Adding next to bottom: " + wt + " at " + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4341 | mAppTokens.add(pos, wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4342 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4343 | mToTopApps.remove(wt); |
| 4344 | mToBottomApps.remove(wt); |
| 4345 | mToBottomApps.add(i, wt); |
| 4346 | wt.sendingToTop = false; |
| 4347 | wt.sendingToBottom = true; |
| 4348 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4349 | pos++; |
| 4350 | } |
| 4351 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4352 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4353 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4354 | moveAppWindowsLocked(tokens, 0); |
| 4355 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4356 | } |
| 4357 | Binder.restoreCallingIdentity(origId); |
| 4358 | } |
| 4359 | |
| 4360 | // ------------------------------------------------------------- |
| 4361 | // Misc IWindowSession methods |
| 4362 | // ------------------------------------------------------------- |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4363 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4364 | private boolean shouldAllowDisableKeyguard() |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4365 | { |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4366 | // We fail safe and prevent disabling keyguard in the unlikely event this gets |
| 4367 | // called before DevicePolicyManagerService has started. |
| 4368 | if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { |
| 4369 | DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( |
| 4370 | Context.DEVICE_POLICY_SERVICE); |
| 4371 | if (dpm != null) { |
| 4372 | mAllowDisableKeyguard = dpm.getPasswordQuality(null) |
| 4373 | == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? |
| 4374 | ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; |
| 4375 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4376 | } |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4377 | return mAllowDisableKeyguard == ALLOW_DISABLE_YES; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4378 | } |
| 4379 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4380 | public void disableKeyguard(IBinder token, String tag) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4381 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4382 | != PackageManager.PERMISSION_GRANTED) { |
| 4383 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4384 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4385 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4386 | synchronized (mKeyguardTokenWatcher) { |
| 4387 | mKeyguardTokenWatcher.acquire(token, tag); |
Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4388 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4389 | } |
| 4390 | |
| 4391 | public void reenableKeyguard(IBinder token) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4392 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4393 | != PackageManager.PERMISSION_GRANTED) { |
| 4394 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4395 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4396 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4397 | synchronized (mKeyguardTokenWatcher) { |
| 4398 | mKeyguardTokenWatcher.release(token); |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4399 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4400 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4401 | // If we are the last one to reenable the keyguard wait until |
| 4402 | // we have actually finished reenabling until returning. |
| 4403 | // It is possible that reenableKeyguard() can be called before |
| 4404 | // the previous disableKeyguard() is handled, in which case |
| 4405 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4406 | // be called. In that case mKeyguardDisabled will be false here |
| 4407 | // and we have nothing to wait for. |
| 4408 | while (mKeyguardDisabled) { |
| 4409 | try { |
| 4410 | mKeyguardTokenWatcher.wait(); |
| 4411 | } catch (InterruptedException e) { |
| 4412 | Thread.currentThread().interrupt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4413 | } |
| 4414 | } |
| 4415 | } |
| 4416 | } |
| 4417 | } |
| 4418 | |
| 4419 | /** |
| 4420 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4421 | */ |
| 4422 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4423 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4424 | != PackageManager.PERMISSION_GRANTED) { |
| 4425 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4426 | } |
| 4427 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4428 | public void onKeyguardExitResult(boolean success) { |
| 4429 | try { |
| 4430 | callback.onKeyguardExitResult(success); |
| 4431 | } catch (RemoteException e) { |
| 4432 | // Client has died, we don't care. |
| 4433 | } |
| 4434 | } |
| 4435 | }); |
| 4436 | } |
| 4437 | |
| 4438 | public boolean inKeyguardRestrictedInputMode() { |
| 4439 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4440 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4441 | |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 4442 | public boolean isKeyguardLocked() { |
| 4443 | return mPolicy.isKeyguardLocked(); |
| 4444 | } |
| 4445 | |
| 4446 | public boolean isKeyguardSecure() { |
| 4447 | return mPolicy.isKeyguardSecure(); |
| 4448 | } |
| 4449 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4450 | public void closeSystemDialogs(String reason) { |
| 4451 | synchronized(mWindowMap) { |
| 4452 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4453 | WindowState w = mWindows.get(i); |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4454 | if (w.mSurface != null) { |
| 4455 | try { |
| 4456 | w.mClient.closeSystemDialogs(reason); |
| 4457 | } catch (RemoteException e) { |
| 4458 | } |
| 4459 | } |
| 4460 | } |
| 4461 | } |
| 4462 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4463 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4464 | static float fixScale(float scale) { |
| 4465 | if (scale < 0) scale = 0; |
| 4466 | else if (scale > 20) scale = 20; |
| 4467 | return Math.abs(scale); |
| 4468 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4469 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4470 | public void setAnimationScale(int which, float scale) { |
| 4471 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4472 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4473 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4474 | } |
| 4475 | |
| 4476 | if (scale < 0) scale = 0; |
| 4477 | else if (scale > 20) scale = 20; |
| 4478 | scale = Math.abs(scale); |
| 4479 | switch (which) { |
| 4480 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4481 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4482 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4483 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4484 | // Persist setting |
| 4485 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4486 | } |
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 | public void setAnimationScales(float[] scales) { |
| 4489 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4490 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4491 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4492 | } |
| 4493 | |
| 4494 | if (scales != null) { |
| 4495 | if (scales.length >= 1) { |
| 4496 | mWindowAnimationScale = fixScale(scales[0]); |
| 4497 | } |
| 4498 | if (scales.length >= 2) { |
| 4499 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4500 | } |
| 4501 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4502 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4503 | // Persist setting |
| 4504 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4505 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4506 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4507 | public float getAnimationScale(int which) { |
| 4508 | switch (which) { |
| 4509 | case 0: return mWindowAnimationScale; |
| 4510 | case 1: return mTransitionAnimationScale; |
| 4511 | } |
| 4512 | return 0; |
| 4513 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4514 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4515 | public float[] getAnimationScales() { |
| 4516 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4517 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4518 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4519 | public int getSwitchState(int sw) { |
| 4520 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4521 | "getSwitchState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4522 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4523 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4524 | return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4525 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4526 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4527 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4528 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4529 | "getSwitchStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4530 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4531 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4532 | return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4533 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4534 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4535 | public int getScancodeState(int sw) { |
| 4536 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4537 | "getScancodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4538 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4539 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4540 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4541 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4542 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4543 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4544 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4545 | "getScancodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4546 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4547 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4548 | return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4549 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4550 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4551 | public int getTrackballScancodeState(int sw) { |
| 4552 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4553 | "getTrackballScancodeState()")) { |
| 4554 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4555 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4556 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4557 | } |
| 4558 | |
| 4559 | public int getDPadScancodeState(int sw) { |
| 4560 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4561 | "getDPadScancodeState()")) { |
| 4562 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4563 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4564 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4565 | } |
| 4566 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4567 | public int getKeycodeState(int sw) { |
| 4568 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4569 | "getKeycodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4570 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4571 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4572 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4573 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4574 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4575 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4576 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4577 | "getKeycodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4578 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4579 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4580 | return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4581 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4582 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4583 | public int getTrackballKeycodeState(int sw) { |
| 4584 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4585 | "getTrackballKeycodeState()")) { |
| 4586 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4587 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4588 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4589 | } |
| 4590 | |
| 4591 | public int getDPadKeycodeState(int sw) { |
| 4592 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4593 | "getDPadKeycodeState()")) { |
| 4594 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4595 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4596 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4597 | } |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4598 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4599 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4600 | return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4601 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4602 | |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4603 | public InputChannel monitorInput(String inputChannelName) { |
| 4604 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4605 | "monitorInput()")) { |
| 4606 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4607 | } |
| 4608 | return mInputManager.monitorInput(inputChannelName); |
| 4609 | } |
| 4610 | |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 4611 | public void setInputFilter(InputFilter filter) { |
| 4612 | mInputManager.setInputFilter(filter); |
| 4613 | } |
| 4614 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 4615 | public InputDevice getInputDevice(int deviceId) { |
| 4616 | return mInputManager.getInputDevice(deviceId); |
| 4617 | } |
| 4618 | |
| 4619 | public int[] getInputDeviceIds() { |
| 4620 | return mInputManager.getInputDeviceIds(); |
| 4621 | } |
| 4622 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4623 | public void enableScreenAfterBoot() { |
| 4624 | synchronized(mWindowMap) { |
| 4625 | if (mSystemBooted) { |
| 4626 | return; |
| 4627 | } |
| 4628 | mSystemBooted = true; |
| 4629 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4630 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4631 | performEnableScreen(); |
| 4632 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4633 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4634 | public void enableScreenIfNeededLocked() { |
| 4635 | if (mDisplayEnabled) { |
| 4636 | return; |
| 4637 | } |
| 4638 | if (!mSystemBooted) { |
| 4639 | return; |
| 4640 | } |
| 4641 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4642 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4643 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4644 | public void performEnableScreen() { |
| 4645 | synchronized(mWindowMap) { |
| 4646 | if (mDisplayEnabled) { |
| 4647 | return; |
| 4648 | } |
| 4649 | if (!mSystemBooted) { |
| 4650 | return; |
| 4651 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4652 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4653 | // Don't enable the screen until all existing windows |
| 4654 | // have been drawn. |
| 4655 | final int N = mWindows.size(); |
| 4656 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4657 | WindowState w = mWindows.get(i); |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 4658 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4659 | return; |
| 4660 | } |
| 4661 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4662 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4663 | mDisplayEnabled = true; |
| 4664 | if (false) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4665 | Slog.i(TAG, "ENABLING SCREEN!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4666 | StringWriter sw = new StringWriter(); |
| 4667 | PrintWriter pw = new PrintWriter(sw); |
| 4668 | this.dump(null, pw, null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4669 | Slog.i(TAG, sw.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4670 | } |
| 4671 | try { |
| 4672 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4673 | if (surfaceFlinger != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4674 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4675 | Parcel data = Parcel.obtain(); |
| 4676 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4677 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4678 | data, null, 0); |
| 4679 | data.recycle(); |
| 4680 | } |
| 4681 | } catch (RemoteException ex) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4682 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4683 | } |
| 4684 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4685 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4686 | mPolicy.enableScreenAfterBoot(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4687 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4688 | // Make sure the last requested orientation has been applied. |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4689 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4690 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4691 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4692 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4693 | public void setInTouchMode(boolean mode) { |
| 4694 | synchronized(mWindowMap) { |
| 4695 | mInTouchMode = mode; |
| 4696 | } |
| 4697 | } |
| 4698 | |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 4699 | // TODO: more accounting of which pid(s) turned it on, keep count, |
| 4700 | // only allow disables from pids which have count on, etc. |
| 4701 | public void showStrictModeViolation(boolean on) { |
| 4702 | int pid = Binder.getCallingPid(); |
| 4703 | synchronized(mWindowMap) { |
| 4704 | // Ignoring requests to enable the red border from clients |
| 4705 | // which aren't on screen. (e.g. Broadcast Receivers in |
| 4706 | // the background..) |
| 4707 | if (on) { |
| 4708 | boolean isVisible = false; |
| 4709 | for (WindowState ws : mWindows) { |
| 4710 | if (ws.mSession.mPid == pid && ws.isVisibleLw()) { |
| 4711 | isVisible = true; |
| 4712 | break; |
| 4713 | } |
| 4714 | } |
| 4715 | if (!isVisible) { |
| 4716 | return; |
| 4717 | } |
| 4718 | } |
| 4719 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4720 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION showStrictModeViolation"); |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 4721 | Surface.openTransaction(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4722 | try { |
| 4723 | if (mStrictModeFlash == null) { |
| 4724 | mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession); |
| 4725 | } |
| 4726 | mStrictModeFlash.setVisibility(on); |
| 4727 | } finally { |
| 4728 | Surface.closeTransaction(); |
| 4729 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION showStrictModeViolation"); |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 4730 | } |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 4731 | } |
| 4732 | } |
| 4733 | |
Brad Fitzpatrick | c1a968a | 2010-11-24 08:56:40 -0800 | [diff] [blame] | 4734 | public void setStrictModeVisualIndicatorPreference(String value) { |
| 4735 | SystemProperties.set(StrictMode.VISUAL_PROPERTY, value); |
| 4736 | } |
| 4737 | |
Jim Miller | e70d506 | 2011-03-08 21:38:39 -0800 | [diff] [blame] | 4738 | /** |
| 4739 | * Takes a snapshot of the screen. In landscape mode this grabs the whole screen. |
| 4740 | * In portrait mode, it grabs the upper region of the screen based on the vertical dimension |
| 4741 | * of the target image. |
| 4742 | * |
| 4743 | * @param width the width of the target bitmap |
| 4744 | * @param height the height of the target bitmap |
| 4745 | */ |
| 4746 | public Bitmap screenshotApplications(IBinder appToken, int width, int height) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4747 | if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER, |
| 4748 | "screenshotApplications()")) { |
| 4749 | throw new SecurityException("Requires READ_FRAME_BUFFER permission"); |
| 4750 | } |
| 4751 | |
| 4752 | Bitmap rawss; |
| 4753 | |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 4754 | int maxLayer = 0; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4755 | final Rect frame = new Rect(); |
| 4756 | |
| 4757 | float scale; |
Jim Miller | e70d506 | 2011-03-08 21:38:39 -0800 | [diff] [blame] | 4758 | int dw, dh; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4759 | int rot; |
| 4760 | |
| 4761 | synchronized(mWindowMap) { |
| 4762 | long ident = Binder.clearCallingIdentity(); |
| 4763 | |
Dianne Hackborn | aa9d84c | 2011-05-09 19:00:59 -0700 | [diff] [blame] | 4764 | dw = mPolicy.getNonDecorDisplayWidth(mCurDisplayWidth); |
| 4765 | dh = mPolicy.getNonDecorDisplayHeight(mCurDisplayHeight); |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 4766 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4767 | int aboveAppLayer = mPolicy.windowTypeToLayerLw( |
| 4768 | WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER |
| 4769 | + TYPE_LAYER_OFFSET; |
| 4770 | aboveAppLayer += TYPE_LAYER_MULTIPLIER; |
| 4771 | |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 4772 | boolean isImeTarget = mInputMethodTarget != null |
| 4773 | && mInputMethodTarget.mAppToken != null |
| 4774 | && mInputMethodTarget.mAppToken.appToken != null |
| 4775 | && mInputMethodTarget.mAppToken.appToken.asBinder() == appToken; |
| 4776 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4777 | // Figure out the part of the screen that is actually the app. |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 4778 | boolean including = false; |
| 4779 | for (int i=mWindows.size()-1; i>=0; i--) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4780 | WindowState ws = mWindows.get(i); |
| 4781 | if (ws.mSurface == null) { |
| 4782 | continue; |
| 4783 | } |
| 4784 | if (ws.mLayer >= aboveAppLayer) { |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 4785 | continue; |
| 4786 | } |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 4787 | // When we will skip windows: when we are not including |
| 4788 | // ones behind a window we didn't skip, and we are actually |
| 4789 | // taking a screenshot of a specific app. |
| 4790 | if (!including && appToken != null) { |
| 4791 | // Also, we can possibly skip this window if it is not |
| 4792 | // an IME target or the application for the screenshot |
| 4793 | // is not the current IME target. |
| 4794 | if (!ws.mIsImWindow || !isImeTarget) { |
| 4795 | // And finally, this window is of no interest if it |
| 4796 | // is not associated with the screenshot app. |
| 4797 | if (ws.mAppToken == null || ws.mAppToken.token != appToken) { |
| 4798 | continue; |
| 4799 | } |
| 4800 | } |
| 4801 | } |
| 4802 | |
| 4803 | // We keep on including windows until we go past a full-screen |
| 4804 | // window. |
| 4805 | including = !ws.mIsImWindow && !ws.isFullscreen(dw, dh); |
| 4806 | |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 4807 | if (maxLayer < ws.mAnimLayer) { |
| 4808 | maxLayer = ws.mAnimLayer; |
| 4809 | } |
Jim Miller | 2aded18 | 2011-03-08 15:32:42 -0800 | [diff] [blame] | 4810 | |
| 4811 | // Don't include wallpaper in bounds calculation |
| 4812 | if (!ws.mIsWallpaper) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4813 | final Rect wf = ws.mScaledFrame; |
Jim Miller | 2aded18 | 2011-03-08 15:32:42 -0800 | [diff] [blame] | 4814 | final Rect cr = ws.mContentInsets; |
| 4815 | int left = wf.left + cr.left; |
| 4816 | int top = wf.top + cr.top; |
| 4817 | int right = wf.right - cr.right; |
| 4818 | int bottom = wf.bottom - cr.bottom; |
| 4819 | frame.union(left, top, right, bottom); |
| 4820 | } |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4821 | } |
| 4822 | Binder.restoreCallingIdentity(ident); |
| 4823 | |
Dianne Hackborn | dd962ee | 2011-02-02 11:11:50 -0800 | [diff] [blame] | 4824 | // Constrain frame to the screen size. |
| 4825 | frame.intersect(0, 0, dw, dh); |
Jim Miller | e70d506 | 2011-03-08 21:38:39 -0800 | [diff] [blame] | 4826 | |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 4827 | if (frame.isEmpty() || maxLayer == 0) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4828 | return null; |
| 4829 | } |
| 4830 | |
| 4831 | // The screenshot API does not apply the current screen rotation. |
| 4832 | rot = mDisplay.getRotation(); |
| 4833 | int fw = frame.width(); |
| 4834 | int fh = frame.height(); |
| 4835 | |
| 4836 | // First try reducing to fit in x dimension. |
Jim Miller | e70d506 | 2011-03-08 21:38:39 -0800 | [diff] [blame] | 4837 | scale = width/(float)fw; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4838 | |
| 4839 | // The screen shot will contain the entire screen. |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 4840 | dw = (int)(dw*scale); |
| 4841 | dh = (int)(dh*scale); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4842 | if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) { |
| 4843 | int tmp = dw; |
| 4844 | dw = dh; |
| 4845 | dh = tmp; |
| 4846 | rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90; |
| 4847 | } |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 4848 | rawss = Surface.screenshot(dw, dh, 0, maxLayer); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4849 | } |
| 4850 | |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 4851 | if (rawss == null) { |
Dianne Hackborn | 88b03bd | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 4852 | Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh |
| 4853 | + ") to layer " + maxLayer); |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 4854 | return null; |
| 4855 | } |
Jim Miller | e70d506 | 2011-03-08 21:38:39 -0800 | [diff] [blame] | 4856 | |
| 4857 | Bitmap bm = Bitmap.createBitmap(width, height, rawss.getConfig()); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4858 | Matrix matrix = new Matrix(); |
| 4859 | ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix); |
| 4860 | matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale)); |
| 4861 | Canvas canvas = new Canvas(bm); |
| 4862 | canvas.drawBitmap(rawss, matrix, null); |
| 4863 | |
| 4864 | rawss.recycle(); |
| 4865 | return bm; |
| 4866 | } |
| 4867 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4868 | public void freezeRotation() { |
| 4869 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 4870 | "freezeRotation()")) { |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4871 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 4872 | } |
| 4873 | |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 4874 | if (DEBUG_ORIENTATION) Slog.v(TAG, "freezeRotation: mRotation=" + mRotation); |
| 4875 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4876 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation); |
| 4877 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0); |
| 4878 | } |
| 4879 | |
| 4880 | public void thawRotation() { |
| 4881 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 4882 | "thawRotation()")) { |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4883 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 4884 | } |
| 4885 | |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 4886 | if (DEBUG_ORIENTATION) Slog.v(TAG, "thawRotation: mRotation=" + mRotation); |
| 4887 | |
| 4888 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 777); // rot not used |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4889 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0); |
| 4890 | } |
| 4891 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4892 | public void setRotation(int rotation, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4893 | boolean alwaysSendConfiguration, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4894 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4895 | "setRotation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4896 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4897 | } |
| 4898 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4899 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4900 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4901 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4902 | public void setRotationUnchecked(int rotation, |
| 4903 | boolean alwaysSendConfiguration, int animFlags) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4904 | if(DEBUG_ORIENTATION) Slog.v(TAG, |
David 'Digit' Turner | 910a068 | 2011-02-05 00:34:46 +0100 | [diff] [blame] | 4905 | "setRotationUnchecked(rotation=" + rotation + |
| 4906 | " alwaysSendConfiguration=" + alwaysSendConfiguration + |
| 4907 | " animFlags=" + animFlags); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4908 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4909 | long origId = Binder.clearCallingIdentity(); |
| 4910 | boolean changed; |
| 4911 | synchronized(mWindowMap) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4912 | changed = setRotationUncheckedLocked(rotation, animFlags, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4913 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4914 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4915 | if (changed || alwaysSendConfiguration) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4916 | sendNewConfiguration(); |
| 4917 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4918 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4919 | Binder.restoreCallingIdentity(origId); |
| 4920 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4921 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4922 | /** |
| 4923 | * Apply a new rotation to the screen, respecting the requests of |
| 4924 | * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply |
| 4925 | * re-evaluate the desired rotation. |
| 4926 | * |
| 4927 | * Returns null if the rotation has been changed. In this case YOU |
| 4928 | * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN. |
| 4929 | */ |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4930 | public boolean setRotationUncheckedLocked(int rotation, int animFlags, boolean inTransaction) { |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 4931 | if (mDragState != null || mScreenRotationAnimation != null) { |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 4932 | // Potential rotation during a drag. Don't do the rotation now, but make |
| 4933 | // a note to perform the rotation later. |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 4934 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation."); |
| 4935 | if (rotation != WindowManagerPolicy.USE_LAST_ROTATION) { |
| 4936 | mDeferredRotation = rotation; |
| 4937 | mDeferredRotationAnimFlags = animFlags; |
| 4938 | } |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 4939 | return false; |
| 4940 | } |
| 4941 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4942 | boolean changed; |
| 4943 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 4944 | if (mDeferredRotation != WindowManagerPolicy.USE_LAST_ROTATION) { |
| 4945 | rotation = mDeferredRotation; |
| 4946 | mRequestedRotation = rotation; |
| 4947 | mLastRotationFlags = mDeferredRotationAnimFlags; |
| 4948 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4949 | rotation = mRequestedRotation; |
| 4950 | } else { |
| 4951 | mRequestedRotation = rotation; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4952 | mLastRotationFlags = animFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4953 | } |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 4954 | mDeferredRotation = WindowManagerPolicy.USE_LAST_ROTATION; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4955 | 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] | 4956 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4957 | mRotation, mDisplayEnabled); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4958 | if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation); |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 4959 | |
| 4960 | int desiredRotation = rotation; |
| 4961 | int lockedRotation = mPolicy.getLockedRotationLw(); |
| 4962 | if (lockedRotation >= 0 && rotation != lockedRotation) { |
| 4963 | // We are locked in a rotation but something is requesting |
| 4964 | // a different rotation... we will either keep the locked |
| 4965 | // rotation if it results in the same orientation, or have to |
| 4966 | // switch into an emulated orientation mode. |
| 4967 | |
| 4968 | // First, we know that our rotation is actually going to be |
| 4969 | // the locked rotation. |
| 4970 | rotation = lockedRotation; |
| 4971 | |
| 4972 | // Now the difference between the desired and lockedRotation |
| 4973 | // may mean that the orientation is different... if that is |
| 4974 | // not the case, we can just make the desired rotation be the |
| 4975 | // same as the new locked rotation. |
| 4976 | switch (lockedRotation) { |
| 4977 | case Surface.ROTATION_0: |
| 4978 | if (rotation == Surface.ROTATION_180) { |
| 4979 | desiredRotation = lockedRotation; |
| 4980 | } |
| 4981 | break; |
| 4982 | case Surface.ROTATION_90: |
| 4983 | if (rotation == Surface.ROTATION_270) { |
| 4984 | desiredRotation = lockedRotation; |
| 4985 | } |
| 4986 | break; |
| 4987 | case Surface.ROTATION_180: |
| 4988 | if (rotation == Surface.ROTATION_0) { |
| 4989 | desiredRotation = lockedRotation; |
| 4990 | } |
| 4991 | break; |
| 4992 | case Surface.ROTATION_270: |
| 4993 | if (rotation == Surface.ROTATION_90) { |
| 4994 | desiredRotation = lockedRotation; |
| 4995 | } |
| 4996 | break; |
| 4997 | } |
| 4998 | } |
| 4999 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5000 | changed = mDisplayEnabled && mRotation != rotation; |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 5001 | if (mAltOrientation != (rotation != desiredRotation)) { |
| 5002 | changed = true; |
| 5003 | mAltOrientation = rotation != desiredRotation; |
| 5004 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5005 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5006 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5007 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5008 | "Rotation changed to " + rotation |
| 5009 | + " from " + mRotation |
| 5010 | + " (forceApp=" + mForcedAppOrientation |
| 5011 | + ", req=" + mRequestedRotation + ")"); |
| 5012 | mRotation = rotation; |
| 5013 | mWindowsFreezingScreen = true; |
| 5014 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 5015 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 5016 | 2000); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5017 | mWaitingForConfig = true; |
| 5018 | mLayoutNeeded = true; |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5019 | startFreezingDisplayLocked(inTransaction); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5020 | Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5021 | mInputManager.setDisplayOrientation(0, rotation); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5022 | if (mDisplayEnabled) { |
David 'Digit' Turner | 910a068 | 2011-02-05 00:34:46 +0100 | [diff] [blame] | 5023 | // NOTE: We disable the rotation in the emulator because |
| 5024 | // it doesn't support hardware OpenGL emulation yet. |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 5025 | if (CUSTOM_SCREEN_ROTATION && mScreenRotationAnimation != null |
| 5026 | && mScreenRotationAnimation.hasScreenshot()) { |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 5027 | Surface.freezeDisplay(0); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5028 | if (!inTransaction) { |
| 5029 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 5030 | ">>> OPEN TRANSACTION setRotationUnchecked"); |
| 5031 | Surface.openTransaction(); |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 5032 | } |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5033 | try { |
| 5034 | if (mScreenRotationAnimation != null) { |
| 5035 | mScreenRotationAnimation.setRotation(rotation); |
| 5036 | } |
| 5037 | } finally { |
| 5038 | if (!inTransaction) { |
| 5039 | Surface.closeTransaction(); |
| 5040 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 5041 | "<<< CLOSE TRANSACTION setRotationUnchecked"); |
| 5042 | } |
| 5043 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 5044 | Surface.setOrientation(0, rotation, animFlags); |
| 5045 | Surface.unfreezeDisplay(0); |
| 5046 | } else { |
| 5047 | Surface.setOrientation(0, rotation, animFlags); |
| 5048 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5049 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 5050 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5051 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5052 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5053 | if (w.mSurface != null) { |
| 5054 | w.mOrientationChanging = true; |
| 5055 | } |
| 5056 | } |
| 5057 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 5058 | try { |
| 5059 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 5060 | } catch (RemoteException e) { |
| 5061 | } |
| 5062 | } |
| 5063 | } //end if changed |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5064 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5065 | return changed; |
| 5066 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5067 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5068 | public int getRotation() { |
| 5069 | return mRotation; |
| 5070 | } |
| 5071 | |
| 5072 | public int watchRotation(IRotationWatcher watcher) { |
| 5073 | final IBinder watcherBinder = watcher.asBinder(); |
| 5074 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 5075 | public void binderDied() { |
| 5076 | synchronized (mWindowMap) { |
| 5077 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 5078 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 5079 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 5080 | if (removed != null) { |
| 5081 | removed.asBinder().unlinkToDeath(this, 0); |
| 5082 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5083 | i--; |
| 5084 | } |
| 5085 | } |
| 5086 | } |
| 5087 | } |
| 5088 | }; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5089 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5090 | synchronized (mWindowMap) { |
| 5091 | try { |
| 5092 | watcher.asBinder().linkToDeath(dr, 0); |
| 5093 | mRotationWatchers.add(watcher); |
| 5094 | } catch (RemoteException e) { |
| 5095 | // Client died, no cleanup needed. |
| 5096 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5097 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5098 | return mRotation; |
| 5099 | } |
| 5100 | } |
| 5101 | |
| 5102 | /** |
| 5103 | * Starts the view server on the specified port. |
| 5104 | * |
| 5105 | * @param port The port to listener to. |
| 5106 | * |
| 5107 | * @return True if the server was successfully started, false otherwise. |
| 5108 | * |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 5109 | * @see com.android.server.wm.ViewServer |
| 5110 | * @see com.android.server.wm.ViewServer#VIEW_SERVER_DEFAULT_PORT |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5111 | */ |
| 5112 | public boolean startViewServer(int port) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5113 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5114 | return false; |
| 5115 | } |
| 5116 | |
| 5117 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 5118 | return false; |
| 5119 | } |
| 5120 | |
| 5121 | if (port < 1024) { |
| 5122 | return false; |
| 5123 | } |
| 5124 | |
| 5125 | if (mViewServer != null) { |
| 5126 | if (!mViewServer.isRunning()) { |
| 5127 | try { |
| 5128 | return mViewServer.start(); |
| 5129 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5130 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5131 | } |
| 5132 | } |
| 5133 | return false; |
| 5134 | } |
| 5135 | |
| 5136 | try { |
| 5137 | mViewServer = new ViewServer(this, port); |
| 5138 | return mViewServer.start(); |
| 5139 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5140 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5141 | } |
| 5142 | return false; |
| 5143 | } |
| 5144 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5145 | private boolean isSystemSecure() { |
| 5146 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 5147 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 5148 | } |
| 5149 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5150 | /** |
| 5151 | * Stops the view server if it exists. |
| 5152 | * |
| 5153 | * @return True if the server stopped, false if it wasn't started or |
| 5154 | * couldn't be stopped. |
| 5155 | * |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 5156 | * @see com.android.server.wm.ViewServer |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5157 | */ |
| 5158 | public boolean stopViewServer() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5159 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5160 | return false; |
| 5161 | } |
| 5162 | |
| 5163 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 5164 | return false; |
| 5165 | } |
| 5166 | |
| 5167 | if (mViewServer != null) { |
| 5168 | return mViewServer.stop(); |
| 5169 | } |
| 5170 | return false; |
| 5171 | } |
| 5172 | |
| 5173 | /** |
| 5174 | * Indicates whether the view server is running. |
| 5175 | * |
| 5176 | * @return True if the server is running, false otherwise. |
| 5177 | * |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 5178 | * @see com.android.server.wm.ViewServer |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5179 | */ |
| 5180 | public boolean isViewServerRunning() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5181 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5182 | return false; |
| 5183 | } |
| 5184 | |
| 5185 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 5186 | return false; |
| 5187 | } |
| 5188 | |
| 5189 | return mViewServer != null && mViewServer.isRunning(); |
| 5190 | } |
| 5191 | |
| 5192 | /** |
| 5193 | * Lists all availble windows in the system. The listing is written in the |
| 5194 | * specified Socket's output stream with the following syntax: |
| 5195 | * windowHashCodeInHexadecimal windowName |
| 5196 | * Each line of the ouput represents a different window. |
| 5197 | * |
| 5198 | * @param client The remote client to send the listing to. |
| 5199 | * @return False if an error occured, true otherwise. |
| 5200 | */ |
| 5201 | boolean viewServerListWindows(Socket client) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5202 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5203 | return false; |
| 5204 | } |
| 5205 | |
| 5206 | boolean result = true; |
| 5207 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5208 | WindowState[] windows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5209 | synchronized (mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5210 | //noinspection unchecked |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5211 | windows = mWindows.toArray(new WindowState[mWindows.size()]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5212 | } |
| 5213 | |
| 5214 | BufferedWriter out = null; |
| 5215 | |
| 5216 | // Any uncaught exception will crash the system process |
| 5217 | try { |
| 5218 | OutputStream clientStream = client.getOutputStream(); |
| 5219 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5220 | |
| 5221 | final int count = windows.length; |
| 5222 | for (int i = 0; i < count; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5223 | final WindowState w = windows[i]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5224 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 5225 | out.write(' '); |
| 5226 | out.append(w.mAttrs.getTitle()); |
| 5227 | out.write('\n'); |
| 5228 | } |
| 5229 | |
| 5230 | out.write("DONE.\n"); |
| 5231 | out.flush(); |
| 5232 | } catch (Exception e) { |
| 5233 | result = false; |
| 5234 | } finally { |
| 5235 | if (out != null) { |
| 5236 | try { |
| 5237 | out.close(); |
| 5238 | } catch (IOException e) { |
| 5239 | result = false; |
| 5240 | } |
| 5241 | } |
| 5242 | } |
| 5243 | |
| 5244 | return result; |
| 5245 | } |
| 5246 | |
| 5247 | /** |
Konstantin Lopyrev | f962476 | 2010-07-14 17:02:37 -0700 | [diff] [blame] | 5248 | * Returns the focused window in the following format: |
| 5249 | * windowHashCodeInHexadecimal windowName |
| 5250 | * |
| 5251 | * @param client The remote client to send the listing to. |
| 5252 | * @return False if an error occurred, true otherwise. |
| 5253 | */ |
| 5254 | boolean viewServerGetFocusedWindow(Socket client) { |
| 5255 | if (isSystemSecure()) { |
| 5256 | return false; |
| 5257 | } |
| 5258 | |
| 5259 | boolean result = true; |
| 5260 | |
| 5261 | WindowState focusedWindow = getFocusedWindow(); |
| 5262 | |
| 5263 | BufferedWriter out = null; |
| 5264 | |
| 5265 | // Any uncaught exception will crash the system process |
| 5266 | try { |
| 5267 | OutputStream clientStream = client.getOutputStream(); |
| 5268 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5269 | |
| 5270 | if(focusedWindow != null) { |
| 5271 | out.write(Integer.toHexString(System.identityHashCode(focusedWindow))); |
| 5272 | out.write(' '); |
| 5273 | out.append(focusedWindow.mAttrs.getTitle()); |
| 5274 | } |
| 5275 | out.write('\n'); |
| 5276 | out.flush(); |
| 5277 | } catch (Exception e) { |
| 5278 | result = false; |
| 5279 | } finally { |
| 5280 | if (out != null) { |
| 5281 | try { |
| 5282 | out.close(); |
| 5283 | } catch (IOException e) { |
| 5284 | result = false; |
| 5285 | } |
| 5286 | } |
| 5287 | } |
| 5288 | |
| 5289 | return result; |
| 5290 | } |
| 5291 | |
| 5292 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5293 | * Sends a command to a target window. The result of the command, if any, will be |
| 5294 | * written in the output stream of the specified socket. |
| 5295 | * |
| 5296 | * The parameters must follow this syntax: |
| 5297 | * windowHashcode extra |
| 5298 | * |
| 5299 | * Where XX is the length in characeters of the windowTitle. |
| 5300 | * |
| 5301 | * The first parameter is the target window. The window with the specified hashcode |
| 5302 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 5303 | * will be delivered to the target window and as parameters to the command itself. |
| 5304 | * |
| 5305 | * @param client The remote client to sent the result, if any, to. |
| 5306 | * @param command The command to execute. |
| 5307 | * @param parameters The command parameters. |
| 5308 | * |
| 5309 | * @return True if the command was successfully delivered, false otherwise. This does |
| 5310 | * not indicate whether the command itself was successful. |
| 5311 | */ |
| 5312 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5313 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5314 | return false; |
| 5315 | } |
| 5316 | |
| 5317 | boolean success = true; |
| 5318 | Parcel data = null; |
| 5319 | Parcel reply = null; |
| 5320 | |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5321 | BufferedWriter out = null; |
| 5322 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5323 | // Any uncaught exception will crash the system process |
| 5324 | try { |
| 5325 | // Find the hashcode of the window |
| 5326 | int index = parameters.indexOf(' '); |
| 5327 | if (index == -1) { |
| 5328 | index = parameters.length(); |
| 5329 | } |
| 5330 | final String code = parameters.substring(0, index); |
Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 5331 | int hashCode = (int) Long.parseLong(code, 16); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5332 | |
| 5333 | // Extract the command's parameter after the window description |
| 5334 | if (index < parameters.length()) { |
| 5335 | parameters = parameters.substring(index + 1); |
| 5336 | } else { |
| 5337 | parameters = ""; |
| 5338 | } |
| 5339 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 5340 | final WindowState window = findWindow(hashCode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5341 | if (window == null) { |
| 5342 | return false; |
| 5343 | } |
| 5344 | |
| 5345 | data = Parcel.obtain(); |
| 5346 | data.writeInterfaceToken("android.view.IWindow"); |
| 5347 | data.writeString(command); |
| 5348 | data.writeString(parameters); |
| 5349 | data.writeInt(1); |
| 5350 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 5351 | |
| 5352 | reply = Parcel.obtain(); |
| 5353 | |
| 5354 | final IBinder binder = window.mClient.asBinder(); |
| 5355 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 5356 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 5357 | |
| 5358 | reply.readException(); |
| 5359 | |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5360 | if (!client.isOutputShutdown()) { |
| 5361 | out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream())); |
| 5362 | out.write("DONE\n"); |
| 5363 | out.flush(); |
| 5364 | } |
| 5365 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5366 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5367 | 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] | 5368 | success = false; |
| 5369 | } finally { |
| 5370 | if (data != null) { |
| 5371 | data.recycle(); |
| 5372 | } |
| 5373 | if (reply != null) { |
| 5374 | reply.recycle(); |
| 5375 | } |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5376 | if (out != null) { |
| 5377 | try { |
| 5378 | out.close(); |
| 5379 | } catch (IOException e) { |
| 5380 | |
| 5381 | } |
| 5382 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5383 | } |
| 5384 | |
| 5385 | return success; |
| 5386 | } |
| 5387 | |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 5388 | public void addWindowChangeListener(WindowChangeListener listener) { |
| 5389 | synchronized(mWindowMap) { |
| 5390 | mWindowChangeListeners.add(listener); |
| 5391 | } |
| 5392 | } |
| 5393 | |
| 5394 | public void removeWindowChangeListener(WindowChangeListener listener) { |
| 5395 | synchronized(mWindowMap) { |
| 5396 | mWindowChangeListeners.remove(listener); |
| 5397 | } |
| 5398 | } |
| 5399 | |
| 5400 | private void notifyWindowsChanged() { |
| 5401 | WindowChangeListener[] windowChangeListeners; |
| 5402 | synchronized(mWindowMap) { |
| 5403 | if(mWindowChangeListeners.isEmpty()) { |
| 5404 | return; |
| 5405 | } |
| 5406 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5407 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5408 | } |
| 5409 | int N = windowChangeListeners.length; |
| 5410 | for(int i = 0; i < N; i++) { |
| 5411 | windowChangeListeners[i].windowsChanged(); |
| 5412 | } |
| 5413 | } |
| 5414 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 5415 | private void notifyFocusChanged() { |
| 5416 | WindowChangeListener[] windowChangeListeners; |
| 5417 | synchronized(mWindowMap) { |
| 5418 | if(mWindowChangeListeners.isEmpty()) { |
| 5419 | return; |
| 5420 | } |
| 5421 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5422 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5423 | } |
| 5424 | int N = windowChangeListeners.length; |
| 5425 | for(int i = 0; i < N; i++) { |
| 5426 | windowChangeListeners[i].focusChanged(); |
| 5427 | } |
| 5428 | } |
| 5429 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5430 | private WindowState findWindow(int hashCode) { |
| 5431 | if (hashCode == -1) { |
| 5432 | return getFocusedWindow(); |
| 5433 | } |
| 5434 | |
| 5435 | synchronized (mWindowMap) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5436 | final ArrayList<WindowState> windows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5437 | final int count = windows.size(); |
| 5438 | |
| 5439 | for (int i = 0; i < count; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5440 | WindowState w = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5441 | if (System.identityHashCode(w) == hashCode) { |
| 5442 | return w; |
| 5443 | } |
| 5444 | } |
| 5445 | } |
| 5446 | |
| 5447 | return null; |
| 5448 | } |
| 5449 | |
| 5450 | /* |
| 5451 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 5452 | * that to config-changed listeners if appropriate. |
| 5453 | */ |
| 5454 | void sendNewConfiguration() { |
| 5455 | try { |
| 5456 | mActivityManager.updateConfiguration(null); |
| 5457 | } catch (RemoteException e) { |
| 5458 | } |
| 5459 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5460 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5461 | public Configuration computeNewConfiguration() { |
| 5462 | synchronized (mWindowMap) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5463 | Configuration config = computeNewConfigurationLocked(); |
| 5464 | if (config == null && mWaitingForConfig) { |
| 5465 | // Nothing changed but we are waiting for something... stop that! |
| 5466 | mWaitingForConfig = false; |
| 5467 | performLayoutAndPlaceSurfacesLocked(); |
| 5468 | } |
| 5469 | return config; |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5470 | } |
| 5471 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5472 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5473 | Configuration computeNewConfigurationLocked() { |
| 5474 | Configuration config = new Configuration(); |
| 5475 | if (!computeNewConfigurationLocked(config)) { |
| 5476 | return null; |
| 5477 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5478 | return config; |
| 5479 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5480 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5481 | boolean computeNewConfigurationLocked(Configuration config) { |
| 5482 | if (mDisplay == null) { |
| 5483 | return false; |
| 5484 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5485 | |
| 5486 | mInputManager.getInputConfiguration(config); |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 5487 | |
| 5488 | // Use the effective "visual" dimensions based on current rotation |
| 5489 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 5490 | || mRotation == Surface.ROTATION_270); |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 5491 | final int realdw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; |
| 5492 | final int realdh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; |
| 5493 | |
| 5494 | if (mAltOrientation) { |
| 5495 | mCurDisplayWidth = realdw; |
| 5496 | mCurDisplayHeight = realdh; |
| 5497 | if (realdw > realdh) { |
| 5498 | // Turn landscape into portrait. |
| 5499 | int maxw = (int)(realdh/1.3f); |
| 5500 | if (maxw < realdw) { |
| 5501 | mCurDisplayWidth = maxw; |
| 5502 | } |
| 5503 | } else { |
| 5504 | // Turn portrait into landscape. |
| 5505 | int maxh = (int)(realdw/1.3f); |
| 5506 | if (maxh < realdh) { |
| 5507 | mCurDisplayHeight = maxh; |
| 5508 | } |
| 5509 | } |
| 5510 | } else { |
| 5511 | mCurDisplayWidth = realdw; |
| 5512 | mCurDisplayHeight = realdh; |
| 5513 | } |
| 5514 | |
| 5515 | final int dw = mCurDisplayWidth; |
| 5516 | final int dh = mCurDisplayHeight; |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 5517 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5518 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 5519 | if (dw < dh) { |
| 5520 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 5521 | } else if (dw > dh) { |
| 5522 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 5523 | } |
| 5524 | config.orientation = orientation; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5525 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5526 | DisplayMetrics dm = new DisplayMetrics(); |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 5527 | mDisplay.getRealMetrics(dm); |
| 5528 | |
| 5529 | // Override display width and height with what we are computing, |
| 5530 | // to be sure they remain consistent. |
Dianne Hackborn | aa9d84c | 2011-05-09 19:00:59 -0700 | [diff] [blame] | 5531 | dm.widthPixels = mPolicy.getNonDecorDisplayWidth(dw); |
| 5532 | dm.heightPixels = mPolicy.getNonDecorDisplayHeight(dh); |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 5533 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 5534 | mCompatibleScreenScale = CompatibilityInfo.updateCompatibleScreenFrame( |
| 5535 | dm, mCompatibleScreenFrame, null); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5536 | |
Dianne Hackborn | 3fc982f | 2011-03-30 16:20:26 -0700 | [diff] [blame] | 5537 | config.screenWidthDp = (int)(dm.widthPixels / dm.density); |
| 5538 | config.screenHeightDp = (int)(dm.heightPixels / dm.density); |
| 5539 | |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 5540 | // Compute the screen layout size class. |
| 5541 | int screenLayout; |
| 5542 | int longSize = dw; |
| 5543 | int shortSize = dh; |
| 5544 | if (longSize < shortSize) { |
| 5545 | int tmp = longSize; |
| 5546 | longSize = shortSize; |
| 5547 | shortSize = tmp; |
| 5548 | } |
| 5549 | longSize = (int)(longSize/dm.density); |
| 5550 | shortSize = (int)(shortSize/dm.density); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5551 | |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 5552 | // These semi-magic numbers define our compatibility modes for |
| 5553 | // applications with different screens. These are guarantees to |
| 5554 | // app developers about the space they can expect for a particular |
| 5555 | // configuration. DO NOT CHANGE! |
| 5556 | if (longSize < 470) { |
| 5557 | // This is shorter than an HVGA normal density screen (which |
| 5558 | // is 480 pixels on its long side). |
| 5559 | screenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 5560 | | Configuration.SCREENLAYOUT_LONG_NO; |
| 5561 | } else { |
| 5562 | // What size is this screen screen? |
| 5563 | if (longSize >= 960 && shortSize >= 720) { |
| 5564 | // 1.5xVGA or larger screens at medium density are the point |
| 5565 | // at which we consider it to be an extra large screen. |
| 5566 | screenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE; |
| 5567 | } else if (longSize >= 640 && shortSize >= 480) { |
| 5568 | // VGA or larger screens at medium density are the point |
| 5569 | // at which we consider it to be a large screen. |
| 5570 | screenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5571 | } else { |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 5572 | screenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
| 5573 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5574 | |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 5575 | // If this screen is wider than normal HVGA, or taller |
| 5576 | // than FWVGA, then for old apps we want to run in size |
| 5577 | // compatibility mode. |
| 5578 | if (shortSize > 321 || longSize > 570) { |
| 5579 | screenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 5580 | } |
| 5581 | |
| 5582 | // Is this a long screen? |
| 5583 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 5584 | // Anything wider than WVGA (5:3) is considering to be long. |
| 5585 | screenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 5586 | } else { |
| 5587 | screenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5588 | } |
| 5589 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 5590 | config.screenLayout = screenLayout; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5591 | |
Jeff Brown | 597eec8 | 2011-01-31 17:12:25 -0800 | [diff] [blame] | 5592 | // Determine whether a hard keyboard is available and enabled. |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 5593 | boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS; |
| 5594 | if (hardKeyboardAvailable != mHardKeyboardAvailable) { |
| 5595 | mHardKeyboardAvailable = hardKeyboardAvailable; |
| 5596 | mHardKeyboardEnabled = hardKeyboardAvailable; |
| 5597 | |
| 5598 | mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
| 5599 | mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
| 5600 | } |
| 5601 | if (!mHardKeyboardEnabled) { |
| 5602 | config.keyboard = Configuration.KEYBOARD_NOKEYS; |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 5603 | } |
Jeff Brown | 597eec8 | 2011-01-31 17:12:25 -0800 | [diff] [blame] | 5604 | |
| 5605 | // Update value of keyboardHidden, hardKeyboardHidden and navigationHidden |
| 5606 | // based on whether a hard or soft keyboard is present, whether navigation keys |
| 5607 | // are present and the lid switch state. |
| 5608 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 5609 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 5610 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO; |
| 5611 | mPolicy.adjustConfigurationLw(config); |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5612 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5613 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5614 | |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 5615 | public boolean isHardKeyboardAvailable() { |
| 5616 | synchronized (mWindowMap) { |
| 5617 | return mHardKeyboardAvailable; |
| 5618 | } |
| 5619 | } |
| 5620 | |
| 5621 | public boolean isHardKeyboardEnabled() { |
| 5622 | synchronized (mWindowMap) { |
| 5623 | return mHardKeyboardEnabled; |
| 5624 | } |
| 5625 | } |
| 5626 | |
| 5627 | public void setHardKeyboardEnabled(boolean enabled) { |
| 5628 | synchronized (mWindowMap) { |
| 5629 | if (mHardKeyboardEnabled != enabled) { |
| 5630 | mHardKeyboardEnabled = enabled; |
| 5631 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 5632 | } |
| 5633 | } |
| 5634 | } |
| 5635 | |
| 5636 | public void setOnHardKeyboardStatusChangeListener( |
| 5637 | OnHardKeyboardStatusChangeListener listener) { |
| 5638 | synchronized (mWindowMap) { |
| 5639 | mHardKeyboardStatusChangeListener = listener; |
| 5640 | } |
| 5641 | } |
| 5642 | |
| 5643 | void notifyHardKeyboardStatusChange() { |
| 5644 | final boolean available, enabled; |
| 5645 | final OnHardKeyboardStatusChangeListener listener; |
| 5646 | synchronized (mWindowMap) { |
| 5647 | listener = mHardKeyboardStatusChangeListener; |
| 5648 | available = mHardKeyboardAvailable; |
| 5649 | enabled = mHardKeyboardEnabled; |
| 5650 | } |
| 5651 | if (listener != null) { |
| 5652 | listener.onHardKeyboardStatusChange(available, enabled); |
| 5653 | } |
| 5654 | } |
| 5655 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5656 | // ------------------------------------------------------------- |
| 5657 | // Drag and drop |
| 5658 | // ------------------------------------------------------------- |
| 5659 | |
| 5660 | IBinder prepareDragSurface(IWindow window, SurfaceSession session, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 5661 | int flags, int width, int height, Surface outSurface) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5662 | if (DEBUG_DRAG) { |
| 5663 | Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 5664 | + " flags=" + Integer.toHexString(flags) + " win=" + window |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5665 | + " asbinder=" + window.asBinder()); |
| 5666 | } |
| 5667 | |
| 5668 | final int callerPid = Binder.getCallingPid(); |
| 5669 | final long origId = Binder.clearCallingIdentity(); |
| 5670 | IBinder token = null; |
| 5671 | |
| 5672 | try { |
| 5673 | synchronized (mWindowMap) { |
| 5674 | try { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5675 | if (mDragState == null) { |
| 5676 | Surface surface = new Surface(session, callerPid, "drag surface", 0, |
| 5677 | width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN); |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 5678 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DRAG " |
| 5679 | + surface + ": CREATE"); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5680 | outSurface.copyFrom(surface); |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 5681 | final IBinder winBinder = window.asBinder(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5682 | token = new Binder(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 5683 | mDragState = new DragState(this, token, surface, /*flags*/ 0, winBinder); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5684 | mDragState.mSurface = surface; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5685 | token = mDragState.mToken = new Binder(); |
| 5686 | |
| 5687 | // 5 second timeout for this window to actually begin the drag |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 5688 | mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder); |
| 5689 | Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5690 | mH.sendMessageDelayed(msg, 5000); |
| 5691 | } else { |
| 5692 | Slog.w(TAG, "Drag already in progress"); |
| 5693 | } |
| 5694 | } catch (Surface.OutOfResourcesException e) { |
| 5695 | Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e); |
| 5696 | if (mDragState != null) { |
| 5697 | mDragState.reset(); |
| 5698 | mDragState = null; |
| 5699 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5700 | } |
| 5701 | } |
| 5702 | } finally { |
| 5703 | Binder.restoreCallingIdentity(origId); |
| 5704 | } |
| 5705 | |
| 5706 | return token; |
| 5707 | } |
| 5708 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5709 | // ------------------------------------------------------------- |
| 5710 | // Input Events and Focus Management |
| 5711 | // ------------------------------------------------------------- |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5712 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 5713 | final InputMonitor mInputMonitor = new InputMonitor(this); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5714 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5715 | public void pauseKeyDispatching(IBinder _token) { |
| 5716 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5717 | "pauseKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5718 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5719 | } |
| 5720 | |
| 5721 | synchronized (mWindowMap) { |
| 5722 | WindowToken token = mTokenMap.get(_token); |
| 5723 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5724 | mInputMonitor.pauseDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5725 | } |
| 5726 | } |
| 5727 | } |
| 5728 | |
| 5729 | public void resumeKeyDispatching(IBinder _token) { |
| 5730 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5731 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5732 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5733 | } |
| 5734 | |
| 5735 | synchronized (mWindowMap) { |
| 5736 | WindowToken token = mTokenMap.get(_token); |
| 5737 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5738 | mInputMonitor.resumeDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5739 | } |
| 5740 | } |
| 5741 | } |
| 5742 | |
| 5743 | public void setEventDispatching(boolean enabled) { |
| 5744 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5745 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5746 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5747 | } |
| 5748 | |
| 5749 | synchronized (mWindowMap) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5750 | mInputMonitor.setEventDispatchingLw(enabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5751 | } |
| 5752 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5753 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5754 | /** |
| 5755 | * Injects a keystroke event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5756 | * Even when sync is false, this method may block while waiting for current |
| 5757 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5758 | * |
| 5759 | * @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] | 5760 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5761 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5762 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5763 | */ |
| 5764 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 5765 | long downTime = ev.getDownTime(); |
| 5766 | long eventTime = ev.getEventTime(); |
| 5767 | |
| 5768 | int action = ev.getAction(); |
| 5769 | int code = ev.getKeyCode(); |
| 5770 | int repeatCount = ev.getRepeatCount(); |
| 5771 | int metaState = ev.getMetaState(); |
| 5772 | int deviceId = ev.getDeviceId(); |
| 5773 | int scancode = ev.getScanCode(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5774 | int source = ev.getSource(); |
Mike Playle | c6ded10 | 2010-11-29 16:01:03 +0000 | [diff] [blame] | 5775 | int flags = ev.getFlags(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5776 | |
| 5777 | if (source == InputDevice.SOURCE_UNKNOWN) { |
| 5778 | source = InputDevice.SOURCE_KEYBOARD; |
| 5779 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5780 | |
| 5781 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 5782 | if (downTime == 0) downTime = eventTime; |
| 5783 | |
| 5784 | KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, |
Jean-Baptiste Queru | 4a88013 | 2010-12-02 15:16:53 -0800 | [diff] [blame] | 5785 | deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5786 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5787 | final int pid = Binder.getCallingPid(); |
| 5788 | final int uid = Binder.getCallingUid(); |
| 5789 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5790 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5791 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5792 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5793 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5794 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5795 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5796 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5797 | return reportInjectionResult(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5798 | } |
| 5799 | |
| 5800 | /** |
| 5801 | * Inject a pointer (touch) event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5802 | * Even when sync is false, this method may block while waiting for current |
| 5803 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5804 | * |
| 5805 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 5806 | * {@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] | 5807 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5808 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5809 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5810 | */ |
| 5811 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5812 | final int pid = Binder.getCallingPid(); |
| 5813 | final int uid = Binder.getCallingUid(); |
| 5814 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5815 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5816 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5817 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) { |
| 5818 | newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 5819 | } |
| 5820 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5821 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5822 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5823 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5824 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5825 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5826 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5827 | return reportInjectionResult(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5828 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5829 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5830 | /** |
| 5831 | * Inject a trackball (navigation device) event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5832 | * Even when sync is false, this method may block while waiting for current |
| 5833 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5834 | * |
| 5835 | * @param ev A motion event describing the trackball action. (As noted in |
| 5836 | * {@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] | 5837 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5838 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5839 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5840 | */ |
| 5841 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5842 | final int pid = Binder.getCallingPid(); |
| 5843 | final int uid = Binder.getCallingUid(); |
| 5844 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5845 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5846 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5847 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) { |
| 5848 | newEvent.setSource(InputDevice.SOURCE_TRACKBALL); |
| 5849 | } |
| 5850 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5851 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5852 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5853 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5854 | INJECTION_TIMEOUT_MILLIS); |
| 5855 | |
| 5856 | Binder.restoreCallingIdentity(ident); |
| 5857 | return reportInjectionResult(result); |
| 5858 | } |
| 5859 | |
| 5860 | /** |
| 5861 | * Inject an input event into the UI without waiting for dispatch to commence. |
| 5862 | * This variant is useful for fire-and-forget input event injection. It does not |
| 5863 | * block any longer than it takes to enqueue the input event. |
| 5864 | * |
| 5865 | * @param ev An input event. (Be sure to set the input source correctly.) |
| 5866 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5867 | */ |
| 5868 | public boolean injectInputEventNoWait(InputEvent ev) { |
| 5869 | final int pid = Binder.getCallingPid(); |
| 5870 | final int uid = Binder.getCallingUid(); |
| 5871 | final long ident = Binder.clearCallingIdentity(); |
| 5872 | |
| 5873 | final int result = mInputManager.injectInputEvent(ev, pid, uid, |
| 5874 | InputManager.INPUT_EVENT_INJECTION_SYNC_NONE, |
| 5875 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5876 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5877 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5878 | return reportInjectionResult(result); |
| 5879 | } |
| 5880 | |
| 5881 | private boolean reportInjectionResult(int result) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5882 | switch (result) { |
| 5883 | case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED: |
| 5884 | Slog.w(TAG, "Input event injection permission denied."); |
| 5885 | throw new SecurityException( |
| 5886 | "Injecting to another application requires INJECT_EVENTS permission"); |
| 5887 | case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED: |
Christopher Tate | 09e85dc | 2010-08-02 11:54:41 -0700 | [diff] [blame] | 5888 | //Slog.v(TAG, "Input event injection succeeded."); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5889 | return true; |
| 5890 | case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT: |
| 5891 | Slog.w(TAG, "Input event injection timed out."); |
| 5892 | return false; |
| 5893 | case InputManager.INPUT_EVENT_INJECTION_FAILED: |
| 5894 | default: |
| 5895 | Slog.w(TAG, "Input event injection failed."); |
| 5896 | return false; |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5897 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5898 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5899 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5900 | private WindowState getFocusedWindow() { |
| 5901 | synchronized (mWindowMap) { |
| 5902 | return getFocusedWindowLocked(); |
| 5903 | } |
| 5904 | } |
| 5905 | |
| 5906 | private WindowState getFocusedWindowLocked() { |
| 5907 | return mCurrentFocus; |
| 5908 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5909 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5910 | public boolean detectSafeMode() { |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 5911 | if (!mInputMonitor.waitForInputDevicesReady( |
| 5912 | INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) { |
| 5913 | Slog.w(TAG, "Devices still not ready after waiting " |
| 5914 | + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS |
| 5915 | + " milliseconds before attempting to detect safe mode."); |
| 5916 | } |
| 5917 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5918 | mSafeMode = mPolicy.detectSafeMode(); |
| 5919 | return mSafeMode; |
| 5920 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5921 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5922 | public void systemReady() { |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 5923 | synchronized(mWindowMap) { |
| 5924 | if (mDisplay != null) { |
| 5925 | throw new IllegalStateException("Display already initialized"); |
| 5926 | } |
| 5927 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 5928 | mDisplay = wm.getDefaultDisplay(); |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 5929 | mInitialDisplayWidth = mCurDisplayWidth = mDisplay.getRealWidth(); |
| 5930 | mInitialDisplayHeight = mCurDisplayHeight = mDisplay.getRealHeight(); |
| 5931 | mInputManager.setDisplaySize(0, mDisplay.getRawWidth(), mDisplay.getRawHeight()); |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 5932 | mPolicy.setInitialDisplaySize(mInitialDisplayWidth, mInitialDisplayHeight); |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 5933 | } |
| 5934 | |
| 5935 | try { |
| 5936 | mActivityManager.updateConfiguration(null); |
| 5937 | } catch (RemoteException e) { |
| 5938 | } |
Dianne Hackborn | 154db5f | 2010-07-29 19:15:19 -0700 | [diff] [blame] | 5939 | |
| 5940 | mPolicy.systemReady(); |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 5941 | } |
| 5942 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5943 | // This is an animation that does nothing: it just immediately finishes |
| 5944 | // itself every time it is called. It is used as a stub animation in cases |
| 5945 | // where we want to synchronize multiple things that may be animating. |
| 5946 | static final class DummyAnimation extends Animation { |
| 5947 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 5948 | return false; |
| 5949 | } |
| 5950 | } |
| 5951 | static final Animation sDummyAnimation = new DummyAnimation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5952 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5953 | // ------------------------------------------------------------- |
| 5954 | // Async Handler |
| 5955 | // ------------------------------------------------------------- |
| 5956 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 5957 | final class H extends Handler { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5958 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 5959 | public static final int REPORT_LOSING_FOCUS = 3; |
| 5960 | public static final int ANIMATE = 4; |
| 5961 | public static final int ADD_STARTING = 5; |
| 5962 | public static final int REMOVE_STARTING = 6; |
| 5963 | public static final int FINISHED_STARTING = 7; |
| 5964 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5965 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 5966 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 5967 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 5968 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 5969 | public static final int FORCE_GC = 15; |
| 5970 | public static final int ENABLE_SCREEN = 16; |
| 5971 | public static final int APP_FREEZE_TIMEOUT = 17; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5972 | public static final int SEND_NEW_CONFIGURATION = 18; |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 5973 | public static final int REPORT_WINDOWS_CHANGE = 19; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5974 | public static final int DRAG_START_TIMEOUT = 20; |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5975 | public static final int DRAG_END_TIMEOUT = 21; |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 5976 | public static final int REPORT_HARD_KEYBOARD_STATUS_CHANGE = 22; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5977 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5978 | private Session mLastReportedHold; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5979 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5980 | public H() { |
| 5981 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5982 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5983 | @Override |
| 5984 | public void handleMessage(Message msg) { |
| 5985 | switch (msg.what) { |
| 5986 | case REPORT_FOCUS_CHANGE: { |
| 5987 | WindowState lastFocus; |
| 5988 | WindowState newFocus; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5989 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5990 | synchronized(mWindowMap) { |
| 5991 | lastFocus = mLastFocus; |
| 5992 | newFocus = mCurrentFocus; |
| 5993 | if (lastFocus == newFocus) { |
| 5994 | // Focus is not changing, so nothing to do. |
| 5995 | return; |
| 5996 | } |
| 5997 | mLastFocus = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5998 | //Slog.i(TAG, "Focus moving from " + lastFocus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5999 | // + " to " + newFocus); |
| 6000 | if (newFocus != null && lastFocus != null |
| 6001 | && !newFocus.isDisplayedLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6002 | //Slog.i(TAG, "Delaying loss of focus..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6003 | mLosingFocus.add(lastFocus); |
| 6004 | lastFocus = null; |
| 6005 | } |
| 6006 | } |
| 6007 | |
| 6008 | if (lastFocus != newFocus) { |
| 6009 | //System.out.println("Changing focus from " + lastFocus |
| 6010 | // + " to " + newFocus); |
| 6011 | if (newFocus != null) { |
| 6012 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6013 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6014 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 6015 | } catch (RemoteException e) { |
| 6016 | // Ignore if process has died. |
| 6017 | } |
Konstantin Lopyrev | 5e7833a | 2010-08-09 17:01:11 -0700 | [diff] [blame] | 6018 | notifyFocusChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6019 | } |
| 6020 | |
| 6021 | if (lastFocus != null) { |
| 6022 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6023 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6024 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 6025 | } catch (RemoteException e) { |
| 6026 | // Ignore if process has died. |
| 6027 | } |
| 6028 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6029 | |
| 6030 | mPolicy.focusChanged(lastFocus, newFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6031 | } |
| 6032 | } break; |
| 6033 | |
| 6034 | case REPORT_LOSING_FOCUS: { |
| 6035 | ArrayList<WindowState> losers; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6036 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6037 | synchronized(mWindowMap) { |
| 6038 | losers = mLosingFocus; |
| 6039 | mLosingFocus = new ArrayList<WindowState>(); |
| 6040 | } |
| 6041 | |
| 6042 | final int N = losers.size(); |
| 6043 | for (int i=0; i<N; i++) { |
| 6044 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6045 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6046 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 6047 | } catch (RemoteException e) { |
| 6048 | // Ignore if process has died. |
| 6049 | } |
| 6050 | } |
| 6051 | } break; |
| 6052 | |
| 6053 | case ANIMATE: { |
| 6054 | synchronized(mWindowMap) { |
| 6055 | mAnimationPending = false; |
| 6056 | performLayoutAndPlaceSurfacesLocked(); |
| 6057 | } |
| 6058 | } break; |
| 6059 | |
| 6060 | case ADD_STARTING: { |
| 6061 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 6062 | final StartingData sd = wtoken.startingData; |
| 6063 | |
| 6064 | if (sd == null) { |
| 6065 | // Animation has been canceled... do nothing. |
| 6066 | return; |
| 6067 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6068 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6069 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6070 | + wtoken + ": pkg=" + sd.pkg); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6071 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6072 | View view = null; |
| 6073 | try { |
| 6074 | view = mPolicy.addStartingWindow( |
| 6075 | wtoken.token, sd.pkg, |
| 6076 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 6077 | sd.icon, sd.windowFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6078 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6079 | Slog.w(TAG, "Exception when adding starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6080 | } |
| 6081 | |
| 6082 | if (view != null) { |
| 6083 | boolean abort = false; |
| 6084 | |
| 6085 | synchronized(mWindowMap) { |
| 6086 | if (wtoken.removed || wtoken.startingData == null) { |
| 6087 | // If the window was successfully added, then |
| 6088 | // we need to remove it. |
| 6089 | if (wtoken.startingWindow != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6090 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6091 | "Aborted starting " + wtoken |
| 6092 | + ": removed=" + wtoken.removed |
| 6093 | + " startingData=" + wtoken.startingData); |
| 6094 | wtoken.startingWindow = null; |
| 6095 | wtoken.startingData = null; |
| 6096 | abort = true; |
| 6097 | } |
| 6098 | } else { |
| 6099 | wtoken.startingView = view; |
| 6100 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6101 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6102 | "Added starting " + wtoken |
| 6103 | + ": startingWindow=" |
| 6104 | + wtoken.startingWindow + " startingView=" |
| 6105 | + wtoken.startingView); |
| 6106 | } |
| 6107 | |
| 6108 | if (abort) { |
| 6109 | try { |
| 6110 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 6111 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6112 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6113 | } |
| 6114 | } |
| 6115 | } |
| 6116 | } break; |
| 6117 | |
| 6118 | case REMOVE_STARTING: { |
| 6119 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 6120 | IBinder token = null; |
| 6121 | View view = null; |
| 6122 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6123 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6124 | + wtoken + ": startingWindow=" |
| 6125 | + wtoken.startingWindow + " startingView=" |
| 6126 | + wtoken.startingView); |
| 6127 | if (wtoken.startingWindow != null) { |
| 6128 | view = wtoken.startingView; |
| 6129 | token = wtoken.token; |
| 6130 | wtoken.startingData = null; |
| 6131 | wtoken.startingView = null; |
| 6132 | wtoken.startingWindow = null; |
| 6133 | } |
| 6134 | } |
| 6135 | if (view != null) { |
| 6136 | try { |
| 6137 | mPolicy.removeStartingWindow(token, view); |
| 6138 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6139 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6140 | } |
| 6141 | } |
| 6142 | } break; |
| 6143 | |
| 6144 | case FINISHED_STARTING: { |
| 6145 | IBinder token = null; |
| 6146 | View view = null; |
| 6147 | while (true) { |
| 6148 | synchronized (mWindowMap) { |
| 6149 | final int N = mFinishedStarting.size(); |
| 6150 | if (N <= 0) { |
| 6151 | break; |
| 6152 | } |
| 6153 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 6154 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6155 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6156 | "Finished starting " + wtoken |
| 6157 | + ": startingWindow=" + wtoken.startingWindow |
| 6158 | + " startingView=" + wtoken.startingView); |
| 6159 | |
| 6160 | if (wtoken.startingWindow == null) { |
| 6161 | continue; |
| 6162 | } |
| 6163 | |
| 6164 | view = wtoken.startingView; |
| 6165 | token = wtoken.token; |
| 6166 | wtoken.startingData = null; |
| 6167 | wtoken.startingView = null; |
| 6168 | wtoken.startingWindow = null; |
| 6169 | } |
| 6170 | |
| 6171 | try { |
| 6172 | mPolicy.removeStartingWindow(token, view); |
| 6173 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6174 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6175 | } |
| 6176 | } |
| 6177 | } break; |
| 6178 | |
| 6179 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 6180 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 6181 | |
| 6182 | boolean nowVisible = msg.arg1 != 0; |
| 6183 | boolean nowGone = msg.arg2 != 0; |
| 6184 | |
| 6185 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6186 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6187 | TAG, "Reporting visible in " + wtoken |
| 6188 | + " visible=" + nowVisible |
| 6189 | + " gone=" + nowGone); |
| 6190 | if (nowVisible) { |
| 6191 | wtoken.appToken.windowsVisible(); |
| 6192 | } else { |
| 6193 | wtoken.appToken.windowsGone(); |
| 6194 | } |
| 6195 | } catch (RemoteException ex) { |
| 6196 | } |
| 6197 | } break; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6198 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6199 | case WINDOW_FREEZE_TIMEOUT: { |
| 6200 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6201 | Slog.w(TAG, "Window freeze timeout expired."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6202 | int i = mWindows.size(); |
| 6203 | while (i > 0) { |
| 6204 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6205 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6206 | if (w.mOrientationChanging) { |
| 6207 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6208 | Slog.w(TAG, "Force clearing orientation change: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6209 | } |
| 6210 | } |
| 6211 | performLayoutAndPlaceSurfacesLocked(); |
| 6212 | } |
| 6213 | break; |
| 6214 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6215 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6216 | case HOLD_SCREEN_CHANGED: { |
| 6217 | Session oldHold; |
| 6218 | Session newHold; |
| 6219 | synchronized (mWindowMap) { |
| 6220 | oldHold = mLastReportedHold; |
| 6221 | newHold = (Session)msg.obj; |
| 6222 | mLastReportedHold = newHold; |
| 6223 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6224 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6225 | if (oldHold != newHold) { |
| 6226 | try { |
| 6227 | if (oldHold != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6228 | mBatteryStats.noteStopWakelock(oldHold.mUid, -1, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6229 | "window", |
| 6230 | BatteryStats.WAKE_TYPE_WINDOW); |
| 6231 | } |
| 6232 | if (newHold != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6233 | mBatteryStats.noteStartWakelock(newHold.mUid, -1, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6234 | "window", |
| 6235 | BatteryStats.WAKE_TYPE_WINDOW); |
| 6236 | } |
| 6237 | } catch (RemoteException e) { |
| 6238 | } |
| 6239 | } |
| 6240 | break; |
| 6241 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6242 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6243 | case APP_TRANSITION_TIMEOUT: { |
| 6244 | synchronized (mWindowMap) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 6245 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6246 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6247 | "*** APP TRANSITION TIMEOUT"); |
| 6248 | mAppTransitionReady = true; |
| 6249 | mAppTransitionTimeout = true; |
| 6250 | performLayoutAndPlaceSurfacesLocked(); |
| 6251 | } |
| 6252 | } |
| 6253 | break; |
| 6254 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6255 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6256 | case PERSIST_ANIMATION_SCALE: { |
| 6257 | Settings.System.putFloat(mContext.getContentResolver(), |
| 6258 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 6259 | Settings.System.putFloat(mContext.getContentResolver(), |
| 6260 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 6261 | break; |
| 6262 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6263 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6264 | case FORCE_GC: { |
| 6265 | synchronized(mWindowMap) { |
| 6266 | if (mAnimationPending) { |
| 6267 | // If we are animating, don't do the gc now but |
| 6268 | // delay a bit so we don't interrupt the animation. |
| 6269 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 6270 | 2000); |
| 6271 | return; |
| 6272 | } |
| 6273 | // If we are currently rotating the display, it will |
| 6274 | // schedule a new message when done. |
| 6275 | if (mDisplayFrozen) { |
| 6276 | return; |
| 6277 | } |
| 6278 | mFreezeGcPending = 0; |
| 6279 | } |
| 6280 | Runtime.getRuntime().gc(); |
| 6281 | break; |
| 6282 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6283 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6284 | case ENABLE_SCREEN: { |
| 6285 | performEnableScreen(); |
| 6286 | break; |
| 6287 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6288 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6289 | case APP_FREEZE_TIMEOUT: { |
| 6290 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6291 | Slog.w(TAG, "App freeze timeout expired."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6292 | int i = mAppTokens.size(); |
| 6293 | while (i > 0) { |
| 6294 | i--; |
| 6295 | AppWindowToken tok = mAppTokens.get(i); |
| 6296 | if (tok.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6297 | Slog.w(TAG, "Force clearing freeze: " + tok); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6298 | unsetAppFreezingScreenLocked(tok, true, true); |
| 6299 | } |
| 6300 | } |
| 6301 | } |
| 6302 | break; |
| 6303 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6304 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6305 | case SEND_NEW_CONFIGURATION: { |
| 6306 | removeMessages(SEND_NEW_CONFIGURATION); |
| 6307 | sendNewConfiguration(); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6308 | break; |
| 6309 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6310 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 6311 | case REPORT_WINDOWS_CHANGE: { |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 6312 | if (mWindowsChanged) { |
| 6313 | synchronized (mWindowMap) { |
| 6314 | mWindowsChanged = false; |
| 6315 | } |
| 6316 | notifyWindowsChanged(); |
| 6317 | } |
| 6318 | break; |
| 6319 | } |
| 6320 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6321 | case DRAG_START_TIMEOUT: { |
| 6322 | IBinder win = (IBinder)msg.obj; |
| 6323 | if (DEBUG_DRAG) { |
| 6324 | Slog.w(TAG, "Timeout starting drag by win " + win); |
| 6325 | } |
| 6326 | synchronized (mWindowMap) { |
| 6327 | // !!! TODO: ANR the app that has failed to start the drag in time |
| 6328 | if (mDragState != null) { |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6329 | mDragState.unregister(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 6330 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6331 | mDragState.reset(); |
| 6332 | mDragState = null; |
| 6333 | } |
| 6334 | } |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6335 | break; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6336 | } |
| 6337 | |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6338 | case DRAG_END_TIMEOUT: { |
| 6339 | IBinder win = (IBinder)msg.obj; |
| 6340 | if (DEBUG_DRAG) { |
| 6341 | Slog.w(TAG, "Timeout ending drag to win " + win); |
| 6342 | } |
| 6343 | synchronized (mWindowMap) { |
| 6344 | // !!! TODO: ANR the drag-receiving app |
| 6345 | mDragState.mDragResult = false; |
| 6346 | mDragState.endDragLw(); |
| 6347 | } |
| 6348 | break; |
| 6349 | } |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 6350 | |
| 6351 | case REPORT_HARD_KEYBOARD_STATUS_CHANGE: { |
| 6352 | notifyHardKeyboardStatusChange(); |
| 6353 | break; |
| 6354 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6355 | } |
| 6356 | } |
| 6357 | } |
| 6358 | |
| 6359 | // ------------------------------------------------------------- |
| 6360 | // IWindowManager API |
| 6361 | // ------------------------------------------------------------- |
| 6362 | |
| 6363 | public IWindowSession openSession(IInputMethodClient client, |
| 6364 | IInputContext inputContext) { |
| 6365 | if (client == null) throw new IllegalArgumentException("null client"); |
| 6366 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 6367 | Session session = new Session(this, client, inputContext); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6368 | return session; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6369 | } |
| 6370 | |
| 6371 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 6372 | synchronized (mWindowMap) { |
| 6373 | // The focus for the client is the window immediately below |
| 6374 | // where we would place the input method window. |
| 6375 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 6376 | WindowState imFocus; |
| 6377 | if (idx > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6378 | imFocus = mWindows.get(idx-1); |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 6379 | //Log.i(TAG, "Desired input method target: " + imFocus); |
| 6380 | //Log.i(TAG, "Current focus: " + this.mCurrentFocus); |
| 6381 | //Log.i(TAG, "Last focus: " + this.mLastFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6382 | if (imFocus != null) { |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 6383 | // This may be a starting window, in which case we still want |
| 6384 | // to count it as okay. |
| 6385 | if (imFocus.mAttrs.type == LayoutParams.TYPE_APPLICATION_STARTING |
| 6386 | && imFocus.mAppToken != null) { |
| 6387 | // The client has definitely started, so it really should |
| 6388 | // have a window in this app token. Let's look for it. |
| 6389 | for (int i=0; i<imFocus.mAppToken.windows.size(); i++) { |
| 6390 | WindowState w = imFocus.mAppToken.windows.get(i); |
| 6391 | if (w != imFocus) { |
| 6392 | //Log.i(TAG, "Switching to real app window: " + w); |
| 6393 | imFocus = w; |
| 6394 | break; |
| 6395 | } |
| 6396 | } |
| 6397 | } |
| 6398 | //Log.i(TAG, "IM target client: " + imFocus.mSession.mClient); |
| 6399 | //if (imFocus.mSession.mClient != null) { |
| 6400 | // Log.i(TAG, "IM target client binder: " + imFocus.mSession.mClient.asBinder()); |
| 6401 | // Log.i(TAG, "Requesting client binder: " + client.asBinder()); |
| 6402 | //} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6403 | if (imFocus.mSession.mClient != null && |
| 6404 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 6405 | return true; |
| 6406 | } |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 6407 | |
| 6408 | // Okay, how about this... what is the current focus? |
| 6409 | // It seems in some cases we may not have moved the IM |
| 6410 | // target window, such as when it was in a pop-up window, |
| 6411 | // so let's also look at the current focus. (An example: |
| 6412 | // go to Gmail, start searching so the keyboard goes up, |
| 6413 | // press home. Sometimes the IME won't go down.) |
| 6414 | // Would be nice to fix this more correctly, but it's |
| 6415 | // way at the end of a release, and this should be good enough. |
| 6416 | if (mCurrentFocus != null && mCurrentFocus.mSession.mClient != null && |
| 6417 | mCurrentFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 6418 | return true; |
| 6419 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6420 | } |
| 6421 | } |
| 6422 | } |
| 6423 | return false; |
| 6424 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6425 | |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 6426 | public void getDisplaySize(Point size) { |
| 6427 | synchronized(mWindowMap) { |
| 6428 | size.x = mCurDisplayWidth; |
| 6429 | size.y = mCurDisplayHeight; |
| 6430 | } |
| 6431 | } |
| 6432 | |
| 6433 | public int getMaximumSizeDimension() { |
| 6434 | synchronized(mWindowMap) { |
| 6435 | // Do this based on the raw screen size, until we are smarter. |
| 6436 | return mInitialDisplayWidth > mInitialDisplayHeight |
| 6437 | ? mInitialDisplayWidth : mInitialDisplayHeight; |
| 6438 | } |
| 6439 | } |
| 6440 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6441 | // ------------------------------------------------------------- |
| 6442 | // Internals |
| 6443 | // ------------------------------------------------------------- |
| 6444 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6445 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 6446 | boolean throwOnError) { |
| 6447 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6448 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6449 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6450 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 6451 | boolean throwOnError) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6452 | WindowState win = mWindowMap.get(client); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6453 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6454 | TAG, "Looking up client " + client + ": " + win); |
| 6455 | if (win == null) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6456 | RuntimeException ex = new IllegalArgumentException( |
| 6457 | "Requested window " + client + " does not exist"); |
| 6458 | if (throwOnError) { |
| 6459 | throw ex; |
| 6460 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6461 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6462 | return null; |
| 6463 | } |
| 6464 | if (session != null && win.mSession != session) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6465 | RuntimeException ex = new IllegalArgumentException( |
| 6466 | "Requested window " + client + " is in session " + |
| 6467 | win.mSession + ", not " + session); |
| 6468 | if (throwOnError) { |
| 6469 | throw ex; |
| 6470 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6471 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6472 | return null; |
| 6473 | } |
| 6474 | |
| 6475 | return win; |
| 6476 | } |
| 6477 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6478 | final void rebuildAppWindowListLocked() { |
| 6479 | int NW = mWindows.size(); |
| 6480 | int i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6481 | int lastWallpaper = -1; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 6482 | int numRemoved = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6483 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6484 | if (mRebuildTmp.length < NW) { |
| 6485 | mRebuildTmp = new WindowState[NW+10]; |
| 6486 | } |
| 6487 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6488 | // First remove all existing app windows. |
| 6489 | i=0; |
| 6490 | while (i < NW) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6491 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6492 | if (w.mAppToken != null) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6493 | WindowState win = mWindows.remove(i); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6494 | win.mRebuilding = true; |
| 6495 | mRebuildTmp[numRemoved] = win; |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 6496 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6497 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 6498 | "Rebuild removing window: " + win); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6499 | NW--; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 6500 | numRemoved++; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6501 | continue; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6502 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 6503 | && lastWallpaper == i-1) { |
| 6504 | lastWallpaper = i; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6505 | } |
| 6506 | i++; |
| 6507 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6508 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6509 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 6510 | // so skip them before adding app tokens. |
| 6511 | lastWallpaper++; |
| 6512 | i = lastWallpaper; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6513 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 6514 | // First add all of the exiting app tokens... these are no longer |
| 6515 | // in the main app list, but still have windows shown. We put them |
| 6516 | // in the back because now that the animation is over we no longer |
| 6517 | // will care about them. |
| 6518 | int NT = mExitingAppTokens.size(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6519 | for (int j=0; j<NT; j++) { |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 6520 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 6521 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6522 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 6523 | // And add in the still active app tokens in Z order. |
| 6524 | NT = mAppTokens.size(); |
| 6525 | for (int j=0; j<NT; j++) { |
| 6526 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6527 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6528 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6529 | i -= lastWallpaper; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 6530 | if (i != numRemoved) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6531 | Slog.w(TAG, "Rebuild removed " + numRemoved |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 6532 | + " windows but added " + i); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6533 | for (i=0; i<numRemoved; i++) { |
| 6534 | WindowState ws = mRebuildTmp[i]; |
| 6535 | if (ws.mRebuilding) { |
| 6536 | StringWriter sw = new StringWriter(); |
| 6537 | PrintWriter pw = new PrintWriter(sw); |
| 6538 | ws.dump(pw, ""); |
| 6539 | pw.flush(); |
| 6540 | Slog.w(TAG, "This window was lost: " + ws); |
| 6541 | Slog.w(TAG, sw.toString()); |
| 6542 | } |
| 6543 | } |
| 6544 | Slog.w(TAG, "Current app token list:"); |
| 6545 | dumpAppTokensLocked(); |
| 6546 | Slog.w(TAG, "Final window list:"); |
| 6547 | dumpWindowsLocked(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 6548 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6549 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6550 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6551 | private final void assignLayersLocked() { |
| 6552 | int N = mWindows.size(); |
| 6553 | int curBaseLayer = 0; |
| 6554 | int curLayer = 0; |
| 6555 | int i; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6556 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 6557 | if (DEBUG_LAYERS) { |
| 6558 | RuntimeException here = new RuntimeException("here"); |
| 6559 | here.fillInStackTrace(); |
| 6560 | Log.v(TAG, "Assigning layers", here); |
| 6561 | } |
| 6562 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6563 | for (i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6564 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6565 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 6566 | || (i > 0 && w.mIsWallpaper)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6567 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 6568 | w.mLayer = curLayer; |
| 6569 | } else { |
| 6570 | curBaseLayer = curLayer = w.mBaseLayer; |
| 6571 | w.mLayer = curLayer; |
| 6572 | } |
| 6573 | if (w.mTargetAppToken != null) { |
| 6574 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 6575 | } else if (w.mAppToken != null) { |
| 6576 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 6577 | } else { |
| 6578 | w.mAnimLayer = w.mLayer; |
| 6579 | } |
| 6580 | if (w.mIsImWindow) { |
| 6581 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6582 | } else if (w.mIsWallpaper) { |
| 6583 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6584 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6585 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6586 | + w.mAnimLayer); |
| 6587 | //System.out.println( |
| 6588 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 6589 | } |
| 6590 | } |
| 6591 | |
| 6592 | private boolean mInLayout = false; |
| 6593 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 6594 | if (mInLayout) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 6595 | if (DEBUG) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6596 | throw new RuntimeException("Recursive call!"); |
| 6597 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6598 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6599 | return; |
| 6600 | } |
| 6601 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6602 | if (mWaitingForConfig) { |
| 6603 | // Our configuration has changed (most likely rotation), but we |
| 6604 | // don't yet have the complete configuration to report to |
| 6605 | // applications. Don't do any window layout until we have it. |
| 6606 | return; |
| 6607 | } |
| 6608 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 6609 | if (mDisplay == null) { |
| 6610 | // Not yet initialized, nothing to do. |
| 6611 | return; |
| 6612 | } |
| 6613 | |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 6614 | mInLayout = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6615 | boolean recoveringMemory = false; |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 6616 | |
| 6617 | try { |
| 6618 | if (mForceRemoves != null) { |
| 6619 | recoveringMemory = true; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6620 | // 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] | 6621 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 6622 | WindowState ws = mForceRemoves.get(i); |
| 6623 | Slog.i(TAG, "Force removing: " + ws); |
| 6624 | removeWindowInnerLocked(ws.mSession, ws); |
| 6625 | } |
| 6626 | mForceRemoves = null; |
| 6627 | Slog.w(TAG, "Due to memory failure, waiting a bit for next layout"); |
| 6628 | Object tmp = new Object(); |
| 6629 | synchronized (tmp) { |
| 6630 | try { |
| 6631 | tmp.wait(250); |
| 6632 | } catch (InterruptedException e) { |
| 6633 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6634 | } |
| 6635 | } |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 6636 | } catch (RuntimeException e) { |
| 6637 | 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] | 6638 | } |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 6639 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6640 | try { |
| 6641 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6642 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6643 | int N = mPendingRemove.size(); |
| 6644 | if (N > 0) { |
| 6645 | if (mPendingRemoveTmp.length < N) { |
| 6646 | mPendingRemoveTmp = new WindowState[N+10]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6647 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6648 | mPendingRemove.toArray(mPendingRemoveTmp); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6649 | mPendingRemove.clear(); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6650 | for (int i=0; i<N; i++) { |
| 6651 | WindowState w = mPendingRemoveTmp[i]; |
| 6652 | removeWindowInnerLocked(w.mSession, w); |
| 6653 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6654 | |
| 6655 | mInLayout = false; |
| 6656 | assignLayersLocked(); |
| 6657 | mLayoutNeeded = true; |
| 6658 | performLayoutAndPlaceSurfacesLocked(); |
| 6659 | |
| 6660 | } else { |
| 6661 | mInLayout = false; |
| 6662 | if (mLayoutNeeded) { |
| 6663 | requestAnimationLocked(0); |
| 6664 | } |
| 6665 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 6666 | if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) { |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 6667 | mH.removeMessages(H.REPORT_WINDOWS_CHANGE); |
| 6668 | mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE)); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 6669 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6670 | } catch (RuntimeException e) { |
| 6671 | mInLayout = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6672 | 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] | 6673 | } |
| 6674 | } |
| 6675 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6676 | private final int performLayoutLockedInner(boolean initial, boolean updateInputWindows) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6677 | if (!mLayoutNeeded) { |
| 6678 | return 0; |
| 6679 | } |
| 6680 | |
| 6681 | mLayoutNeeded = false; |
| 6682 | |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 6683 | final int dw = mCurDisplayWidth; |
| 6684 | final int dh = mCurDisplayHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6685 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 6686 | final int innerDw = mPolicy.getNonDecorDisplayWidth(dw); |
| 6687 | final int innerDh = mPolicy.getNonDecorDisplayHeight(dh); |
| 6688 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6689 | final int N = mWindows.size(); |
| 6690 | int i; |
| 6691 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6692 | if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed=" |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 6693 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 6694 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6695 | mPolicy.beginLayoutLw(dw, dh); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6696 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6697 | int seq = mLayoutSeq+1; |
| 6698 | if (seq < 0) seq = 0; |
| 6699 | mLayoutSeq = seq; |
| 6700 | |
| 6701 | // First perform layout of any root windows (not attached |
| 6702 | // to another window). |
| 6703 | int topAttached = -1; |
| 6704 | for (i = N-1; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6705 | WindowState win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6706 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6707 | // Don't do layout of a window if it is not visible, or |
| 6708 | // soon won't be visible, to avoid wasting time and funky |
| 6709 | // changes while a window is animating away. |
| 6710 | final AppWindowToken atoken = win.mAppToken; |
| 6711 | final boolean gone = win.mViewVisibility == View.GONE |
| 6712 | || !win.mRelayoutCalled |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 6713 | || (atoken == null && win.mRootToken.hidden) |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6714 | || (atoken != null && atoken.hiddenRequested) |
| 6715 | || win.mAttachedHidden |
| 6716 | || win.mExiting || win.mDestroying; |
| 6717 | |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 6718 | if (DEBUG_LAYOUT && !win.mLayoutAttached) { |
| 6719 | Slog.v(TAG, "First pass " + win |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6720 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 6721 | + " mLayoutAttached=" + win.mLayoutAttached); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 6722 | if (gone) Slog.v(TAG, " (mViewVisibility=" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6723 | + win.mViewVisibility + " mRelayoutCalled=" |
| 6724 | + win.mRelayoutCalled + " hidden=" |
| 6725 | + win.mRootToken.hidden + " hiddenRequested=" |
| 6726 | + (atoken != null && atoken.hiddenRequested) |
| 6727 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 6728 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6729 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6730 | // If this view is GONE, then skip it -- keep the current |
| 6731 | // frame, and let the caller know so they can ignore it |
| 6732 | // if they want. (We do the normal layout for INVISIBLE |
| 6733 | // windows, since that means "perform layout as normal, |
| 6734 | // just don't display"). |
| 6735 | if (!gone || !win.mHaveFrame) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6736 | if (!win.mLayoutAttached) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6737 | if (initial) { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 6738 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6739 | win.mContentChanged = false; |
| 6740 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 6741 | win.prelayout(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6742 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 6743 | win.evalNeedsBackgroundFiller(innerDw, innerDh); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6744 | win.mLayoutSeq = seq; |
| 6745 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 6746 | + win.mFrame + " mContainingFrame=" |
| 6747 | + win.mContainingFrame + " mDisplayFrame=" |
| 6748 | + win.mDisplayFrame); |
| 6749 | } else { |
| 6750 | if (topAttached < 0) topAttached = i; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 6751 | } |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 6752 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6753 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6754 | |
| 6755 | // Now perform layout of attached windows, which usually |
| 6756 | // depend on the position of the window they are attached to. |
| 6757 | // XXX does not deal with windows that are attached to windows |
| 6758 | // that are themselves attached. |
| 6759 | for (i = topAttached; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6760 | WindowState win = mWindows.get(i); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6761 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6762 | if (win.mLayoutAttached) { |
| 6763 | if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win |
| 6764 | + " mHaveFrame=" + win.mHaveFrame |
| 6765 | + " mViewVisibility=" + win.mViewVisibility |
| 6766 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 6767 | // If this view is GONE, then skip it -- keep the current |
| 6768 | // frame, and let the caller know so they can ignore it |
| 6769 | // if they want. (We do the normal layout for INVISIBLE |
| 6770 | // windows, since that means "perform layout as normal, |
| 6771 | // just don't display"). |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6772 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 6773 | || !win.mHaveFrame) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6774 | if (initial) { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 6775 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6776 | win.mContentChanged = false; |
| 6777 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 6778 | win.prelayout(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6779 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 6780 | win.evalNeedsBackgroundFiller(innerDw, innerDh); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6781 | win.mLayoutSeq = seq; |
| 6782 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 6783 | + win.mFrame + " mContainingFrame=" |
| 6784 | + win.mContainingFrame + " mDisplayFrame=" |
| 6785 | + win.mDisplayFrame); |
| 6786 | } |
| 6787 | } |
| 6788 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6789 | |
| 6790 | // Window frames may have changed. Tell the input dispatcher about it. |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6791 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 6792 | if (updateInputWindows) { |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 6793 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6794 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6795 | |
| 6796 | return mPolicy.finishLayoutLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6797 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6798 | |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 6799 | // "Something has changed! Let's make it correct now." |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6800 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 6801 | boolean recoveringMemory) { |
Joe Onorato | 34bcebc | 2010-07-07 18:05:01 -0400 | [diff] [blame] | 6802 | if (mDisplay == null) { |
| 6803 | Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay"); |
| 6804 | return; |
| 6805 | } |
| 6806 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6807 | final long currentTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 6808 | final int dw = mCurDisplayWidth; |
| 6809 | final int dh = mCurDisplayHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6810 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 6811 | final int innerDw = mPolicy.getNonDecorDisplayWidth(dw); |
| 6812 | final int innerDh = mPolicy.getNonDecorDisplayHeight(dh); |
| 6813 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6814 | int i; |
| 6815 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 6816 | if (mFocusMayChange) { |
| 6817 | mFocusMayChange = false; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6818 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 6819 | false /*updateInputWindows*/); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 6820 | } |
| 6821 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6822 | // Initialize state of exiting tokens. |
| 6823 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 6824 | mExitingTokens.get(i).hasVisible = false; |
| 6825 | } |
| 6826 | |
| 6827 | // Initialize state of exiting applications. |
| 6828 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 6829 | mExitingAppTokens.get(i).hasVisible = false; |
| 6830 | } |
| 6831 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6832 | boolean orientationChangeComplete = true; |
| 6833 | Session holdScreen = null; |
| 6834 | float screenBrightness = -1; |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 6835 | float buttonBrightness = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6836 | boolean focusDisplayed = false; |
| 6837 | boolean animating = false; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 6838 | boolean createWatermark = false; |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 6839 | boolean updateRotation = false; |
Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 6840 | boolean screenRotationFinished = false; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 6841 | |
| 6842 | if (mFxSession == null) { |
| 6843 | mFxSession = new SurfaceSession(); |
| 6844 | createWatermark = true; |
| 6845 | } |
| 6846 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 6847 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6848 | |
| 6849 | Surface.openTransaction(); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 6850 | |
| 6851 | if (createWatermark) { |
| 6852 | createWatermark(); |
| 6853 | } |
| 6854 | if (mWatermark != null) { |
| 6855 | mWatermark.positionSurface(dw, dh); |
| 6856 | } |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 6857 | if (mStrictModeFlash != null) { |
| 6858 | mStrictModeFlash.positionSurface(dw, dh); |
| 6859 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 6860 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6861 | try { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 6862 | boolean wallpaperForceHidingChanged = false; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6863 | int repeats = 0; |
| 6864 | int changes = 0; |
| 6865 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6866 | do { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6867 | repeats++; |
| 6868 | if (repeats > 6) { |
| 6869 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 6870 | mLayoutNeeded = false; |
| 6871 | break; |
| 6872 | } |
| 6873 | |
| 6874 | if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER |
| 6875 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG |
| 6876 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) { |
| 6877 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 6878 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 6879 | assignLayersLocked(); |
| 6880 | mLayoutNeeded = true; |
| 6881 | } |
| 6882 | } |
| 6883 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 6884 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 6885 | if (updateOrientationFromAppTokensLocked(true)) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6886 | mLayoutNeeded = true; |
| 6887 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 6888 | } |
| 6889 | } |
| 6890 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 6891 | mLayoutNeeded = true; |
| 6892 | } |
| 6893 | } |
| 6894 | |
| 6895 | // FIRST LOOP: Perform a layout, if needed. |
| 6896 | if (repeats < 4) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6897 | changes = performLayoutLockedInner(repeats == 0, false /*updateInputWindows*/); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6898 | if (changes != 0) { |
| 6899 | continue; |
| 6900 | } |
| 6901 | } else { |
| 6902 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 6903 | changes = 0; |
| 6904 | } |
| 6905 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6906 | final int transactionSequence = ++mTransactionSequence; |
| 6907 | |
| 6908 | // Update animations of all applications, including those |
| 6909 | // associated with exiting/removed apps |
| 6910 | boolean tokensAnimating = false; |
| 6911 | final int NAT = mAppTokens.size(); |
| 6912 | for (i=0; i<NAT; i++) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 6913 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, |
| 6914 | innerDw, innerDh)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6915 | tokensAnimating = true; |
| 6916 | } |
| 6917 | } |
| 6918 | final int NEAT = mExitingAppTokens.size(); |
| 6919 | for (i=0; i<NEAT; i++) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 6920 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, |
| 6921 | innerDw, innerDh)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6922 | tokensAnimating = true; |
| 6923 | } |
| 6924 | } |
| 6925 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6926 | // SECOND LOOP: Execute animations and update visibility of windows. |
| 6927 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6928 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq=" |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 6929 | + transactionSequence + " tokensAnimating=" |
| 6930 | + tokensAnimating); |
| 6931 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6932 | animating = tokensAnimating; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6933 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 6934 | if (mScreenRotationAnimation != null) { |
| 6935 | if (mScreenRotationAnimation.isAnimating()) { |
| 6936 | if (mScreenRotationAnimation.stepAnimation(currentTime)) { |
| 6937 | animating = true; |
| 6938 | } else { |
Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 6939 | screenRotationFinished = true; |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 6940 | updateRotation = true; |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 6941 | } |
| 6942 | } |
| 6943 | } |
| 6944 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6945 | boolean tokenMayBeDrawn = false; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6946 | boolean wallpaperMayChange = false; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6947 | boolean forceHiding = false; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 6948 | WindowState windowDetachedWallpaper = null; |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 6949 | WindowState windowAnimationBackground = null; |
| 6950 | int windowAnimationBackgroundColor = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6951 | |
| 6952 | mPolicy.beginAnimationLw(dw, dh); |
| 6953 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 6954 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6955 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6956 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6957 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6958 | |
| 6959 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 6960 | |
| 6961 | if (w.mSurface != null) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6962 | // Take care of the window being ready to display. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6963 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 6964 | if ((w.mAttrs.flags |
| 6965 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6966 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6967 | "First draw done in potential wallpaper target " + w); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6968 | wallpaperMayChange = true; |
| 6969 | } |
| 6970 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6971 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 6972 | final boolean wasAnimating = w.mAnimating; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6973 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 6974 | int animDw = innerDw; |
| 6975 | int animDh = innerDh; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6976 | |
| 6977 | // If the window has moved due to its containing |
| 6978 | // content frame changing, then we'd like to animate |
| 6979 | // it. The checks here are ordered by what is least |
Joe Onorato | 3fe7f2f | 2010-11-20 13:48:58 -0800 | [diff] [blame] | 6980 | // likely to be true first. |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 6981 | if (w.shouldAnimateMove()) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6982 | // Frame has moved, containing content frame |
| 6983 | // has also moved, and we're not currently animating... |
| 6984 | // let's do something. |
| 6985 | Animation a = AnimationUtils.loadAnimation(mContext, |
| 6986 | com.android.internal.R.anim.window_move_from_decor); |
| 6987 | w.setAnimation(a); |
| 6988 | animDw = w.mLastFrame.left - w.mFrame.left; |
| 6989 | animDh = w.mLastFrame.top - w.mFrame.top; |
| 6990 | } |
| 6991 | |
| 6992 | // Execute animation. |
| 6993 | final boolean nowAnimating = w.stepAnimationLocked(currentTime, |
| 6994 | animDw, animDh); |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 6995 | |
| 6996 | // If this window is animating, make a note that we have |
| 6997 | // an animating window and take care of a request to run |
| 6998 | // a detached wallpaper animation. |
| 6999 | if (nowAnimating) { |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 7000 | if (w.mAnimation != null) { |
| 7001 | if (w.mAnimation.getDetachWallpaper()) { |
| 7002 | windowDetachedWallpaper = w; |
| 7003 | } |
| 7004 | if (w.mAnimation.getBackgroundColor() != 0) { |
| 7005 | windowAnimationBackground = w; |
| 7006 | windowAnimationBackgroundColor = |
| 7007 | w.mAnimation.getBackgroundColor(); |
| 7008 | } |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 7009 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7010 | animating = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7011 | } |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 7012 | |
| 7013 | // If this window's app token is running a detached wallpaper |
| 7014 | // animation, make a note so we can ensure the wallpaper is |
| 7015 | // displayed behind it. |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 7016 | if (w.mAppToken != null && w.mAppToken.animation != null) { |
| 7017 | if (w.mAppToken.animation.getDetachWallpaper()) { |
| 7018 | windowDetachedWallpaper = w; |
| 7019 | } |
| 7020 | if (w.mAppToken.animation.getBackgroundColor() != 0) { |
| 7021 | windowAnimationBackground = w; |
| 7022 | windowAnimationBackgroundColor = |
| 7023 | w.mAppToken.animation.getBackgroundColor(); |
| 7024 | } |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 7025 | } |
| 7026 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7027 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 7028 | wallpaperMayChange = true; |
| 7029 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7030 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7031 | if (mPolicy.doesForceHide(w, attrs)) { |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 7032 | if (!wasAnimating && nowAnimating) { |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 7033 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 7034 | "Animation started that could impact force hide: " |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 7035 | + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7036 | wallpaperForceHidingChanged = true; |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7037 | mFocusMayChange = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7038 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 7039 | forceHiding = true; |
| 7040 | } |
| 7041 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 7042 | boolean changed; |
| 7043 | if (forceHiding) { |
| 7044 | changed = w.hideLw(false, false); |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 7045 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 7046 | "Now policy hidden: " + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7047 | } else { |
| 7048 | changed = w.showLw(false, false); |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 7049 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 7050 | "Now policy shown: " + w); |
| 7051 | if (changed) { |
| 7052 | if (wallpaperForceHidingChanged |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7053 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 7054 | // Assume we will need to animate. If |
| 7055 | // we don't (because the wallpaper will |
| 7056 | // stay with the lock screen), then we will |
| 7057 | // clean up later. |
| 7058 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 7059 | if (a != null) { |
| 7060 | w.setAnimation(a); |
| 7061 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7062 | } |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 7063 | if (mCurrentFocus == null || |
| 7064 | mCurrentFocus.mLayer < w.mLayer) { |
| 7065 | // We are showing on to of the current |
| 7066 | // focus, so re-evaluate focus to make |
| 7067 | // sure it is correct. |
| 7068 | mFocusMayChange = true; |
| 7069 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7070 | } |
| 7071 | } |
| 7072 | if (changed && (attrs.flags |
| 7073 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 7074 | wallpaperMayChange = true; |
| 7075 | } |
| 7076 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7077 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7078 | mPolicy.animatingWindowLw(w, attrs); |
| 7079 | } |
| 7080 | |
| 7081 | final AppWindowToken atoken = w.mAppToken; |
| 7082 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 7083 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 7084 | atoken.lastTransactionSequence = transactionSequence; |
| 7085 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 7086 | atoken.startingDisplayed = false; |
| 7087 | } |
| 7088 | if ((w.isOnScreen() || w.mAttrs.type |
| 7089 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 7090 | && !w.mExiting && !w.mDestroying) { |
| 7091 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7092 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7093 | + w.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7094 | + ", isAnimating=" + w.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7095 | if (!w.isDrawnLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7096 | Slog.v(TAG, "Not displayed: s=" + w.mSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7097 | + " pv=" + w.mPolicyVisibility |
| 7098 | + " dp=" + w.mDrawPending |
| 7099 | + " cdp=" + w.mCommitDrawPending |
| 7100 | + " ah=" + w.mAttachedHidden |
| 7101 | + " th=" + atoken.hiddenRequested |
| 7102 | + " a=" + w.mAnimating); |
| 7103 | } |
| 7104 | } |
| 7105 | if (w != atoken.startingWindow) { |
| 7106 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 7107 | atoken.numInterestingWindows++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7108 | if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7109 | atoken.numDrawnWindows++; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7110 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7111 | "tokenMayBeDrawn: " + atoken |
| 7112 | + " freezingScreen=" + atoken.freezingScreen |
| 7113 | + " mAppFreezing=" + w.mAppFreezing); |
| 7114 | tokenMayBeDrawn = true; |
| 7115 | } |
| 7116 | } |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7117 | } else if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7118 | atoken.startingDisplayed = true; |
| 7119 | } |
| 7120 | } |
| 7121 | } else if (w.mReadyToShow) { |
| 7122 | w.performShowLocked(); |
| 7123 | } |
| 7124 | } |
| 7125 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7126 | changes |= mPolicy.finishAnimationLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7127 | |
| 7128 | if (tokenMayBeDrawn) { |
| 7129 | // See if any windows have been drawn, so they (and others |
| 7130 | // associated with them) can now be shown. |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7131 | final int NT = mAppTokens.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7132 | for (i=0; i<NT; i++) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7133 | AppWindowToken wtoken = mAppTokens.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7134 | if (wtoken.freezingScreen) { |
| 7135 | int numInteresting = wtoken.numInterestingWindows; |
| 7136 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7137 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7138 | "allDrawn: " + wtoken |
| 7139 | + " interesting=" + numInteresting |
| 7140 | + " drawn=" + wtoken.numDrawnWindows); |
| 7141 | wtoken.showAllWindowsLocked(); |
| 7142 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 7143 | orientationChangeComplete = true; |
| 7144 | } |
| 7145 | } else if (!wtoken.allDrawn) { |
| 7146 | int numInteresting = wtoken.numInterestingWindows; |
| 7147 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7148 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7149 | "allDrawn: " + wtoken |
| 7150 | + " interesting=" + numInteresting |
| 7151 | + " drawn=" + wtoken.numDrawnWindows); |
| 7152 | wtoken.allDrawn = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7153 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7154 | |
| 7155 | // We can now show all of the drawn windows! |
| 7156 | if (!mOpeningApps.contains(wtoken)) { |
| 7157 | wtoken.showAllWindowsLocked(); |
| 7158 | } |
| 7159 | } |
| 7160 | } |
| 7161 | } |
| 7162 | } |
| 7163 | |
| 7164 | // If we are ready to perform an app transition, check through |
| 7165 | // all of the app tokens to be shown and see if they are ready |
| 7166 | // to go. |
| 7167 | if (mAppTransitionReady) { |
| 7168 | int NN = mOpeningApps.size(); |
| 7169 | boolean goodToGo = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7170 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7171 | "Checking " + NN + " opening apps (frozen=" |
| 7172 | + mDisplayFrozen + " timeout=" |
| 7173 | + mAppTransitionTimeout + ")..."); |
| 7174 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 7175 | // If the display isn't frozen, wait to do anything until |
| 7176 | // all of the apps are ready. Otherwise just go because |
| 7177 | // we'll unfreeze the display when everyone is ready. |
| 7178 | for (i=0; i<NN && goodToGo; i++) { |
| 7179 | AppWindowToken wtoken = mOpeningApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7180 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7181 | "Check opening app" + wtoken + ": allDrawn=" |
| 7182 | + wtoken.allDrawn + " startingDisplayed=" |
| 7183 | + wtoken.startingDisplayed); |
| 7184 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 7185 | && !wtoken.startingMoved) { |
| 7186 | goodToGo = false; |
| 7187 | } |
| 7188 | } |
| 7189 | } |
| 7190 | if (goodToGo) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7191 | 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] | 7192 | int transit = mNextAppTransition; |
| 7193 | if (mSkipAppTransitionAnimation) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 7194 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7195 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 7196 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7197 | mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7198 | mAppTransitionRunning = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7199 | mAppTransitionTimeout = false; |
| 7200 | mStartingIconInTransition = false; |
| 7201 | mSkipAppTransitionAnimation = false; |
| 7202 | |
| 7203 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 7204 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7205 | // If there are applications waiting to come to the |
| 7206 | // top of the stack, now is the time to move their windows. |
| 7207 | // (Note that we don't do apps going to the bottom |
| 7208 | // here -- we want to keep their windows in the old |
| 7209 | // Z-order until the animation completes.) |
| 7210 | if (mToTopApps.size() > 0) { |
| 7211 | NN = mAppTokens.size(); |
| 7212 | for (i=0; i<NN; i++) { |
| 7213 | AppWindowToken wtoken = mAppTokens.get(i); |
| 7214 | if (wtoken.sendingToTop) { |
| 7215 | wtoken.sendingToTop = false; |
| 7216 | moveAppWindowsLocked(wtoken, NN, false); |
| 7217 | } |
| 7218 | } |
| 7219 | mToTopApps.clear(); |
| 7220 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7221 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7222 | WindowState oldWallpaper = mWallpaperTarget; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7223 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7224 | adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7225 | wallpaperMayChange = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7226 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 7227 | // The top-most window will supply the layout params, |
| 7228 | // and we will determine it below. |
| 7229 | LayoutParams animLp = null; |
| 7230 | int bestAnimLayer = -1; |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 7231 | boolean fullscreenAnim = false; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 7232 | boolean needBgFiller = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7233 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7234 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7235 | "New wallpaper target=" + mWallpaperTarget |
| 7236 | + ", lower target=" + mLowerWallpaperTarget |
| 7237 | + ", upper target=" + mUpperWallpaperTarget); |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7238 | int foundWallpapers = 0; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 7239 | // Do a first pass through the tokens for two |
| 7240 | // things: |
| 7241 | // (1) Determine if both the closing and opening |
| 7242 | // app token sets are wallpaper targets, in which |
| 7243 | // case special animations are needed |
| 7244 | // (since the wallpaper needs to stay static |
| 7245 | // behind them). |
| 7246 | // (2) Find the layout params of the top-most |
| 7247 | // application window in the tokens, which is |
| 7248 | // what will control the animation theme. |
| 7249 | final int NC = mClosingApps.size(); |
| 7250 | NN = NC + mOpeningApps.size(); |
| 7251 | for (i=0; i<NN; i++) { |
| 7252 | AppWindowToken wtoken; |
| 7253 | int mode; |
| 7254 | if (i < NC) { |
| 7255 | wtoken = mClosingApps.get(i); |
| 7256 | mode = 1; |
| 7257 | } else { |
| 7258 | wtoken = mOpeningApps.get(i-NC); |
| 7259 | mode = 2; |
| 7260 | } |
| 7261 | if (mLowerWallpaperTarget != null) { |
| 7262 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 7263 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 7264 | foundWallpapers |= mode; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7265 | } |
| 7266 | } |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 7267 | if (wtoken.appFullscreen) { |
| 7268 | WindowState ws = wtoken.findMainWindow(); |
| 7269 | if (ws != null) { |
| 7270 | // If this is a compatibility mode |
| 7271 | // window, we will always use its anim. |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 7272 | if (ws.mNeedsBackgroundFiller) { |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 7273 | animLp = ws.mAttrs; |
| 7274 | bestAnimLayer = Integer.MAX_VALUE; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 7275 | needBgFiller = true; |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 7276 | } else if (!fullscreenAnim || ws.mLayer > bestAnimLayer) { |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 7277 | animLp = ws.mAttrs; |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 7278 | bestAnimLayer = ws.mLayer; |
| 7279 | } |
| 7280 | fullscreenAnim = true; |
| 7281 | } |
| 7282 | } else if (!fullscreenAnim) { |
| 7283 | WindowState ws = wtoken.findMainWindow(); |
| 7284 | if (ws != null) { |
| 7285 | if (ws.mLayer > bestAnimLayer) { |
| 7286 | animLp = ws.mAttrs; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 7287 | bestAnimLayer = ws.mLayer; |
| 7288 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7289 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7290 | } |
| 7291 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7292 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7293 | if (foundWallpapers == 3) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7294 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7295 | "Wallpaper animation!"); |
| 7296 | switch (transit) { |
| 7297 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 7298 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 7299 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 7300 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 7301 | break; |
| 7302 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 7303 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 7304 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 7305 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 7306 | break; |
| 7307 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7308 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7309 | "New transit: " + transit); |
| 7310 | } else if (oldWallpaper != null) { |
| 7311 | // We are transitioning from an activity with |
| 7312 | // a wallpaper to one without. |
| 7313 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7314 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7315 | "New transit away from wallpaper: " + transit); |
| 7316 | } else if (mWallpaperTarget != null) { |
| 7317 | // We are transitioning from an activity without |
| 7318 | // a wallpaper to now showing the wallpaper |
| 7319 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7320 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7321 | "New transit into wallpaper: " + transit); |
| 7322 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7323 | |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7324 | // If all closing windows are obscured, then there is |
| 7325 | // no need to do an animation. This is the case, for |
| 7326 | // example, when this transition is being done behind |
| 7327 | // the lock screen. |
| 7328 | if (!mPolicy.allowAppAnimationsLw()) { |
| 7329 | animLp = null; |
| 7330 | } |
| 7331 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7332 | NN = mOpeningApps.size(); |
| 7333 | for (i=0; i<NN; i++) { |
| 7334 | AppWindowToken wtoken = mOpeningApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7335 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7336 | "Now opening app" + wtoken); |
| 7337 | wtoken.reportedVisible = false; |
| 7338 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 7339 | wtoken.animation = null; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 7340 | setTokenVisibilityLocked(wtoken, animLp, true, |
| 7341 | transit, false, needBgFiller); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7342 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7343 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7344 | wtoken.showAllWindowsLocked(); |
| 7345 | } |
| 7346 | NN = mClosingApps.size(); |
| 7347 | for (i=0; i<NN; i++) { |
| 7348 | AppWindowToken wtoken = mClosingApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7349 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7350 | "Now closing app" + wtoken); |
| 7351 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 7352 | wtoken.animation = null; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 7353 | setTokenVisibilityLocked(wtoken, animLp, false, |
| 7354 | transit, false, needBgFiller); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7355 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7356 | wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7357 | // Force the allDrawn flag, because we want to start |
| 7358 | // this guy's animations regardless of whether it's |
| 7359 | // gotten drawn. |
| 7360 | wtoken.allDrawn = true; |
| 7361 | } |
| 7362 | |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 7363 | mNextAppTransitionPackage = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7364 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7365 | mOpeningApps.clear(); |
| 7366 | mClosingApps.clear(); |
| 7367 | |
| 7368 | // This has changed the visibility of windows, so perform |
| 7369 | // a new layout to get them all up-to-date. |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 7370 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT |
| 7371 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7372 | mLayoutNeeded = true; |
Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 7373 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 7374 | assignLayersLocked(); |
| 7375 | } |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 7376 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, |
| 7377 | false /*updateInputWindows*/); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7378 | mFocusMayChange = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7379 | } |
| 7380 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7381 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7382 | int adjResult = 0; |
| 7383 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7384 | if (!animating && mAppTransitionRunning) { |
| 7385 | // We have finished the animation of an app transition. To do |
| 7386 | // this, we have delayed a lot of operations like showing and |
| 7387 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 7388 | // reflects the correct Z-order, but the window list may now |
| 7389 | // be out of sync with it. So here we will just rebuild the |
| 7390 | // entire app window list. Fun! |
| 7391 | mAppTransitionRunning = false; |
| 7392 | // Clear information about apps that were moving. |
| 7393 | mToBottomApps.clear(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7394 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7395 | rebuildAppWindowListLocked(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7396 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7397 | adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7398 | moveInputMethodWindowsIfNeededLocked(false); |
| 7399 | wallpaperMayChange = true; |
Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 7400 | // Since the window list has been rebuilt, focus might |
| 7401 | // have to be recomputed since the actual order of windows |
| 7402 | // might have changed again. |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7403 | mFocusMayChange = true; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7404 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7405 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7406 | if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7407 | // At this point, there was a window with a wallpaper that |
| 7408 | // was force hiding other windows behind it, but now it |
| 7409 | // is going away. This may be simple -- just animate |
| 7410 | // away the wallpaper and its window -- or it may be |
| 7411 | // hard -- the wallpaper now needs to be shown behind |
| 7412 | // something that was hidden. |
| 7413 | WindowState oldWallpaper = mWallpaperTarget; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7414 | if (mLowerWallpaperTarget != null |
| 7415 | && mLowerWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7416 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7417 | "wallpaperForceHiding changed with lower=" |
| 7418 | + mLowerWallpaperTarget); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7419 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7420 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 7421 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 7422 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 7423 | // The lower target has become hidden before we |
| 7424 | // actually started the animation... let's completely |
| 7425 | // re-evaluate everything. |
| 7426 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7427 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7428 | } |
| 7429 | } |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7430 | adjResult |= adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7431 | wallpaperMayChange = false; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7432 | wallpaperForceHidingChanged = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7433 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7434 | + " NEW: " + mWallpaperTarget |
| 7435 | + " LOWER: " + mLowerWallpaperTarget); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7436 | if (mLowerWallpaperTarget == null) { |
| 7437 | // Whoops, we don't need a special wallpaper animation. |
| 7438 | // Clear them out. |
| 7439 | forceHiding = false; |
| 7440 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7441 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7442 | if (w.mSurface != null) { |
| 7443 | final WindowManager.LayoutParams attrs = w.mAttrs; |
Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 7444 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7445 | if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7446 | forceHiding = true; |
| 7447 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 7448 | if (!w.mAnimating) { |
| 7449 | // We set the animation above so it |
| 7450 | // is not yet running. |
| 7451 | w.clearAnimation(); |
| 7452 | } |
| 7453 | } |
| 7454 | } |
| 7455 | } |
| 7456 | } |
| 7457 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7458 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 7459 | if (mWindowDetachedWallpaper != windowDetachedWallpaper) { |
| 7460 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 7461 | "Detached wallpaper changed from " + mWindowDetachedWallpaper |
| 7462 | + windowDetachedWallpaper); |
| 7463 | mWindowDetachedWallpaper = windowDetachedWallpaper; |
| 7464 | wallpaperMayChange = true; |
| 7465 | } |
| 7466 | |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 7467 | if (windowAnimationBackgroundColor != 0) { |
| 7468 | if (mWindowAnimationBackgroundSurface == null) { |
| 7469 | mWindowAnimationBackgroundSurface = new DimSurface(mFxSession); |
| 7470 | } |
| 7471 | mWindowAnimationBackgroundSurface.show(dw, dh, |
| 7472 | windowAnimationBackground.mAnimLayer - LAYER_OFFSET_DIM, |
| 7473 | windowAnimationBackgroundColor); |
| 7474 | } else if (mWindowAnimationBackgroundSurface != null) { |
| 7475 | mWindowAnimationBackgroundSurface.hide(); |
| 7476 | } |
| 7477 | |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7478 | if (wallpaperMayChange) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7479 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7480 | "Wallpaper may change! Adjusting"); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7481 | adjResult |= adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7482 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7483 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7484 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7485 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7486 | "Wallpaper layer changed: assigning layers + relayout"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7487 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7488 | assignLayersLocked(); |
| 7489 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7490 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7491 | "Wallpaper visibility changed: relayout"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7492 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7493 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7494 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7495 | if (mFocusMayChange) { |
| 7496 | mFocusMayChange = false; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 7497 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, |
| 7498 | false /*updateInputWindows*/)) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7499 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7500 | adjResult = 0; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7501 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7502 | } |
| 7503 | |
| 7504 | if (mLayoutNeeded) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7505 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7506 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7507 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7508 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x" |
| 7509 | + Integer.toHexString(changes)); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7510 | } while (changes != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7511 | |
| 7512 | // THIRD LOOP: Update the surfaces of all windows. |
| 7513 | |
| 7514 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 7515 | |
| 7516 | boolean obscured = false; |
| 7517 | boolean blurring = false; |
| 7518 | boolean dimming = false; |
| 7519 | boolean covered = false; |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 7520 | boolean syswin = false; |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 7521 | boolean backgroundFillerWasShown = mBackgroundFillerTarget != null; |
| 7522 | mBackgroundFillerTarget = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7523 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 7524 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7525 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7526 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7527 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7528 | |
| 7529 | boolean displayed = false; |
| 7530 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 7531 | final int attrFlags = attrs.flags; |
| 7532 | |
| 7533 | if (w.mSurface != null) { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 7534 | // XXX NOTE: The logic here could be improved. We have |
| 7535 | // the decision about whether to resize a window separated |
| 7536 | // from whether to hide the surface. This can cause us to |
| 7537 | // resize a surface even if we are going to hide it. You |
| 7538 | // can see this by (1) holding device in landscape mode on |
| 7539 | // home screen; (2) tapping browser icon (device will rotate |
| 7540 | // to landscape; (3) tap home. The wallpaper will be resized |
| 7541 | // in step 2 but then immediately hidden, causing us to |
| 7542 | // have to resize and then redraw it again in step 3. It |
| 7543 | // would be nice to figure out how to avoid this, but it is |
| 7544 | // difficult because we do need to resize surfaces in some |
| 7545 | // cases while they are hidden such as when first showing a |
| 7546 | // window. |
| 7547 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7548 | w.computeShownFrameLocked(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7549 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7550 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 7551 | + ": new=" + w.mShownFrame + ", old=" |
| 7552 | + w.mLastShownFrame); |
| 7553 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7554 | int width, height; |
| 7555 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7556 | // for a scaled surface, we just want to use |
| 7557 | // the requested size. |
| 7558 | width = w.mRequestedWidth; |
| 7559 | height = w.mRequestedHeight; |
| 7560 | w.mLastRequestedWidth = width; |
| 7561 | w.mLastRequestedHeight = height; |
| 7562 | w.mLastShownFrame.set(w.mShownFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7563 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7564 | width = w.mShownFrame.width(); |
| 7565 | height = w.mShownFrame.height(); |
| 7566 | w.mLastShownFrame.set(w.mShownFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7567 | } |
| 7568 | |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 7569 | if (w.mSurface != null) { |
| 7570 | if (w.mSurfaceX != w.mShownFrame.left |
| 7571 | || w.mSurfaceY != w.mShownFrame.top) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7572 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7573 | if (SHOW_TRANSACTIONS) logSurface(w, |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 7574 | "POS " + w.mShownFrame.left |
| 7575 | + ", " + w.mShownFrame.top, null); |
| 7576 | w.mSurfaceX = w.mShownFrame.left; |
| 7577 | w.mSurfaceY = w.mShownFrame.top; |
| 7578 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 7579 | } catch (RuntimeException e) { |
| 7580 | Slog.w(TAG, "Error positioning surface of " + w |
| 7581 | + " pos=(" + w.mShownFrame.left |
| 7582 | + "," + w.mShownFrame.top + ")", e); |
| 7583 | if (!recoveringMemory) { |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 7584 | reclaimSomeSurfaceMemoryLocked(w, "position", true); |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 7585 | } |
| 7586 | } |
| 7587 | } |
| 7588 | |
| 7589 | if (width < 1) { |
| 7590 | width = 1; |
| 7591 | } |
| 7592 | if (height < 1) { |
| 7593 | height = 1; |
| 7594 | } |
| 7595 | |
| 7596 | if (w.mSurfaceW != width || w.mSurfaceH != height) { |
| 7597 | try { |
| 7598 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 7599 | "SIZE " + w.mShownFrame.width() + "x" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7600 | + w.mShownFrame.height(), null); |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 7601 | w.mSurfaceResized = true; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7602 | w.mSurfaceW = width; |
| 7603 | w.mSurfaceH = height; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7604 | w.mSurface.setSize(width, height); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7605 | } catch (RuntimeException e) { |
| 7606 | // If something goes wrong with the surface (such |
| 7607 | // as running out of memory), don't take down the |
| 7608 | // entire system. |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 7609 | Slog.e(TAG, "Error resizing surface of " + w |
| 7610 | + " size=(" + width + "x" + height + ")", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7611 | if (!recoveringMemory) { |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 7612 | reclaimSomeSurfaceMemoryLocked(w, "size", true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7613 | } |
| 7614 | } |
| 7615 | } |
| 7616 | } |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 7617 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7618 | if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7619 | w.mContentInsetsChanged = |
| 7620 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 7621 | w.mVisibleInsetsChanged = |
| 7622 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7623 | boolean configChanged = |
| 7624 | w.mConfiguration != mCurConfiguration |
| 7625 | && (w.mConfiguration == null |
| 7626 | || mCurConfiguration.diff(w.mConfiguration) != 0); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 7627 | if (DEBUG_CONFIGURATION && configChanged) { |
| 7628 | Slog.v(TAG, "Win " + w + " config changed: " |
| 7629 | + mCurConfiguration); |
| 7630 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7631 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7632 | + ": configChanged=" + configChanged |
| 7633 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 7634 | boolean frameChanged = !w.mLastFrame.equals(w.mFrame); |
| 7635 | if (frameChanged |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7636 | || w.mContentInsetsChanged |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7637 | || w.mVisibleInsetsChanged |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 7638 | || w.mSurfaceResized |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7639 | || configChanged) { |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 7640 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) { |
| 7641 | Slog.v(TAG, "Resize reasons: " |
| 7642 | + "frameChanged=" + frameChanged |
| 7643 | + " contentInsetsChanged=" + w.mContentInsetsChanged |
| 7644 | + " visibleInsetsChanged=" + w.mVisibleInsetsChanged |
| 7645 | + " surfaceResized=" + w.mSurfaceResized |
| 7646 | + " configChanged=" + configChanged); |
| 7647 | } |
| 7648 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7649 | w.mLastFrame.set(w.mFrame); |
| 7650 | w.mLastContentInsets.set(w.mContentInsets); |
| 7651 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7652 | // If the screen is currently frozen, then keep |
| 7653 | // it frozen until this window draws at its new |
| 7654 | // orientation. |
| 7655 | if (mDisplayFrozen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7656 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7657 | "Resizing while display frozen: " + w); |
| 7658 | w.mOrientationChanging = true; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7659 | if (!mWindowsFreezingScreen) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7660 | mWindowsFreezingScreen = true; |
| 7661 | // XXX should probably keep timeout from |
| 7662 | // when we first froze the display. |
| 7663 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 7664 | mH.sendMessageDelayed(mH.obtainMessage( |
| 7665 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 7666 | } |
| 7667 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7668 | // If the orientation is changing, then we need to |
| 7669 | // hold off on unfreezing the display until this |
| 7670 | // window has been redrawn; to do that, we need |
| 7671 | // to go through the process of getting informed |
| 7672 | // by the application when it has finished drawing. |
| 7673 | if (w.mOrientationChanging) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7674 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7675 | "Orientation start waiting for draw in " |
| 7676 | + w + ", surface " + w.mSurface); |
| 7677 | w.mDrawPending = true; |
| 7678 | w.mCommitDrawPending = false; |
| 7679 | w.mReadyToShow = false; |
| 7680 | if (w.mAppToken != null) { |
| 7681 | w.mAppToken.allDrawn = false; |
| 7682 | } |
| 7683 | } |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 7684 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7685 | "Resizing window " + w + " to " + w.mFrame); |
| 7686 | mResizingWindows.add(w); |
| 7687 | } else if (w.mOrientationChanging) { |
| 7688 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7689 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7690 | "Orientation not waiting for draw in " |
| 7691 | + w + ", surface " + w.mSurface); |
| 7692 | w.mOrientationChanging = false; |
| 7693 | } |
| 7694 | } |
| 7695 | } |
| 7696 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7697 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7698 | if (!w.mLastHidden) { |
| 7699 | //dump(); |
| 7700 | w.mLastHidden = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7701 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 7702 | "HIDE (performLayout)", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7703 | if (w.mSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7704 | w.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7705 | try { |
| 7706 | w.mSurface.hide(); |
| 7707 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7708 | Slog.w(TAG, "Exception hiding surface in " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7709 | } |
| 7710 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7711 | } |
| 7712 | // If we are waiting for this window to handle an |
| 7713 | // orientation change, well, it is hidden, so |
| 7714 | // doesn't really matter. Note that this does |
| 7715 | // introduce a potential glitch if the window |
| 7716 | // becomes unhidden before it has drawn for the |
| 7717 | // new orientation. |
| 7718 | if (w.mOrientationChanging) { |
| 7719 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7720 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7721 | "Orientation change skips hidden " + w); |
| 7722 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7723 | } else if (w.mLastLayer != w.mAnimLayer |
| 7724 | || w.mLastAlpha != w.mShownAlpha |
| 7725 | || w.mLastDsDx != w.mDsDx |
| 7726 | || w.mLastDtDx != w.mDtDx |
| 7727 | || w.mLastDsDy != w.mDsDy |
| 7728 | || w.mLastDtDy != w.mDtDy |
| 7729 | || w.mLastHScale != w.mHScale |
| 7730 | || w.mLastVScale != w.mVScale |
| 7731 | || w.mLastHidden) { |
| 7732 | displayed = true; |
| 7733 | w.mLastAlpha = w.mShownAlpha; |
| 7734 | w.mLastLayer = w.mAnimLayer; |
| 7735 | w.mLastDsDx = w.mDsDx; |
| 7736 | w.mLastDtDx = w.mDtDx; |
| 7737 | w.mLastDsDy = w.mDsDy; |
| 7738 | w.mLastDtDy = w.mDtDy; |
| 7739 | w.mLastHScale = w.mHScale; |
| 7740 | w.mLastVScale = w.mVScale; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7741 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 7742 | "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7743 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 7744 | + "," + (w.mDtDx*w.mVScale) |
| 7745 | + "][" + (w.mDsDy*w.mHScale) |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7746 | + "," + (w.mDtDy*w.mVScale) + "]", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7747 | if (w.mSurface != null) { |
| 7748 | try { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7749 | w.mSurfaceAlpha = w.mShownAlpha; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7750 | w.mSurface.setAlpha(w.mShownAlpha); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7751 | w.mSurfaceLayer = w.mAnimLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7752 | w.mSurface.setLayer(w.mAnimLayer); |
| 7753 | w.mSurface.setMatrix( |
| 7754 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 7755 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 7756 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7757 | Slog.w(TAG, "Error updating surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7758 | if (!recoveringMemory) { |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 7759 | reclaimSomeSurfaceMemoryLocked(w, "update", true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7760 | } |
| 7761 | } |
| 7762 | } |
| 7763 | |
| 7764 | if (w.mLastHidden && !w.mDrawPending |
| 7765 | && !w.mCommitDrawPending |
| 7766 | && !w.mReadyToShow) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7767 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 7768 | "SHOW (performLayout)", null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7769 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7770 | + " during relayout"); |
| 7771 | if (showSurfaceRobustlyLocked(w)) { |
| 7772 | w.mHasDrawn = true; |
| 7773 | w.mLastHidden = false; |
| 7774 | } else { |
| 7775 | w.mOrientationChanging = false; |
| 7776 | } |
| 7777 | } |
| 7778 | if (w.mSurface != null) { |
| 7779 | w.mToken.hasVisible = true; |
| 7780 | } |
| 7781 | } else { |
| 7782 | displayed = true; |
| 7783 | } |
| 7784 | |
| 7785 | if (displayed) { |
| 7786 | if (!covered) { |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 7787 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 7788 | && attrs.height == LayoutParams.MATCH_PARENT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7789 | covered = true; |
| 7790 | } |
| 7791 | } |
| 7792 | if (w.mOrientationChanging) { |
| 7793 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 7794 | orientationChangeComplete = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7795 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7796 | "Orientation continue waiting for draw in " + w); |
| 7797 | } else { |
| 7798 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7799 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7800 | "Orientation change complete in " + w); |
| 7801 | } |
| 7802 | } |
| 7803 | w.mToken.hasVisible = true; |
| 7804 | } |
| 7805 | } else if (w.mOrientationChanging) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7806 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7807 | "Orientation change skips hidden " + w); |
| 7808 | w.mOrientationChanging = false; |
| 7809 | } |
| 7810 | |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 7811 | if (w.mContentChanged) { |
| 7812 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing"); |
| 7813 | w.mContentChanged = false; |
| 7814 | } |
| 7815 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7816 | final boolean canBeSeen = w.isDisplayedLw(); |
| 7817 | |
| 7818 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 7819 | focusDisplayed = true; |
| 7820 | } |
| 7821 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7822 | final boolean obscuredChanged = w.mObscured != obscured; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7823 | |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 7824 | if (mBackgroundFillerTarget != null) { |
| 7825 | if (w.isAnimating()) { |
| 7826 | // Background filler is below all other windows that |
| 7827 | // are animating. |
| 7828 | mBackgroundFillerTarget = w; |
| 7829 | } else if (w.mIsWallpaper) { |
| 7830 | mBackgroundFillerTarget = w; |
| 7831 | } |
| 7832 | } |
| 7833 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7834 | // Update effect. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7835 | if (!(w.mObscured=obscured)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7836 | if (w.mSurface != null) { |
| 7837 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 7838 | holdScreen = w.mSession; |
| 7839 | } |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 7840 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 7841 | && screenBrightness < 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7842 | screenBrightness = w.mAttrs.screenBrightness; |
| 7843 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 7844 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 7845 | && buttonBrightness < 0) { |
| 7846 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 7847 | } |
Mike Lockwood | 46af6a8 | 2010-03-09 08:28:22 -0500 | [diff] [blame] | 7848 | if (canBeSeen |
| 7849 | && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 7850 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 7851 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) { |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 7852 | syswin = true; |
| 7853 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7854 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7855 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7856 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 7857 | if (opaqueDrawn && w.isFullscreen(innerDw, innerDh)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7858 | // This window completely covers everything behind it, |
| 7859 | // so we want to leave all of them as unblurred (for |
| 7860 | // performance reasons). |
| 7861 | obscured = true; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 7862 | } else if (w.mNeedsBackgroundFiller && w.mHasDrawn |
| 7863 | && w.mViewVisibility == View.VISIBLE |
| 7864 | && (canBeSeen || w.isAnimating())) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7865 | // This window is in compatibility mode, and needs background filler. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7866 | obscured = true; |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 7867 | mBackgroundFillerTarget = w; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7868 | } else if (canBeSeen && !obscured && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7869 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7870 | if (localLOGV) Slog.v(TAG, "Win " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7871 | + ": blurring=" + blurring |
| 7872 | + " obscured=" + obscured |
| 7873 | + " displayed=" + displayed); |
| 7874 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 7875 | if (!dimming) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7876 | //Slog.i(TAG, "DIM BEHIND: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7877 | dimming = true; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7878 | if (mDimAnimator == null) { |
| 7879 | mDimAnimator = new DimAnimator(mFxSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7880 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7881 | mDimAnimator.show(dw, dh); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 7882 | mDimAnimator.updateParameters(mContext.getResources(), |
| 7883 | w, currentTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7884 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7885 | } |
| 7886 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 7887 | if (!blurring) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7888 | //Slog.i(TAG, "BLUR BEHIND: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7889 | blurring = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7890 | if (mBlurSurface == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7891 | try { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7892 | mBlurSurface = new Surface(mFxSession, 0, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 7893 | "BlurSurface", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7894 | -1, 16, 16, |
| 7895 | PixelFormat.OPAQUE, |
| 7896 | Surface.FX_SURFACE_BLUR); |
| 7897 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7898 | Slog.e(TAG, "Exception creating Blur surface", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7899 | } |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 7900 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 7901 | + mBlurSurface + ": CREATE"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7902 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7903 | if (mBlurSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7904 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 7905 | + mBlurSurface + ": pos=(0,0) (" + |
| 7906 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7907 | mBlurSurface.setPosition(0, 0); |
| 7908 | mBlurSurface.setSize(dw, dh); |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 7909 | mBlurSurface.setLayer(w.mAnimLayer-LAYER_OFFSET_BLUR); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7910 | if (!mBlurShown) { |
| 7911 | try { |
| 7912 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 7913 | + mBlurSurface + ": SHOW"); |
| 7914 | mBlurSurface.show(); |
| 7915 | } catch (RuntimeException e) { |
| 7916 | Slog.w(TAG, "Failure showing blur surface", e); |
| 7917 | } |
| 7918 | mBlurShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7919 | } |
| 7920 | } |
| 7921 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7922 | } |
| 7923 | } |
| 7924 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7925 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7926 | if (obscuredChanged && mWallpaperTarget == w) { |
| 7927 | // This is the wallpaper target and its obscured state |
| 7928 | // changed... make sure the current wallaper's visibility |
| 7929 | // has been updated accordingly. |
| 7930 | updateWallpaperVisibilityLocked(); |
| 7931 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7932 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7933 | |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 7934 | if (mBackgroundFillerTarget != null) { |
| 7935 | if (mBackgroundFillerSurface == null) { |
| 7936 | try { |
| 7937 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
| 7938 | "BackGroundFiller", |
| 7939 | 0, dw, dh, |
| 7940 | PixelFormat.OPAQUE, |
| 7941 | Surface.FX_SURFACE_NORMAL); |
| 7942 | } catch (Exception e) { |
| 7943 | Slog.e(TAG, "Exception creating filler surface", e); |
| 7944 | } |
| 7945 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BG FILLER " |
| 7946 | + mBackgroundFillerSurface + ": CREATE"); |
| 7947 | } |
| 7948 | try { |
| 7949 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BG FILLER " |
| 7950 | + mBackgroundFillerSurface + " SHOW: pos=(0,0) (" |
| 7951 | + dw + "x" + dh + ") layer=" |
| 7952 | + (mBackgroundFillerTarget.mLayer - 1)); |
| 7953 | mBackgroundFillerSurface.setPosition(0, 0); |
| 7954 | mBackgroundFillerSurface.setSize(dw, dh); |
| 7955 | // Using the same layer as Dim because they will never be shown at the |
| 7956 | // same time. NOTE: we do NOT use mAnimLayer, because we don't |
| 7957 | // want this surface dragged up in front of stuff that is animating. |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 7958 | mBackgroundFillerSurface.setLayer(mBackgroundFillerTarget.mLayer |
| 7959 | - LAYER_OFFSET_DIM); |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 7960 | mBackgroundFillerSurface.show(); |
| 7961 | } catch (RuntimeException e) { |
| 7962 | Slog.e(TAG, "Exception showing filler surface"); |
| 7963 | } |
| 7964 | } else if (backgroundFillerWasShown) { |
| 7965 | mBackgroundFillerTarget = null; |
| 7966 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BG FILLER " |
| 7967 | + mBackgroundFillerSurface + " HIDE"); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7968 | try { |
| 7969 | mBackgroundFillerSurface.hide(); |
| 7970 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7971 | Slog.e(TAG, "Exception hiding filler surface", e); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7972 | } |
| 7973 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7974 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7975 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7976 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 7977 | mDisplayFrozen || !mPolicy.isScreenOn()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7978 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7979 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7980 | if (!blurring && mBlurShown) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7981 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7982 | + ": HIDE"); |
| 7983 | try { |
| 7984 | mBlurSurface.hide(); |
| 7985 | } catch (IllegalArgumentException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7986 | Slog.w(TAG, "Illegal argument exception hiding blur surface"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7987 | } |
| 7988 | mBlurShown = false; |
| 7989 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7990 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7991 | Slog.e(TAG, "Unhandled exception in Window Manager", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7992 | } |
| 7993 | |
| 7994 | Surface.closeTransaction(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7995 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 7996 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces"); |
| 7997 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 7998 | if (mWatermark != null) { |
| 7999 | mWatermark.drawIfNeeded(); |
| 8000 | } |
| 8001 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8002 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8003 | "With display frozen, orientationChangeComplete=" |
| 8004 | + orientationChangeComplete); |
| 8005 | if (orientationChangeComplete) { |
| 8006 | if (mWindowsFreezingScreen) { |
| 8007 | mWindowsFreezingScreen = false; |
| 8008 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 8009 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8010 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8011 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8012 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8013 | i = mResizingWindows.size(); |
| 8014 | if (i > 0) { |
| 8015 | do { |
| 8016 | i--; |
| 8017 | WindowState win = mResizingWindows.get(i); |
| 8018 | try { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 8019 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| 8020 | "Reporting new frame to " + win + ": " + win.mFrame); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 8021 | int diff = 0; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8022 | boolean configChanged = |
| 8023 | win.mConfiguration != mCurConfiguration |
| 8024 | && (win.mConfiguration == null |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 8025 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); |
| 8026 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) |
| 8027 | && configChanged) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8028 | Slog.i(TAG, "Sending new config to window " + win + ": " |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8029 | + win.mFrame.width() + "x" + win.mFrame.height() |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 8030 | + " / " + mCurConfiguration + " / 0x" |
| 8031 | + Integer.toHexString(diff)); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8032 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 8033 | win.mConfiguration = mCurConfiguration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8034 | win.mClient.resized(win.mFrame.width(), |
| 8035 | win.mFrame.height(), win.mLastContentInsets, |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8036 | win.mLastVisibleInsets, win.mDrawPending, |
| 8037 | configChanged ? win.mConfiguration : null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8038 | win.mContentInsetsChanged = false; |
| 8039 | win.mVisibleInsetsChanged = false; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 8040 | win.mSurfaceResized = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8041 | } catch (RemoteException e) { |
| 8042 | win.mOrientationChanging = false; |
| 8043 | } |
| 8044 | } while (i > 0); |
| 8045 | mResizingWindows.clear(); |
| 8046 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8047 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8048 | // Destroy the surface of any windows that are no longer visible. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8049 | boolean wallpaperDestroyed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8050 | i = mDestroySurface.size(); |
| 8051 | if (i > 0) { |
| 8052 | do { |
| 8053 | i--; |
| 8054 | WindowState win = mDestroySurface.get(i); |
| 8055 | win.mDestroying = false; |
| 8056 | if (mInputMethodWindow == win) { |
| 8057 | mInputMethodWindow = null; |
| 8058 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8059 | if (win == mWallpaperTarget) { |
| 8060 | wallpaperDestroyed = true; |
| 8061 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8062 | win.destroySurfaceLocked(); |
| 8063 | } while (i > 0); |
| 8064 | mDestroySurface.clear(); |
| 8065 | } |
| 8066 | |
| 8067 | // Time to remove any exiting tokens? |
| 8068 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 8069 | WindowToken token = mExitingTokens.get(i); |
| 8070 | if (!token.hasVisible) { |
| 8071 | mExitingTokens.remove(i); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 8072 | if (token.windowType == TYPE_WALLPAPER) { |
| 8073 | mWallpaperTokens.remove(token); |
| 8074 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8075 | } |
| 8076 | } |
| 8077 | |
| 8078 | // Time to remove any exiting applications? |
| 8079 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 8080 | AppWindowToken token = mExitingAppTokens.get(i); |
| 8081 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8082 | // Make sure there is no animation running on this token, |
| 8083 | // so any windows associated with it will be removed as |
| 8084 | // soon as their animations are complete |
| 8085 | token.animation = null; |
| 8086 | token.animating = false; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8087 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 8088 | "performLayout: App token exiting now removed" + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8089 | mAppTokens.remove(token); |
| 8090 | mExitingAppTokens.remove(i); |
| 8091 | } |
| 8092 | } |
| 8093 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8094 | boolean needRelayout = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8095 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8096 | if (!animating && mAppTransitionRunning) { |
| 8097 | // We have finished the animation of an app transition. To do |
| 8098 | // this, we have delayed a lot of operations like showing and |
| 8099 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 8100 | // reflects the correct Z-order, but the window list may now |
| 8101 | // be out of sync with it. So here we will just rebuild the |
| 8102 | // entire app window list. Fun! |
| 8103 | mAppTransitionRunning = false; |
| 8104 | needRelayout = true; |
| 8105 | rebuildAppWindowListLocked(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8106 | assignLayersLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8107 | // Clear information about apps that were moving. |
| 8108 | mToBottomApps.clear(); |
| 8109 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8110 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8111 | if (focusDisplayed) { |
| 8112 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 8113 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8114 | if (wallpaperDestroyed) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 8115 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8116 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8117 | if (needRelayout) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8118 | requestAnimationLocked(0); |
| 8119 | } else if (animating) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8120 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 8121 | } |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 8122 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 8123 | // Finally update all input windows now that the window changes have stabilized. |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 8124 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 8125 | |
Jeff Brown | 8e03b75 | 2010-06-13 19:16:55 -0700 | [diff] [blame] | 8126 | setHoldScreenLocked(holdScreen != null); |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 8127 | if (!mDisplayFrozen) { |
| 8128 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 8129 | mPowerManager.setScreenBrightnessOverride(-1); |
| 8130 | } else { |
| 8131 | mPowerManager.setScreenBrightnessOverride((int) |
| 8132 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 8133 | } |
| 8134 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 8135 | mPowerManager.setButtonBrightnessOverride(-1); |
| 8136 | } else { |
| 8137 | mPowerManager.setButtonBrightnessOverride((int) |
| 8138 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 8139 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 8140 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8141 | if (holdScreen != mHoldingScreenOn) { |
| 8142 | mHoldingScreenOn = holdScreen; |
| 8143 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 8144 | mH.sendMessage(m); |
| 8145 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8146 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8147 | if (mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8148 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8149 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 8150 | LocalPowerManager.BUTTON_EVENT, true); |
| 8151 | mTurnOnScreen = false; |
| 8152 | } |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 8153 | |
Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 8154 | if (screenRotationFinished && mScreenRotationAnimation != null) { |
| 8155 | mScreenRotationAnimation.kill(); |
| 8156 | mScreenRotationAnimation = null; |
| 8157 | } |
| 8158 | |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 8159 | if (updateRotation) { |
| 8160 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation"); |
| 8161 | boolean changed = setRotationUncheckedLocked( |
| 8162 | WindowManagerPolicy.USE_LAST_ROTATION, 0, false); |
| 8163 | if (changed) { |
Dianne Hackborn | 3e4f9d0 | 2011-02-04 14:05:55 -0800 | [diff] [blame] | 8164 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 8165 | } |
| 8166 | } |
| 8167 | |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 8168 | // Check to see if we are now in a state where the screen should |
| 8169 | // be enabled, because the window obscured flags have changed. |
| 8170 | enableScreenIfNeededLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8171 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8172 | |
| 8173 | /** |
| 8174 | * Must be called with the main window manager lock held. |
| 8175 | */ |
| 8176 | void setHoldScreenLocked(boolean holding) { |
| 8177 | boolean state = mHoldingScreenWakeLock.isHeld(); |
| 8178 | if (holding != state) { |
| 8179 | if (holding) { |
| 8180 | mHoldingScreenWakeLock.acquire(); |
| 8181 | } else { |
| 8182 | mPolicy.screenOnStoppedLw(); |
| 8183 | mHoldingScreenWakeLock.release(); |
| 8184 | } |
| 8185 | } |
| 8186 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8187 | |
| 8188 | void requestAnimationLocked(long delay) { |
| 8189 | if (!mAnimationPending) { |
| 8190 | mAnimationPending = true; |
| 8191 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 8192 | } |
| 8193 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8194 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8195 | /** |
| 8196 | * Have the surface flinger show a surface, robustly dealing with |
| 8197 | * error conditions. In particular, if there is not enough memory |
| 8198 | * to show the surface, then we will try to get rid of other surfaces |
| 8199 | * in order to succeed. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8200 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8201 | * @return Returns true if the surface was successfully shown. |
| 8202 | */ |
| 8203 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 8204 | try { |
| 8205 | if (win.mSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8206 | win.mSurfaceShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8207 | win.mSurface.show(); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8208 | if (win.mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8209 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 8210 | "Show surface turning screen on: " + win); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8211 | win.mTurnOnScreen = false; |
| 8212 | mTurnOnScreen = true; |
| 8213 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8214 | } |
| 8215 | return true; |
| 8216 | } catch (RuntimeException e) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 8217 | 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] | 8218 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8219 | |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 8220 | reclaimSomeSurfaceMemoryLocked(win, "show", true); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8221 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8222 | return false; |
| 8223 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8224 | |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 8225 | boolean reclaimSomeSurfaceMemoryLocked(WindowState win, String operation, boolean secure) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8226 | final Surface surface = win.mSurface; |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 8227 | boolean leakedSurface = false; |
| 8228 | boolean killedApps = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8229 | |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8230 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8231 | win.mSession.mPid, operation); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8232 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8233 | if (mForceRemoves == null) { |
| 8234 | mForceRemoves = new ArrayList<WindowState>(); |
| 8235 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8236 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8237 | long callingIdentity = Binder.clearCallingIdentity(); |
| 8238 | try { |
| 8239 | // There was some problem... first, do a sanity check of the |
| 8240 | // window list to make sure we haven't left any dangling surfaces |
| 8241 | // around. |
| 8242 | int N = mWindows.size(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8243 | 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] | 8244 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8245 | WindowState ws = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8246 | if (ws.mSurface != null) { |
| 8247 | if (!mSessions.contains(ws.mSession)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8248 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8249 | + ws + " surface=" + ws.mSurface |
| 8250 | + " token=" + win.mToken |
| 8251 | + " pid=" + ws.mSession.mPid |
| 8252 | + " uid=" + ws.mSession.mUid); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 8253 | if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 8254 | ws.mSurface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8255 | ws.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8256 | ws.mSurface = null; |
| 8257 | mForceRemoves.add(ws); |
| 8258 | i--; |
| 8259 | N--; |
| 8260 | leakedSurface = true; |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 8261 | } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8262 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8263 | + ws + " surface=" + ws.mSurface |
| 8264 | + " token=" + win.mAppToken); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 8265 | if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 8266 | ws.mSurface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8267 | ws.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8268 | ws.mSurface = null; |
| 8269 | leakedSurface = true; |
| 8270 | } |
| 8271 | } |
| 8272 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8273 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8274 | if (!leakedSurface) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8275 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8276 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 8277 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8278 | WindowState ws = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8279 | if (ws.mSurface != null) { |
| 8280 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 8281 | } |
| 8282 | } |
| 8283 | if (pidCandidates.size() > 0) { |
| 8284 | int[] pids = new int[pidCandidates.size()]; |
| 8285 | for (int i=0; i<pids.length; i++) { |
| 8286 | pids[i] = pidCandidates.keyAt(i); |
| 8287 | } |
| 8288 | try { |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 8289 | if (mActivityManager.killPids(pids, "Free memory", secure)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8290 | killedApps = true; |
| 8291 | } |
| 8292 | } catch (RemoteException e) { |
| 8293 | } |
| 8294 | } |
| 8295 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8296 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8297 | if (leakedSurface || killedApps) { |
| 8298 | // We managed to reclaim some memory, so get rid of the trouble |
| 8299 | // surface and ask the app to request another one. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8300 | 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] | 8301 | if (surface != null) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 8302 | if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 8303 | surface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8304 | win.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8305 | win.mSurface = null; |
| 8306 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8307 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8308 | try { |
| 8309 | win.mClient.dispatchGetNewSurface(); |
| 8310 | } catch (RemoteException e) { |
| 8311 | } |
| 8312 | } |
| 8313 | } finally { |
| 8314 | Binder.restoreCallingIdentity(callingIdentity); |
| 8315 | } |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 8316 | |
| 8317 | return leakedSurface || killedApps; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8318 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8319 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 8320 | private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8321 | WindowState newFocus = computeFocusedWindowLocked(); |
| 8322 | if (mCurrentFocus != newFocus) { |
| 8323 | // This check makes sure that we don't already have the focus |
| 8324 | // change message pending. |
| 8325 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 8326 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8327 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8328 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 8329 | final WindowState oldFocus = mCurrentFocus; |
| 8330 | mCurrentFocus = newFocus; |
| 8331 | mLosingFocus.remove(newFocus); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8332 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8333 | final WindowState imWindow = mInputMethodWindow; |
| 8334 | if (newFocus != imWindow && oldFocus != imWindow) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 8335 | if (moveInputMethodWindowsIfNeededLocked( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8336 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 8337 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 8338 | mLayoutNeeded = true; |
| 8339 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8340 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 8341 | performLayoutLockedInner(true /*initial*/, updateInputWindows); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 8342 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 8343 | // Client will do the layout, but we need to assign layers |
| 8344 | // for handleNewWindowLocked() below. |
| 8345 | assignLayersLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8346 | } |
| 8347 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8348 | |
| 8349 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 8350 | // If we defer assigning layers, then the caller is responsible for |
| 8351 | // doing this part. |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 8352 | finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 8353 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8354 | return true; |
| 8355 | } |
| 8356 | return false; |
| 8357 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8358 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 8359 | private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) { |
| 8360 | mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8361 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8362 | |
| 8363 | private WindowState computeFocusedWindowLocked() { |
| 8364 | WindowState result = null; |
| 8365 | WindowState win; |
| 8366 | |
| 8367 | int i = mWindows.size() - 1; |
| 8368 | int nextAppIndex = mAppTokens.size()-1; |
| 8369 | WindowToken nextApp = nextAppIndex >= 0 |
| 8370 | ? mAppTokens.get(nextAppIndex) : null; |
| 8371 | |
| 8372 | while (i >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8373 | win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8374 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8375 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8376 | TAG, "Looking for focus: " + i |
| 8377 | + " = " + win |
| 8378 | + ", flags=" + win.mAttrs.flags |
| 8379 | + ", canReceive=" + win.canReceiveKeys()); |
| 8380 | |
| 8381 | AppWindowToken thisApp = win.mAppToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8382 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8383 | // If this window's application has been removed, just skip it. |
| 8384 | if (thisApp != null && thisApp.removed) { |
| 8385 | i--; |
| 8386 | continue; |
| 8387 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8388 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8389 | // If there is a focused app, don't allow focus to go to any |
| 8390 | // windows below it. If this is an application window, step |
| 8391 | // through the app tokens until we find its app. |
| 8392 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 8393 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 8394 | int origAppIndex = nextAppIndex; |
| 8395 | while (nextAppIndex > 0) { |
| 8396 | if (nextApp == mFocusedApp) { |
| 8397 | // Whoops, we are below the focused app... no focus |
| 8398 | // for you! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8399 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8400 | TAG, "Reached focused app: " + mFocusedApp); |
| 8401 | return null; |
| 8402 | } |
| 8403 | nextAppIndex--; |
| 8404 | nextApp = mAppTokens.get(nextAppIndex); |
| 8405 | if (nextApp == thisApp) { |
| 8406 | break; |
| 8407 | } |
| 8408 | } |
| 8409 | if (thisApp != nextApp) { |
| 8410 | // Uh oh, the app token doesn't exist! This shouldn't |
| 8411 | // happen, but if it does we can get totally hosed... |
| 8412 | // so restart at the original app. |
| 8413 | nextAppIndex = origAppIndex; |
| 8414 | nextApp = mAppTokens.get(nextAppIndex); |
| 8415 | } |
| 8416 | } |
| 8417 | |
| 8418 | // Dispatch to this window if it is wants key events. |
| 8419 | if (win.canReceiveKeys()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8420 | if (DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8421 | TAG, "Found focus @ " + i + " = " + win); |
| 8422 | result = win; |
| 8423 | break; |
| 8424 | } |
| 8425 | |
| 8426 | i--; |
| 8427 | } |
| 8428 | |
| 8429 | return result; |
| 8430 | } |
| 8431 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 8432 | private void startFreezingDisplayLocked(boolean inTransaction) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8433 | if (mDisplayFrozen) { |
| 8434 | return; |
| 8435 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8436 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8437 | mScreenFrozenLock.acquire(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8438 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8439 | long now = SystemClock.uptimeMillis(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8440 | //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8441 | if (mFreezeGcPending != 0) { |
| 8442 | if (now > (mFreezeGcPending+1000)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8443 | //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8444 | mH.removeMessages(H.FORCE_GC); |
| 8445 | Runtime.getRuntime().gc(); |
| 8446 | mFreezeGcPending = now; |
| 8447 | } |
| 8448 | } else { |
| 8449 | mFreezeGcPending = now; |
| 8450 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8451 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8452 | mDisplayFrozen = true; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8453 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 8454 | mInputMonitor.freezeInputDispatchingLw(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8455 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8456 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 8457 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8458 | mNextAppTransitionPackage = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8459 | mAppTransitionReady = true; |
| 8460 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8461 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8462 | if (PROFILE_ORIENTATION) { |
| 8463 | File file = new File("/data/system/frozen"); |
| 8464 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 8465 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 8466 | |
| 8467 | if (CUSTOM_SCREEN_ROTATION) { |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 8468 | if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) { |
| 8469 | mScreenRotationAnimation.kill(); |
| 8470 | mScreenRotationAnimation = null; |
| 8471 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 8472 | if (mScreenRotationAnimation == null) { |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 8473 | mScreenRotationAnimation = new ScreenRotationAnimation(mContext, |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 8474 | mDisplay, mFxSession, inTransaction); |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 8475 | } |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 8476 | if (!mScreenRotationAnimation.hasScreenshot()) { |
| 8477 | Surface.freezeDisplay(0); |
| 8478 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 8479 | } else { |
| 8480 | Surface.freezeDisplay(0); |
| 8481 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8482 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8483 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8484 | private void stopFreezingDisplayLocked() { |
| 8485 | if (!mDisplayFrozen) { |
| 8486 | return; |
| 8487 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8488 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8489 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) { |
| 8490 | return; |
| 8491 | } |
| 8492 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8493 | mDisplayFrozen = false; |
| 8494 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 8495 | if (PROFILE_ORIENTATION) { |
| 8496 | Debug.stopMethodTracing(); |
| 8497 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 8498 | |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 8499 | boolean updateRotation = false; |
| 8500 | |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 8501 | if (CUSTOM_SCREEN_ROTATION && mScreenRotationAnimation != null |
| 8502 | && mScreenRotationAnimation.hasScreenshot()) { |
| 8503 | if (mScreenRotationAnimation.dismiss(mFxSession, MAX_ANIMATION_DURATION, |
| 8504 | mTransitionAnimationScale)) { |
| 8505 | requestAnimationLocked(0); |
| 8506 | } else { |
| 8507 | mScreenRotationAnimation = null; |
| 8508 | updateRotation = true; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 8509 | } |
| 8510 | } else { |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 8511 | if (mScreenRotationAnimation != null) { |
| 8512 | mScreenRotationAnimation.kill(); |
| 8513 | mScreenRotationAnimation = null; |
| 8514 | } |
| 8515 | updateRotation = true; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 8516 | Surface.unfreezeDisplay(0); |
| 8517 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8518 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 8519 | mInputMonitor.thawInputDispatchingLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8520 | |
Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 8521 | boolean configChanged; |
| 8522 | |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 8523 | // While the display is frozen we don't re-compute the orientation |
| 8524 | // to avoid inconsistent states. However, something interesting |
| 8525 | // could have actually changed during that time so re-evaluate it |
| 8526 | // now to catch that. |
Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 8527 | configChanged = updateOrientationFromAppTokensLocked(false); |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 8528 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8529 | // A little kludge: a lot could have happened while the |
| 8530 | // display was frozen, so now that we are coming back we |
| 8531 | // do a gc so that any remote references the system |
| 8532 | // processes holds on others can be released if they are |
| 8533 | // no longer needed. |
| 8534 | mH.removeMessages(H.FORCE_GC); |
| 8535 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 8536 | 2000); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8537 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8538 | mScreenFrozenLock.release(); |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 8539 | |
| 8540 | if (updateRotation) { |
| 8541 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation"); |
Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 8542 | configChanged |= setRotationUncheckedLocked( |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 8543 | WindowManagerPolicy.USE_LAST_ROTATION, 0, false); |
Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 8544 | } |
| 8545 | |
| 8546 | if (configChanged) { |
| 8547 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 8548 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8549 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8550 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 8551 | static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps, |
| 8552 | DisplayMetrics dm) { |
| 8553 | if (index < tokens.length) { |
| 8554 | String str = tokens[index]; |
| 8555 | if (str != null && str.length() > 0) { |
| 8556 | try { |
| 8557 | int val = Integer.parseInt(str); |
| 8558 | return val; |
| 8559 | } catch (Exception e) { |
| 8560 | } |
| 8561 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 8562 | } |
| 8563 | if (defUnits == TypedValue.COMPLEX_UNIT_PX) { |
| 8564 | return defDps; |
| 8565 | } |
| 8566 | int val = (int)TypedValue.applyDimension(defUnits, defDps, dm); |
| 8567 | return val; |
| 8568 | } |
| 8569 | |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 8570 | void createWatermark() { |
| 8571 | if (mWatermark != null) { |
| 8572 | return; |
| 8573 | } |
| 8574 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 8575 | File file = new File("/system/etc/setup.conf"); |
| 8576 | FileInputStream in = null; |
| 8577 | try { |
| 8578 | in = new FileInputStream(file); |
| 8579 | DataInputStream ind = new DataInputStream(in); |
| 8580 | String line = ind.readLine(); |
| 8581 | if (line != null) { |
| 8582 | String[] toks = line.split("%"); |
| 8583 | if (toks != null && toks.length > 0) { |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 8584 | mWatermark = new Watermark(mDisplay, mFxSession, toks); |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 8585 | } |
| 8586 | } |
| 8587 | } catch (FileNotFoundException e) { |
| 8588 | } catch (IOException e) { |
| 8589 | } finally { |
| 8590 | if (in != null) { |
| 8591 | try { |
| 8592 | in.close(); |
| 8593 | } catch (IOException e) { |
| 8594 | } |
| 8595 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 8596 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 8597 | } |
| 8598 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8599 | @Override |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 8600 | public void statusBarVisibilityChanged(int visibility) { |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 8601 | mInputManager.setSystemUiVisibility(visibility); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 8602 | synchronized (mWindowMap) { |
| 8603 | final int N = mWindows.size(); |
| 8604 | for (int i = 0; i < N; i++) { |
| 8605 | WindowState ws = mWindows.get(i); |
| 8606 | try { |
| 8607 | if (ws.getAttrs().hasSystemUiListeners) { |
| 8608 | ws.mClient.dispatchSystemUiVisibilityChanged(visibility); |
| 8609 | } |
| 8610 | } catch (RemoteException e) { |
| 8611 | // so sorry |
| 8612 | } |
| 8613 | } |
| 8614 | } |
| 8615 | } |
| 8616 | |
| 8617 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8618 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 8619 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 8620 | != PackageManager.PERMISSION_GRANTED) { |
| 8621 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 8622 | + Binder.getCallingPid() |
| 8623 | + ", uid=" + Binder.getCallingUid()); |
| 8624 | return; |
| 8625 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8626 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 8627 | mInputManager.dump(pw); |
Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 8628 | pw.println(" "); |
| 8629 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8630 | synchronized(mWindowMap) { |
| 8631 | pw.println("Current Window Manager state:"); |
| 8632 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8633 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8634 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 8635 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8636 | w.dump(pw, " "); |
| 8637 | } |
| 8638 | if (mInputMethodDialogs.size() > 0) { |
| 8639 | pw.println(" "); |
| 8640 | pw.println(" Input method dialogs:"); |
| 8641 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 8642 | WindowState w = mInputMethodDialogs.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8643 | 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] | 8644 | } |
| 8645 | } |
| 8646 | if (mPendingRemove.size() > 0) { |
| 8647 | pw.println(" "); |
| 8648 | pw.println(" Remove pending for:"); |
| 8649 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 8650 | WindowState w = mPendingRemove.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8651 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 8652 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8653 | w.dump(pw, " "); |
| 8654 | } |
| 8655 | } |
| 8656 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 8657 | pw.println(" "); |
| 8658 | pw.println(" Windows force removing:"); |
| 8659 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 8660 | WindowState w = mForceRemoves.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8661 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 8662 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8663 | w.dump(pw, " "); |
| 8664 | } |
| 8665 | } |
| 8666 | if (mDestroySurface.size() > 0) { |
| 8667 | pw.println(" "); |
| 8668 | pw.println(" Windows waiting to destroy their surface:"); |
| 8669 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 8670 | WindowState w = mDestroySurface.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8671 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 8672 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8673 | w.dump(pw, " "); |
| 8674 | } |
| 8675 | } |
| 8676 | if (mLosingFocus.size() > 0) { |
| 8677 | pw.println(" "); |
| 8678 | pw.println(" Windows losing focus:"); |
| 8679 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 8680 | WindowState w = mLosingFocus.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8681 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 8682 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8683 | w.dump(pw, " "); |
| 8684 | } |
| 8685 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 8686 | if (mResizingWindows.size() > 0) { |
| 8687 | pw.println(" "); |
| 8688 | pw.println(" Windows waiting to resize:"); |
| 8689 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 8690 | WindowState w = mResizingWindows.get(i); |
| 8691 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 8692 | pw.print(w); pw.println(":"); |
| 8693 | w.dump(pw, " "); |
| 8694 | } |
| 8695 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8696 | if (mSessions.size() > 0) { |
| 8697 | pw.println(" "); |
| 8698 | pw.println(" All active sessions:"); |
| 8699 | Iterator<Session> it = mSessions.iterator(); |
| 8700 | while (it.hasNext()) { |
| 8701 | Session s = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8702 | pw.print(" Session "); pw.print(s); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8703 | s.dump(pw, " "); |
| 8704 | } |
| 8705 | } |
| 8706 | if (mTokenMap.size() > 0) { |
| 8707 | pw.println(" "); |
| 8708 | pw.println(" All tokens:"); |
| 8709 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 8710 | while (it.hasNext()) { |
| 8711 | WindowToken token = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8712 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8713 | token.dump(pw, " "); |
| 8714 | } |
| 8715 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 8716 | if (mWallpaperTokens.size() > 0) { |
| 8717 | pw.println(" "); |
| 8718 | pw.println(" Wallpaper tokens:"); |
| 8719 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 8720 | WindowToken token = mWallpaperTokens.get(i); |
| 8721 | pw.print(" Wallpaper #"); pw.print(i); |
| 8722 | pw.print(' '); pw.print(token); pw.println(':'); |
| 8723 | token.dump(pw, " "); |
| 8724 | } |
| 8725 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8726 | if (mAppTokens.size() > 0) { |
| 8727 | pw.println(" "); |
| 8728 | pw.println(" Application tokens in Z order:"); |
| 8729 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8730 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 8731 | pw.println(mAppTokens.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8732 | } |
| 8733 | } |
| 8734 | if (mFinishedStarting.size() > 0) { |
| 8735 | pw.println(" "); |
| 8736 | pw.println(" Finishing start of application tokens:"); |
| 8737 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 8738 | WindowToken token = mFinishedStarting.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8739 | pw.print(" Finished Starting #"); pw.print(i); |
| 8740 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8741 | token.dump(pw, " "); |
| 8742 | } |
| 8743 | } |
| 8744 | if (mExitingTokens.size() > 0) { |
| 8745 | pw.println(" "); |
| 8746 | pw.println(" Exiting tokens:"); |
| 8747 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 8748 | WindowToken token = mExitingTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8749 | pw.print(" Exiting #"); pw.print(i); |
| 8750 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8751 | token.dump(pw, " "); |
| 8752 | } |
| 8753 | } |
| 8754 | if (mExitingAppTokens.size() > 0) { |
| 8755 | pw.println(" "); |
| 8756 | pw.println(" Exiting application tokens:"); |
| 8757 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 8758 | WindowToken token = mExitingAppTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8759 | pw.print(" Exiting App #"); pw.print(i); |
| 8760 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8761 | token.dump(pw, " "); |
| 8762 | } |
| 8763 | } |
| 8764 | pw.println(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8765 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 8766 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 8767 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 8768 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 8769 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 8770 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 8771 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 8772 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 8773 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 8774 | } |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 8775 | if (mWindowDetachedWallpaper != null) { |
| 8776 | pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper); |
| 8777 | } |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 8778 | if (mWindowAnimationBackgroundSurface != null) { |
| 8779 | pw.println(" mWindowAnimationBackgroundSurface:"); |
| 8780 | mWindowAnimationBackgroundSurface.printTo(" ", pw); |
| 8781 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8782 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 8783 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 8784 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8785 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 8786 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 8787 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 8788 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 8789 | if (mDimAnimator != null) { |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 8790 | pw.println(" mDimAnimator:"); |
| 8791 | mDimAnimator.printTo(" ", pw); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 8792 | } else { |
Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 8793 | pw.println( " no DimAnimator "); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 8794 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8795 | pw.print(" mInputMethodAnimLayerAdjustment="); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8796 | pw.print(mInputMethodAnimLayerAdjustment); |
| 8797 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 8798 | pw.println(mWallpaperAnimLayerAdjustment); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 8799 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 8800 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8801 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 8802 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8803 | pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); |
| 8804 | pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8805 | pw.print(" mRotation="); pw.print(mRotation); |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 8806 | pw.print(" mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 8807 | pw.print(" mRequestedRotation="); pw.print(mRequestedRotation); |
| 8808 | pw.print(" mAltOrientation="); pw.println(mAltOrientation); |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 8809 | pw.print(" mDeferredRotation="); pw.print(mDeferredRotation); |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 8810 | pw.print(", mDeferredRotationAnimFlags="); pw.println(mDeferredRotationAnimFlags); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8811 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 8812 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 8813 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 8814 | pw.print(" mNextAppTransition=0x"); |
| 8815 | pw.print(Integer.toHexString(mNextAppTransition)); |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 8816 | pw.print(" mAppTransitionReady="); pw.println(mAppTransitionReady); |
| 8817 | pw.print(" mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
| 8818 | pw.print(" mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8819 | if (mNextAppTransitionPackage != null) { |
| 8820 | pw.print(" mNextAppTransitionPackage="); |
| 8821 | pw.print(mNextAppTransitionPackage); |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 8822 | pw.print(" mNextAppTransitionEnter=0x"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8823 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 8824 | pw.print(" mNextAppTransitionExit=0x"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8825 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 8826 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8827 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 8828 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
| 8829 | if (mOpeningApps.size() > 0) { |
| 8830 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 8831 | } |
| 8832 | if (mClosingApps.size() > 0) { |
| 8833 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 8834 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8835 | if (mToTopApps.size() > 0) { |
| 8836 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 8837 | } |
| 8838 | if (mToBottomApps.size() > 0) { |
| 8839 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 8840 | } |
Dianne Hackborn | 87fc308 | 2010-12-03 13:09:12 -0800 | [diff] [blame] | 8841 | if (mDisplay != null) { |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 8842 | pw.print(" Display: init="); pw.print(mInitialDisplayWidth); pw.print("x"); |
| 8843 | pw.print(mInitialDisplayHeight); pw.print(" cur="); |
| 8844 | pw.print(mCurDisplayWidth); pw.print("x"); pw.print(mCurDisplayHeight); |
| 8845 | pw.print(" real="); pw.print(mDisplay.getRealWidth()); |
| 8846 | pw.print("x"); pw.print(mDisplay.getRealHeight()); |
| 8847 | pw.print(" raw="); pw.print(mDisplay.getRawWidth()); |
| 8848 | pw.print("x"); pw.println(mDisplay.getRawHeight()); |
Dianne Hackborn | 87fc308 | 2010-12-03 13:09:12 -0800 | [diff] [blame] | 8849 | } else { |
| 8850 | pw.println(" NO DISPLAY"); |
| 8851 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8852 | pw.println(" Policy:"); |
| 8853 | mPolicy.dump(" ", fd, pw, args); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8854 | } |
| 8855 | } |
| 8856 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8857 | // 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] | 8858 | public void monitor() { |
| 8859 | synchronized (mWindowMap) { } |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 8860 | synchronized (mKeyguardTokenWatcher) { } |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 8861 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8862 | |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 8863 | public interface OnHardKeyboardStatusChangeListener { |
| 8864 | public void onHardKeyboardStatusChange(boolean available, boolean enabled); |
| 8865 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8866 | } |