The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server; |
| 18 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
| 20 | import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; |
| 21 | import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 22 | import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND; |
| 24 | import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 25 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 27 | import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 28 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 30 | import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 32 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 33 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 34 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 35 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | |
| 37 | import com.android.internal.app.IBatteryStats; |
| 38 | import com.android.internal.policy.PolicyManager; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 39 | import com.android.internal.policy.impl.PhoneWindowManager; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 40 | import com.android.internal.view.BaseInputHandler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import com.android.internal.view.IInputContext; |
| 42 | import com.android.internal.view.IInputMethodClient; |
| 43 | import com.android.internal.view.IInputMethodManager; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 44 | import com.android.internal.view.WindowManagerPolicyThread; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import com.android.server.am.BatteryStatsService; |
| 46 | |
| 47 | import android.Manifest; |
| 48 | import android.app.ActivityManagerNative; |
| 49 | import android.app.IActivityManager; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 50 | import android.app.admin.DevicePolicyManager; |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 51 | import android.content.BroadcastReceiver; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 52 | import android.content.ClipData; |
| 53 | import android.content.ClipDescription; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | import android.content.Context; |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 55 | import android.content.Intent; |
| 56 | import android.content.IntentFilter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | import android.content.pm.ActivityInfo; |
| 58 | import android.content.pm.PackageManager; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 59 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | import android.content.res.Configuration; |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 61 | import android.content.res.Resources; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 62 | import android.graphics.Bitmap; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 63 | import android.graphics.Canvas; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | import android.graphics.Matrix; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 65 | import android.graphics.Paint; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | import android.graphics.PixelFormat; |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 67 | import android.graphics.PorterDuff; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | import android.graphics.Rect; |
| 69 | import android.graphics.Region; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 70 | import android.graphics.Typeface; |
| 71 | import android.graphics.Paint.FontMetricsInt; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | import android.os.BatteryStats; |
| 73 | import android.os.Binder; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 74 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | import android.os.Debug; |
| 76 | import android.os.Handler; |
| 77 | import android.os.IBinder; |
| 78 | import android.os.LocalPowerManager; |
| 79 | import android.os.Looper; |
| 80 | import android.os.Message; |
| 81 | import android.os.Parcel; |
| 82 | import android.os.ParcelFileDescriptor; |
| 83 | import android.os.Power; |
| 84 | import android.os.PowerManager; |
| 85 | import android.os.Process; |
| 86 | import android.os.RemoteException; |
| 87 | import android.os.ServiceManager; |
Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 88 | import android.os.StrictMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | import android.os.SystemClock; |
| 90 | import android.os.SystemProperties; |
| 91 | import android.os.TokenWatcher; |
| 92 | import android.provider.Settings; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 93 | import android.util.DisplayMetrics; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | import android.util.EventLog; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 95 | import android.util.Log; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 96 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | import android.util.SparseIntArray; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 98 | import android.util.TypedValue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | import android.view.Display; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 100 | import android.view.DragEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | import android.view.Gravity; |
| 102 | import android.view.IApplicationToken; |
| 103 | import android.view.IOnKeyguardExitResult; |
| 104 | import android.view.IRotationWatcher; |
| 105 | import android.view.IWindow; |
| 106 | import android.view.IWindowManager; |
| 107 | import android.view.IWindowSession; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 108 | import android.view.InputChannel; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 109 | import android.view.InputDevice; |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 110 | import android.view.InputEvent; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 111 | import android.view.InputHandler; |
| 112 | import android.view.InputQueue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | import android.view.KeyEvent; |
| 114 | import android.view.MotionEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | import android.view.Surface; |
| 116 | import android.view.SurfaceSession; |
| 117 | import android.view.View; |
| 118 | import android.view.ViewTreeObserver; |
| 119 | import android.view.WindowManager; |
| 120 | import android.view.WindowManagerImpl; |
| 121 | import android.view.WindowManagerPolicy; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 122 | import android.view.Surface.OutOfResourcesException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | import android.view.WindowManager.LayoutParams; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 124 | import android.view.animation.AccelerateInterpolator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | import android.view.animation.Animation; |
| 126 | import android.view.animation.AnimationUtils; |
| 127 | import android.view.animation.Transformation; |
| 128 | |
| 129 | import java.io.BufferedWriter; |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 130 | import java.io.DataInputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | import java.io.File; |
| 132 | import java.io.FileDescriptor; |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 133 | import java.io.FileInputStream; |
| 134 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | import java.io.IOException; |
| 136 | import java.io.OutputStream; |
| 137 | import java.io.OutputStreamWriter; |
| 138 | import java.io.PrintWriter; |
| 139 | import java.io.StringWriter; |
| 140 | import java.net.Socket; |
| 141 | import java.util.ArrayList; |
| 142 | import java.util.HashMap; |
| 143 | import java.util.HashSet; |
| 144 | import java.util.Iterator; |
| 145 | import java.util.List; |
| 146 | |
| 147 | /** {@hide} */ |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 148 | public class WindowManagerService extends IWindowManager.Stub |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 149 | implements Watchdog.Monitor { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | static final String TAG = "WindowManager"; |
| 151 | static final boolean DEBUG = false; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 152 | static final boolean DEBUG_ADD_REMOVE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | static final boolean DEBUG_FOCUS = false; |
| 154 | static final boolean DEBUG_ANIM = false; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 155 | static final boolean DEBUG_LAYOUT = false; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 156 | static final boolean DEBUG_RESIZE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | static final boolean DEBUG_LAYERS = false; |
| 158 | static final boolean DEBUG_INPUT = false; |
| 159 | static final boolean DEBUG_INPUT_METHOD = false; |
| 160 | static final boolean DEBUG_VISIBILITY = false; |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 161 | static final boolean DEBUG_WINDOW_MOVEMENT = false; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 162 | static final boolean DEBUG_TOKEN_MOVEMENT = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | static final boolean DEBUG_ORIENTATION = false; |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 164 | static final boolean DEBUG_CONFIGURATION = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 166 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 167 | static final boolean DEBUG_REORDER = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 168 | static final boolean DEBUG_WALLPAPER = false; |
Christopher Tate | 994ef92 | 2011-01-12 20:06:07 -0800 | [diff] [blame] | 169 | static final boolean DEBUG_DRAG = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | static final boolean SHOW_TRANSACTIONS = false; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 171 | static final boolean HIDE_STACK_CRAWLS = true; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 172 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | static final boolean PROFILE_ORIENTATION = false; |
| 174 | static final boolean BLUR = true; |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 175 | static final boolean localLOGV = DEBUG; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 176 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | /** How much to multiply the policy's type layer, to reserve room |
| 178 | * for multiple windows of the same type and Z-ordering adjustment |
| 179 | * with TYPE_LAYER_OFFSET. */ |
| 180 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 181 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 183 | * or below others in the same layer. */ |
| 184 | static final int TYPE_LAYER_OFFSET = 1000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 185 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | /** How much to increment the layer for each window, to reserve room |
| 187 | * for effect surfaces between them. |
| 188 | */ |
| 189 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | /** The maximum length we will accept for a loaded animation duration: |
| 192 | * this is 10 seconds. |
| 193 | */ |
| 194 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 195 | |
| 196 | /** Amount of time (in milliseconds) to animate the dim surface from one |
| 197 | * value to another, when no window animation is driving it. |
| 198 | */ |
| 199 | static final int DEFAULT_DIM_DURATION = 200; |
| 200 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 201 | /** Amount of time (in milliseconds) to animate the fade-in-out transition for |
| 202 | * compatible windows. |
| 203 | */ |
| 204 | static final int DEFAULT_FADE_IN_OUT_DURATION = 400; |
| 205 | |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 206 | /** |
| 207 | * If true, the window manager will do its own custom freezing and general |
| 208 | * management of the screen during rotation. |
| 209 | */ |
| 210 | static final boolean CUSTOM_SCREEN_ROTATION = true; |
| 211 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 212 | // Maximum number of milliseconds to wait for input event injection. |
| 213 | // FIXME is this value reasonable? |
| 214 | private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000; |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 215 | |
| 216 | // Maximum number of milliseconds to wait for input devices to be enumerated before |
| 217 | // proceding with safe mode detection. |
| 218 | private static final int INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS = 1000; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 219 | |
| 220 | // Default input dispatching timeout in nanoseconds. |
| 221 | private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 222 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 224 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 225 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 226 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 227 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | private static final String SYSTEM_SECURE = "ro.secure"; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 229 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | |
| 231 | /** |
| 232 | * Condition waited on by {@link #reenableKeyguard} to know the call to |
| 233 | * the window policy has finished. |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 234 | * This is set to true only if mKeyguardTokenWatcher.acquired() has |
| 235 | * actually disabled the keyguard. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 236 | */ |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 237 | private boolean mKeyguardDisabled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 239 | private static final int ALLOW_DISABLE_YES = 1; |
| 240 | private static final int ALLOW_DISABLE_NO = 0; |
| 241 | private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager |
| 242 | private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher |
| 243 | |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 244 | final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher( |
| 245 | new Handler(), "WindowManagerService.mKeyguardTokenWatcher") { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | public void acquired() { |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 247 | if (shouldAllowDisableKeyguard()) { |
| 248 | mPolicy.enableKeyguard(false); |
| 249 | mKeyguardDisabled = true; |
| 250 | } else { |
| 251 | Log.v(TAG, "Not disabling keyguard since device policy is enforced"); |
| 252 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | } |
| 254 | public void released() { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 255 | mPolicy.enableKeyguard(true); |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 256 | synchronized (mKeyguardTokenWatcher) { |
| 257 | mKeyguardDisabled = false; |
| 258 | mKeyguardTokenWatcher.notifyAll(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | }; |
| 262 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 263 | final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 264 | @Override |
| 265 | public void onReceive(Context context, Intent intent) { |
| 266 | mPolicy.enableKeyguard(true); |
| 267 | synchronized(mKeyguardTokenWatcher) { |
| 268 | // lazily evaluate this next time we're asked to disable keyguard |
| 269 | mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; |
| 270 | mKeyguardDisabled = false; |
| 271 | } |
| 272 | } |
| 273 | }; |
| 274 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | final Context mContext; |
| 276 | |
| 277 | final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 278 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 279 | final boolean mLimitedAlphaCompositing; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 280 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 281 | final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 282 | |
| 283 | final IActivityManager mActivityManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 284 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 285 | final IBatteryStats mBatteryStats; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 286 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 287 | /** |
| 288 | * All currently active sessions with clients. |
| 289 | */ |
| 290 | final HashSet<Session> mSessions = new HashSet<Session>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 291 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | /** |
| 293 | * Mapping from an IWindow IBinder to the server's Window object. |
| 294 | * This is also used as the lock for all of our state. |
| 295 | */ |
| 296 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 297 | |
| 298 | /** |
| 299 | * Mapping from a token IBinder to a WindowToken object. |
| 300 | */ |
| 301 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 302 | new HashMap<IBinder, WindowToken>(); |
| 303 | |
| 304 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 305 | * Window tokens that are in the process of exiting, but still |
| 306 | * on screen for animations. |
| 307 | */ |
| 308 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 309 | |
| 310 | /** |
| 311 | * Z-ordered (bottom-most first) list of all application tokens, for |
| 312 | * controlling the ordering of windows in different applications. This |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 313 | * contains AppWindowToken objects. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | */ |
| 315 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
| 316 | |
| 317 | /** |
| 318 | * Application tokens that are in the process of exiting, but still |
| 319 | * on screen for animations. |
| 320 | */ |
| 321 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 322 | |
| 323 | /** |
| 324 | * List of window tokens that have finished starting their application, |
| 325 | * and now need to have the policy remove their windows. |
| 326 | */ |
| 327 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 328 | |
| 329 | /** |
| 330 | * Z-ordered (bottom-most first) list of all Window objects. |
| 331 | */ |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 332 | final ArrayList<WindowState> mWindows = new ArrayList<WindowState>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 | |
| 334 | /** |
| 335 | * Windows that are being resized. Used so we can tell the client about |
| 336 | * the resize after closing the transaction in which we resized the |
| 337 | * underlying surface. |
| 338 | */ |
| 339 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 340 | |
| 341 | /** |
| 342 | * Windows whose animations have ended and now must be removed. |
| 343 | */ |
| 344 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 345 | |
| 346 | /** |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 347 | * Used when processing mPendingRemove to avoid working on the original array. |
| 348 | */ |
| 349 | WindowState[] mPendingRemoveTmp = new WindowState[20]; |
| 350 | |
| 351 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 352 | * Windows whose surface should be destroyed. |
| 353 | */ |
| 354 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 355 | |
| 356 | /** |
| 357 | * Windows that have lost input focus and are waiting for the new |
| 358 | * focus window to be displayed before they are told about this. |
| 359 | */ |
| 360 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 361 | |
| 362 | /** |
| 363 | * This is set when we have run out of memory, and will either be an empty |
| 364 | * list or contain windows that need to be force removed. |
| 365 | */ |
| 366 | ArrayList<WindowState> mForceRemoves; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 367 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 368 | /** |
| 369 | * Used when rebuilding window list to keep track of windows that have |
| 370 | * been removed. |
| 371 | */ |
| 372 | WindowState[] mRebuildTmp = new WindowState[20]; |
| 373 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | IInputMethodManager mInputMethodManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 375 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | SurfaceSession mFxSession; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 377 | private DimAnimator mDimAnimator = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | Surface mBlurSurface; |
| 379 | boolean mBlurShown; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 380 | Watermark mWatermark; |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 381 | StrictModeFlash mStrictModeFlash; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 382 | ScreenRotationAnimation mScreenRotationAnimation; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 383 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 384 | int mTransactionSequence = 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 385 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 386 | final float[] mTmpFloats = new float[9]; |
| 387 | |
| 388 | boolean mSafeMode; |
| 389 | boolean mDisplayEnabled = false; |
| 390 | boolean mSystemBooted = false; |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 391 | int mInitialDisplayWidth = 0; |
| 392 | int mInitialDisplayHeight = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 393 | int mRotation = 0; |
| 394 | int mRequestedRotation = 0; |
| 395 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 396 | int mLastRotationFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | ArrayList<IRotationWatcher> mRotationWatchers |
| 398 | = new ArrayList<IRotationWatcher>(); |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame^] | 399 | int mDeferredRotation; |
| 400 | int mDeferredRotationAnimFlags; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 401 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | boolean mLayoutNeeded = true; |
| 403 | boolean mAnimationPending = false; |
| 404 | boolean mDisplayFrozen = false; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 405 | boolean mWaitingForConfig = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 406 | boolean mWindowsFreezingScreen = false; |
| 407 | long mFreezeGcPending = 0; |
| 408 | int mAppsFreezingScreen = 0; |
| 409 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 410 | int mLayoutSeq = 0; |
| 411 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 412 | // State while inside of layoutAndPlaceSurfacesLocked(). |
| 413 | boolean mFocusMayChange; |
| 414 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 415 | Configuration mCurConfiguration = new Configuration(); |
| 416 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 | // This is held as long as we have the screen frozen, to give us time to |
| 418 | // perform a rotation animation when turning off shows the lock screen which |
| 419 | // changes the orientation. |
| 420 | PowerManager.WakeLock mScreenFrozenLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 421 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 422 | // State management of app transitions. When we are preparing for a |
| 423 | // transition, mNextAppTransition will be the kind of transition to |
| 424 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 425 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 426 | // made visible or hidden at the next transition. |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 427 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 428 | String mNextAppTransitionPackage; |
| 429 | int mNextAppTransitionEnter; |
| 430 | int mNextAppTransitionExit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 431 | boolean mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 432 | boolean mAppTransitionRunning = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | boolean mAppTransitionTimeout = false; |
| 434 | boolean mStartingIconInTransition = false; |
| 435 | boolean mSkipAppTransitionAnimation = false; |
| 436 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 437 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 438 | final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>(); |
| 439 | final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 440 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 441 | Display mDisplay; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 442 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | H mH = new H(); |
| 444 | |
| 445 | WindowState mCurrentFocus = null; |
| 446 | WindowState mLastFocus = null; |
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 | // This just indicates the window the input method is on top of, not |
| 449 | // necessarily the window its input is going to. |
| 450 | WindowState mInputMethodTarget = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | boolean mInputMethodTargetWaitingAnim; |
| 452 | int mInputMethodAnimLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 453 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 454 | WindowState mInputMethodWindow = null; |
| 455 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 456 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 457 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 458 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 459 | // If non-null, this is the currently visible window that is associated |
| 460 | // with the wallpaper. |
| 461 | WindowState mWallpaperTarget = null; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 462 | // If non-null, we are in the middle of animating from one wallpaper target |
| 463 | // to another, and this is the lower one in Z-order. |
| 464 | WindowState mLowerWallpaperTarget = null; |
| 465 | // If non-null, we are in the middle of animating from one wallpaper target |
| 466 | // to another, and this is the higher one in Z-order. |
| 467 | WindowState mUpperWallpaperTarget = null; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 468 | // Window currently running an animation that has requested it be detached |
| 469 | // from the wallpaper. This means we need to ensure the wallpaper is |
| 470 | // visible behind it in case it animates in a way that would allow it to be |
| 471 | // seen. |
| 472 | WindowState mWindowDetachedWallpaper = null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 473 | int mWallpaperAnimLayerAdjustment; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 474 | float mLastWallpaperX = -1; |
| 475 | float mLastWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 476 | float mLastWallpaperXStep = -1; |
| 477 | float mLastWallpaperYStep = -1; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 478 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 479 | // changing its scroll position. |
| 480 | WindowState mWaitingOnWallpaper; |
| 481 | // The last time we had a timeout when waiting for a wallpaper. |
| 482 | long mLastWallpaperTimeoutTime; |
| 483 | // We give a wallpaper up to 150ms to finish scrolling. |
| 484 | static final long WALLPAPER_TIMEOUT = 150; |
| 485 | // Time we wait after a timeout before trying to wait again. |
| 486 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 487 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 488 | AppWindowToken mFocusedApp = null; |
| 489 | |
| 490 | PowerManagerService mPowerManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 491 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 492 | float mWindowAnimationScale = 1.0f; |
| 493 | float mTransitionAnimationScale = 1.0f; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 494 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 495 | final InputManager mInputManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | |
| 497 | // Who is holding the screen on. |
| 498 | Session mHoldingScreenOn; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 499 | PowerManager.WakeLock mHoldingScreenWakeLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 500 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 501 | boolean mTurnOnScreen; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 502 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | /** |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 504 | * Drag/drop state |
| 505 | */ |
| 506 | class DragState { |
| 507 | IBinder mToken; |
| 508 | Surface mSurface; |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 509 | int mFlags; |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 510 | IBinder mLocalWin; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 511 | ClipData mData; |
| 512 | ClipDescription mDataDescription; |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 513 | boolean mDragResult; |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 514 | float mCurrentX, mCurrentY; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 515 | float mThumbOffsetX, mThumbOffsetY; |
| 516 | InputChannel mServerChannel, mClientChannel; |
| 517 | WindowState mTargetWindow; |
| 518 | ArrayList<WindowState> mNotifiedWindows; |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 519 | boolean mDragInProgress; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 520 | |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 521 | private final Region mTmpRegion = new Region(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 522 | |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 523 | DragState(IBinder token, Surface surface, int flags, IBinder localWin) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 524 | mToken = token; |
| 525 | mSurface = surface; |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 526 | mFlags = flags; |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 527 | mLocalWin = localWin; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 528 | mNotifiedWindows = new ArrayList<WindowState>(); |
| 529 | } |
| 530 | |
| 531 | void reset() { |
| 532 | if (mSurface != null) { |
| 533 | mSurface.destroy(); |
| 534 | } |
| 535 | mSurface = null; |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 536 | mFlags = 0; |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 537 | mLocalWin = null; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 538 | mToken = null; |
| 539 | mData = null; |
| 540 | mThumbOffsetX = mThumbOffsetY = 0; |
| 541 | mNotifiedWindows = null; |
| 542 | } |
| 543 | |
| 544 | void register() { |
| 545 | if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel"); |
| 546 | if (mClientChannel != null) { |
| 547 | Slog.e(TAG, "Duplicate register of drag input channel"); |
| 548 | } else { |
| 549 | InputChannel[] channels = InputChannel.openInputChannelPair("drag"); |
| 550 | mServerChannel = channels[0]; |
| 551 | mClientChannel = channels[1]; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 552 | mInputManager.registerInputChannel(mServerChannel, null); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 553 | InputQueue.registerInputChannel(mClientChannel, mDragInputHandler, |
| 554 | mH.getLooper().getQueue()); |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | void unregister() { |
| 559 | if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel"); |
| 560 | if (mClientChannel == null) { |
| 561 | Slog.e(TAG, "Unregister of nonexistent drag input channel"); |
| 562 | } else { |
| 563 | mInputManager.unregisterInputChannel(mServerChannel); |
| 564 | InputQueue.unregisterInputChannel(mClientChannel); |
| 565 | mClientChannel.dispose(); |
Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 566 | mServerChannel.dispose(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 567 | mClientChannel = null; |
| 568 | mServerChannel = null; |
| 569 | } |
| 570 | } |
| 571 | |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 572 | int getDragLayerLw() { |
| 573 | return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG) |
| 574 | * TYPE_LAYER_MULTIPLIER |
| 575 | + TYPE_LAYER_OFFSET; |
| 576 | } |
| 577 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 578 | /* call out to each visible window/session informing it about the drag |
| 579 | */ |
Chris Tate | b8203e9 | 2010-10-12 14:23:21 -0700 | [diff] [blame] | 580 | void broadcastDragStartedLw(final float touchX, final float touchY) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 581 | // Cache a base-class instance of the clip metadata so that parceling |
| 582 | // works correctly in calling out to the apps. |
Christopher Tate | 1fc014f | 2011-01-19 12:56:26 -0800 | [diff] [blame] | 583 | mDataDescription = (mData != null) ? mData.getDescription() : null; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 584 | mNotifiedWindows.clear(); |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 585 | mDragInProgress = true; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 586 | |
| 587 | if (DEBUG_DRAG) { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 588 | Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")"); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 589 | } |
| 590 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 591 | final int N = mWindows.size(); |
| 592 | for (int i = 0; i < N; i++) { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 593 | sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 594 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the |
| 598 | * designated window is potentially a drop recipient. There are race situations |
| 599 | * around DRAG_ENDED broadcast, so we make sure that once we've declared that |
| 600 | * the drag has ended, we never send out another DRAG_STARTED for this drag action. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 601 | * |
| 602 | * This method clones the 'event' parameter if it's being delivered to the same |
| 603 | * process, so it's safe for the caller to call recycle() on the event afterwards. |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 604 | */ |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 605 | private void sendDragStartedLw(WindowState newWin, float touchX, float touchY, |
| 606 | ClipDescription desc) { |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 607 | // Don't actually send the event if the drag is supposed to be pinned |
| 608 | // to the originating window but 'newWin' is not that window. |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 609 | if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) { |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 610 | final IBinder winBinder = newWin.mClient.asBinder(); |
| 611 | if (winBinder != mLocalWin) { |
| 612 | if (DEBUG_DRAG) { |
| 613 | Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin); |
| 614 | } |
| 615 | return; |
| 616 | } |
| 617 | } |
| 618 | |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 619 | if (mDragInProgress && newWin.isPotentialDragTarget()) { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 620 | DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED, |
| 621 | touchX - newWin.mFrame.left, touchY - newWin.mFrame.top, |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 622 | null, desc, null, false); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 623 | try { |
| 624 | newWin.mClient.dispatchDragEvent(event); |
| 625 | // track each window that we've notified that the drag is starting |
| 626 | mNotifiedWindows.add(newWin); |
| 627 | } catch (RemoteException e) { |
| 628 | Slog.w(TAG, "Unable to drag-start window " + newWin); |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 629 | } finally { |
| 630 | // if the callee was local, the dispatch has already recycled the event |
| 631 | if (Process.myPid() != newWin.mSession.mPid) { |
| 632 | event.recycle(); |
| 633 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 634 | } |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | /* helper - construct and send a DRAG_STARTED event only if the window has not |
| 639 | * previously been notified, i.e. it became visible after the drag operation |
| 640 | * was begun. This is a rare case. |
| 641 | */ |
| 642 | private void sendDragStartedIfNeededLw(WindowState newWin) { |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 643 | if (mDragInProgress) { |
| 644 | // If we have sent the drag-started, we needn't do so again |
| 645 | for (WindowState ws : mNotifiedWindows) { |
| 646 | if (ws == newWin) { |
| 647 | return; |
| 648 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 649 | } |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 650 | if (DEBUG_DRAG) { |
Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 651 | Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin); |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 652 | } |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 653 | sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 654 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 655 | } |
| 656 | |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 657 | void broadcastDragEndedLw() { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 658 | if (DEBUG_DRAG) { |
| 659 | Slog.d(TAG, "broadcasting DRAG_ENDED"); |
| 660 | } |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 661 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED, |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 662 | 0, 0, null, null, null, mDragResult); |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 663 | for (WindowState ws: mNotifiedWindows) { |
| 664 | try { |
| 665 | ws.mClient.dispatchDragEvent(evt); |
| 666 | } catch (RemoteException e) { |
| 667 | Slog.w(TAG, "Unable to drag-end window " + ws); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 668 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 669 | } |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 670 | mNotifiedWindows.clear(); |
| 671 | mDragInProgress = false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 672 | evt.recycle(); |
| 673 | } |
| 674 | |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 675 | void endDragLw() { |
| 676 | mDragState.broadcastDragEndedLw(); |
| 677 | |
| 678 | // stop intercepting input |
| 679 | mDragState.unregister(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 680 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 681 | mInputMonitor.updateInputWindowsLw(); |
| 682 | |
| 683 | // free our resources and drop all the object references |
| 684 | mDragState.reset(); |
| 685 | mDragState = null; |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 686 | |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame^] | 687 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-drag rotation"); |
| 688 | boolean changed = setRotationUncheckedLocked( |
| 689 | WindowManagerPolicy.USE_LAST_ROTATION, 0, false); |
| 690 | if (changed) { |
| 691 | sendNewConfiguration(); |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 692 | } |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 693 | } |
| 694 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 695 | void notifyMoveLw(float x, float y) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 696 | final int myPid = Process.myPid(); |
| 697 | |
| 698 | // Move the surface to the given touch |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 699 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION notifyMoveLw"); |
Christopher Tate | f01af75 | 2011-01-19 16:22:07 -0800 | [diff] [blame] | 700 | Surface.openTransaction(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 701 | try { |
| 702 | mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY)); |
| 703 | } finally { |
Christopher Tate | f01af75 | 2011-01-19 16:22:07 -0800 | [diff] [blame] | 704 | Surface.closeTransaction(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 705 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION notifyMoveLw"); |
| 706 | } |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 707 | |
| 708 | // Tell the affected window |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 709 | WindowState touchedWin = getTouchedWinAtPointLw(x, y); |
Christopher Tate | f01af75 | 2011-01-19 16:22:07 -0800 | [diff] [blame] | 710 | if (touchedWin == null) { |
| 711 | if (DEBUG_DRAG) Slog.d(TAG, "No touched win at x=" + x + " y=" + y); |
| 712 | return; |
| 713 | } |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 714 | if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) { |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 715 | final IBinder touchedBinder = touchedWin.mClient.asBinder(); |
| 716 | if (touchedBinder != mLocalWin) { |
| 717 | // This drag is pinned only to the originating window, but the drag |
| 718 | // point is outside that window. Pretend it's over empty space. |
| 719 | touchedWin = null; |
| 720 | } |
| 721 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 722 | try { |
| 723 | // have we dragged over a new window? |
| 724 | if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) { |
| 725 | if (DEBUG_DRAG) { |
| 726 | Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow); |
| 727 | } |
| 728 | // force DRAG_EXITED_EVENT if appropriate |
| 729 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED, |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 730 | x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top, |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 731 | null, null, null, false); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 732 | mTargetWindow.mClient.dispatchDragEvent(evt); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 733 | if (myPid != mTargetWindow.mSession.mPid) { |
| 734 | evt.recycle(); |
| 735 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 736 | } |
| 737 | if (touchedWin != null) { |
Chris Tate | 9d1ab88 | 2010-11-02 15:55:39 -0700 | [diff] [blame] | 738 | if (false && DEBUG_DRAG) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 739 | Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin); |
| 740 | } |
| 741 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION, |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 742 | x - touchedWin.mFrame.left, y - touchedWin.mFrame.top, |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 743 | null, null, null, false); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 744 | touchedWin.mClient.dispatchDragEvent(evt); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 745 | if (myPid != touchedWin.mSession.mPid) { |
| 746 | evt.recycle(); |
| 747 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 748 | } |
| 749 | } catch (RemoteException e) { |
| 750 | Slog.w(TAG, "can't send drag notification to windows"); |
| 751 | } |
| 752 | mTargetWindow = touchedWin; |
| 753 | } |
| 754 | |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 755 | // Tell the drop target about the data. Returns 'true' if we can immediately |
| 756 | // dispatch the global drag-ended message, 'false' if we need to wait for a |
| 757 | // result from the recipient. |
| 758 | boolean notifyDropLw(float x, float y) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 759 | WindowState touchedWin = getTouchedWinAtPointLw(x, y); |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 760 | if (touchedWin == null) { |
| 761 | // "drop" outside a valid window -- no recipient to apply a |
| 762 | // timeout to, and we can send the drag-ended message immediately. |
| 763 | mDragResult = false; |
| 764 | return true; |
| 765 | } |
| 766 | |
| 767 | if (DEBUG_DRAG) { |
| 768 | Slog.d(TAG, "sending DROP to " + touchedWin); |
| 769 | } |
| 770 | final int myPid = Process.myPid(); |
| 771 | final IBinder token = touchedWin.mClient.asBinder(); |
| 772 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP, |
| 773 | x - touchedWin.mFrame.left, y - touchedWin.mFrame.top, |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 774 | null, null, mData, false); |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 775 | try { |
| 776 | touchedWin.mClient.dispatchDragEvent(evt); |
| 777 | |
| 778 | // 5 second timeout for this window to respond to the drop |
| 779 | mH.removeMessages(H.DRAG_END_TIMEOUT, token); |
| 780 | Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token); |
| 781 | mH.sendMessageDelayed(msg, 5000); |
| 782 | } catch (RemoteException e) { |
| 783 | Slog.w(TAG, "can't send drop notification to win " + touchedWin); |
| 784 | return true; |
| 785 | } finally { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 786 | if (myPid != touchedWin.mSession.mPid) { |
| 787 | evt.recycle(); |
| 788 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 789 | } |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 790 | mToken = token; |
| 791 | return false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | // Find the visible, touch-deliverable window under the given point |
| 795 | private WindowState getTouchedWinAtPointLw(float xf, float yf) { |
| 796 | WindowState touchedWin = null; |
| 797 | final int x = (int) xf; |
| 798 | final int y = (int) yf; |
| 799 | final ArrayList<WindowState> windows = mWindows; |
| 800 | final int N = windows.size(); |
| 801 | for (int i = N - 1; i >= 0; i--) { |
| 802 | WindowState child = windows.get(i); |
| 803 | final int flags = child.mAttrs.flags; |
| 804 | if (!child.isVisibleLw()) { |
| 805 | // not visible == don't tell about drags |
| 806 | continue; |
| 807 | } |
| 808 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 809 | // not touchable == don't tell about drags |
| 810 | continue; |
| 811 | } |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 812 | |
| 813 | child.getTouchableRegion(mTmpRegion); |
| 814 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 815 | final int touchFlags = flags & |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 816 | (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 817 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
| 818 | if (mTmpRegion.contains(x, y) || touchFlags == 0) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 819 | // Found it |
| 820 | touchedWin = child; |
| 821 | break; |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | return touchedWin; |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | DragState mDragState = null; |
| 830 | private final InputHandler mDragInputHandler = new BaseInputHandler() { |
| 831 | @Override |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 832 | public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) { |
| 833 | boolean handled = false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 834 | try { |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 835 | if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0 |
| 836 | && mDragState != null) { |
| 837 | boolean endDrag = false; |
| 838 | final float newX = event.getRawX(); |
| 839 | final float newY = event.getRawY(); |
| 840 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 841 | switch (event.getAction()) { |
| 842 | case MotionEvent.ACTION_DOWN: { |
| 843 | if (DEBUG_DRAG) { |
| 844 | Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer"); |
| 845 | } |
| 846 | } break; |
| 847 | |
| 848 | case MotionEvent.ACTION_MOVE: { |
| 849 | synchronized (mWindowMap) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 850 | // move the surface and tell the involved window(s) where we are |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 851 | mDragState.notifyMoveLw(newX, newY); |
| 852 | } |
| 853 | } break; |
| 854 | |
| 855 | case MotionEvent.ACTION_UP: { |
| 856 | if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at " |
| 857 | + newX + "," + newY); |
| 858 | synchronized (mWindowMap) { |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 859 | endDrag = mDragState.notifyDropLw(newX, newY); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 860 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 861 | } break; |
| 862 | |
| 863 | case MotionEvent.ACTION_CANCEL: { |
| 864 | if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!"); |
| 865 | endDrag = true; |
| 866 | } break; |
| 867 | } |
| 868 | |
| 869 | if (endDrag) { |
| 870 | if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state"); |
| 871 | // tell all the windows that the drag has ended |
Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 872 | synchronized (mWindowMap) { |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 873 | mDragState.endDragLw(); |
Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 874 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 875 | } |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 876 | |
| 877 | handled = true; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 878 | } |
| 879 | } catch (Exception e) { |
| 880 | Slog.e(TAG, "Exception caught by drag handleMotion", e); |
| 881 | } finally { |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 882 | finishedCallback.finished(handled); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 883 | } |
| 884 | } |
| 885 | }; |
| 886 | |
| 887 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 888 | * Whether the UI is currently running in touch mode (not showing |
| 889 | * navigational focus because the user is directly pressing the screen). |
| 890 | */ |
| 891 | boolean mInTouchMode = false; |
| 892 | |
| 893 | private ViewServer mViewServer; |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 894 | private ArrayList<WindowChangeListener> mWindowChangeListeners = |
| 895 | new ArrayList<WindowChangeListener>(); |
| 896 | private boolean mWindowsChanged = false; |
| 897 | |
| 898 | public interface WindowChangeListener { |
| 899 | public void windowsChanged(); |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 900 | public void focusChanged(); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 901 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 902 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 903 | final Configuration mTempConfiguration = new Configuration(); |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 904 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 905 | |
| 906 | // The frame use to limit the size of the app running in compatibility mode. |
| 907 | Rect mCompatibleScreenFrame = new Rect(); |
| 908 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 909 | Surface mBackgroundFillerSurface = null; |
| 910 | boolean mBackgroundFillerShown = false; |
| 911 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 912 | public static WindowManagerService main(Context context, |
| 913 | PowerManagerService pm, boolean haveInputMethods) { |
| 914 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 915 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 916 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 917 | synchronized (thr) { |
| 918 | while (thr.mService == null) { |
| 919 | try { |
| 920 | thr.wait(); |
| 921 | } catch (InterruptedException e) { |
| 922 | } |
| 923 | } |
| 924 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 925 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 926 | return thr.mService; |
| 927 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 928 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 929 | static class WMThread extends Thread { |
| 930 | WindowManagerService mService; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 931 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 932 | private final Context mContext; |
| 933 | private final PowerManagerService mPM; |
| 934 | private final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 935 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 936 | public WMThread(Context context, PowerManagerService pm, |
| 937 | boolean haveInputMethods) { |
| 938 | super("WindowManager"); |
| 939 | mContext = context; |
| 940 | mPM = pm; |
| 941 | mHaveInputMethods = haveInputMethods; |
| 942 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 943 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 944 | public void run() { |
| 945 | Looper.prepare(); |
| 946 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 947 | mHaveInputMethods); |
| 948 | android.os.Process.setThreadPriority( |
| 949 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 950 | android.os.Process.setCanSelfBackground(false); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 951 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 952 | synchronized (this) { |
| 953 | mService = s; |
| 954 | notifyAll(); |
| 955 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 956 | |
Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 957 | // For debug builds, log event loop stalls to dropbox for analysis. |
| 958 | if (StrictMode.conditionallyEnableDebugLogging()) { |
| 959 | Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper"); |
| 960 | } |
| 961 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 962 | Looper.loop(); |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | static class PolicyThread extends Thread { |
| 967 | private final WindowManagerPolicy mPolicy; |
| 968 | private final WindowManagerService mService; |
| 969 | private final Context mContext; |
| 970 | private final PowerManagerService mPM; |
| 971 | boolean mRunning = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 972 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 973 | public PolicyThread(WindowManagerPolicy policy, |
| 974 | WindowManagerService service, Context context, |
| 975 | PowerManagerService pm) { |
| 976 | super("WindowManagerPolicy"); |
| 977 | mPolicy = policy; |
| 978 | mService = service; |
| 979 | mContext = context; |
| 980 | mPM = pm; |
| 981 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 982 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 983 | public void run() { |
| 984 | Looper.prepare(); |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 985 | WindowManagerPolicyThread.set(this, Looper.myLooper()); |
| 986 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 987 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 988 | // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 989 | android.os.Process.setThreadPriority( |
| 990 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 991 | android.os.Process.setCanSelfBackground(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 992 | mPolicy.init(mContext, mService, mPM); |
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 | synchronized (this) { |
| 995 | mRunning = true; |
| 996 | notifyAll(); |
| 997 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 998 | |
Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 999 | // For debug builds, log event loop stalls to dropbox for analysis. |
| 1000 | if (StrictMode.conditionallyEnableDebugLogging()) { |
| 1001 | Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper"); |
| 1002 | } |
| 1003 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1004 | Looper.loop(); |
| 1005 | } |
| 1006 | } |
| 1007 | |
| 1008 | private WindowManagerService(Context context, PowerManagerService pm, |
| 1009 | boolean haveInputMethods) { |
| 1010 | mContext = context; |
| 1011 | mHaveInputMethods = haveInputMethods; |
| 1012 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 1013 | com.android.internal.R.bool.config_sf_limitedAlpha); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1014 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1015 | mPowerManager = pm; |
| 1016 | mPowerManager.setPolicy(mPolicy); |
| 1017 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 1018 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 1019 | "SCREEN_FROZEN"); |
| 1020 | mScreenFrozenLock.setReferenceCounted(false); |
| 1021 | |
| 1022 | mActivityManager = ActivityManagerNative.getDefault(); |
| 1023 | mBatteryStats = BatteryStatsService.getService(); |
| 1024 | |
| 1025 | // Get persisted window scale setting |
| 1026 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 1027 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 1028 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 1029 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1030 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1031 | // Track changes to DevicePolicyManager state so we can enable/disable keyguard. |
| 1032 | IntentFilter filter = new IntentFilter(); |
| 1033 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 1034 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 1035 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1036 | mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 1037 | "KEEP_SCREEN_ON_FLAG"); |
| 1038 | mHoldingScreenWakeLock.setReferenceCounted(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1039 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1040 | mInputManager = new InputManager(context, this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1041 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1042 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 1043 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1044 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1045 | synchronized (thr) { |
| 1046 | while (!thr.mRunning) { |
| 1047 | try { |
| 1048 | thr.wait(); |
| 1049 | } catch (InterruptedException e) { |
| 1050 | } |
| 1051 | } |
| 1052 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1053 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1054 | mInputManager.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1055 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1056 | // Add ourself to the Watchdog monitors. |
| 1057 | Watchdog.getInstance().addMonitor(this); |
| 1058 | } |
| 1059 | |
| 1060 | @Override |
| 1061 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 1062 | throws RemoteException { |
| 1063 | try { |
| 1064 | return super.onTransact(code, data, reply, flags); |
| 1065 | } catch (RuntimeException e) { |
| 1066 | // The window manager only throws security exceptions, so let's |
| 1067 | // log all others. |
| 1068 | if (!(e instanceof SecurityException)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1069 | Slog.e(TAG, "Window Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1070 | } |
| 1071 | throw e; |
| 1072 | } |
| 1073 | } |
| 1074 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1075 | private void placeWindowAfter(WindowState pos, WindowState window) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1076 | final int i = mWindows.indexOf(pos); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1077 | 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] | 1078 | TAG, "Adding window " + window + " at " |
| 1079 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 1080 | mWindows.add(i+1, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1081 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1082 | } |
| 1083 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1084 | private void placeWindowBefore(WindowState pos, WindowState window) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1085 | final int i = mWindows.indexOf(pos); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1086 | 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] | 1087 | TAG, "Adding window " + window + " at " |
| 1088 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 1089 | mWindows.add(i, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1090 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | //This method finds out the index of a window that has the same app token as |
| 1094 | //win. used for z ordering the windows in mWindows |
| 1095 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 1096 | //use a local variable to cache mWindows |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1097 | ArrayList<WindowState> localmWindows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1098 | int jmax = localmWindows.size(); |
| 1099 | if(jmax == 0) { |
| 1100 | return -1; |
| 1101 | } |
| 1102 | for(int j = (jmax-1); j >= 0; j--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1103 | WindowState wentry = localmWindows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1104 | if(wentry.mAppToken == win.mAppToken) { |
| 1105 | return j; |
| 1106 | } |
| 1107 | } |
| 1108 | return -1; |
| 1109 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1110 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1111 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 1112 | final IWindow client = win.mClient; |
| 1113 | final WindowToken token = win.mToken; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1114 | final ArrayList<WindowState> localmWindows = mWindows; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1115 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1116 | final int N = localmWindows.size(); |
| 1117 | final WindowState attached = win.mAttachedWindow; |
| 1118 | int i; |
| 1119 | if (attached == null) { |
| 1120 | int tokenWindowsPos = token.windows.size(); |
| 1121 | if (token.appWindowToken != null) { |
| 1122 | int index = tokenWindowsPos-1; |
| 1123 | if (index >= 0) { |
| 1124 | // If this application has existing windows, we |
| 1125 | // simply place the new window on top of them... but |
| 1126 | // keep the starting window on top. |
| 1127 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 1128 | // Base windows go behind everything else. |
| 1129 | placeWindowBefore(token.windows.get(0), win); |
| 1130 | tokenWindowsPos = 0; |
| 1131 | } else { |
| 1132 | AppWindowToken atoken = win.mAppToken; |
| 1133 | if (atoken != null && |
| 1134 | token.windows.get(index) == atoken.startingWindow) { |
| 1135 | placeWindowBefore(token.windows.get(index), win); |
| 1136 | tokenWindowsPos--; |
| 1137 | } else { |
| 1138 | int newIdx = findIdxBasedOnAppTokens(win); |
| 1139 | if(newIdx != -1) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1140 | //there is a window above this one associated with the same |
| 1141 | //apptoken note that the window could be a floating window |
| 1142 | //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] | 1143 | //windows associated with this token. |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1144 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 1145 | Slog.v(TAG, "Adding window " + win + " at " |
| 1146 | + (newIdx+1) + " of " + N); |
| 1147 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1148 | localmWindows.add(newIdx+1, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1149 | mWindowsChanged = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1150 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1151 | } |
| 1152 | } |
| 1153 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1154 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1155 | TAG, "Figuring out where to add app window " |
| 1156 | + client.asBinder() + " (token=" + token + ")"); |
| 1157 | // Figure out where the window should go, based on the |
| 1158 | // order of applications. |
| 1159 | final int NA = mAppTokens.size(); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1160 | WindowState pos = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1161 | for (i=NA-1; i>=0; i--) { |
| 1162 | AppWindowToken t = mAppTokens.get(i); |
| 1163 | if (t == token) { |
| 1164 | i--; |
| 1165 | break; |
| 1166 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1167 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1168 | // We haven't reached the token yet; if this token |
| 1169 | // is not going to the bottom and has windows, we can |
| 1170 | // use it as an anchor for when we do reach the token. |
| 1171 | if (!t.sendingToBottom && t.windows.size() > 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1172 | pos = t.windows.get(0); |
| 1173 | } |
| 1174 | } |
| 1175 | // We now know the index into the apps. If we found |
| 1176 | // an app window above, that gives us the position; else |
| 1177 | // we need to look some more. |
| 1178 | if (pos != null) { |
| 1179 | // Move behind any windows attached to this one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1180 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1181 | if (atoken != null) { |
| 1182 | final int NC = atoken.windows.size(); |
| 1183 | if (NC > 0) { |
| 1184 | WindowState bottom = atoken.windows.get(0); |
| 1185 | if (bottom.mSubLayer < 0) { |
| 1186 | pos = bottom; |
| 1187 | } |
| 1188 | } |
| 1189 | } |
| 1190 | placeWindowBefore(pos, win); |
| 1191 | } else { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1192 | // Continue looking down until we find the first |
| 1193 | // token that has windows. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1194 | while (i >= 0) { |
| 1195 | AppWindowToken t = mAppTokens.get(i); |
| 1196 | final int NW = t.windows.size(); |
| 1197 | if (NW > 0) { |
| 1198 | pos = t.windows.get(NW-1); |
| 1199 | break; |
| 1200 | } |
| 1201 | i--; |
| 1202 | } |
| 1203 | if (pos != null) { |
| 1204 | // Move in front of any windows attached to this |
| 1205 | // one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1206 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1207 | if (atoken != null) { |
| 1208 | final int NC = atoken.windows.size(); |
| 1209 | if (NC > 0) { |
| 1210 | WindowState top = atoken.windows.get(NC-1); |
| 1211 | if (top.mSubLayer >= 0) { |
| 1212 | pos = top; |
| 1213 | } |
| 1214 | } |
| 1215 | } |
| 1216 | placeWindowAfter(pos, win); |
| 1217 | } else { |
| 1218 | // Just search for the start of this layer. |
| 1219 | final int myLayer = win.mBaseLayer; |
| 1220 | for (i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1221 | WindowState w = localmWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1222 | if (w.mBaseLayer > myLayer) { |
| 1223 | break; |
| 1224 | } |
| 1225 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1226 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 1227 | Slog.v(TAG, "Adding window " + win + " at " |
| 1228 | + i + " of " + N); |
| 1229 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1230 | localmWindows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1231 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1232 | } |
| 1233 | } |
| 1234 | } |
| 1235 | } else { |
| 1236 | // Figure out where window should go, based on layer. |
| 1237 | final int myLayer = win.mBaseLayer; |
| 1238 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1239 | if (localmWindows.get(i).mBaseLayer <= myLayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1240 | i++; |
| 1241 | break; |
| 1242 | } |
| 1243 | } |
| 1244 | if (i < 0) i = 0; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1245 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1246 | TAG, "Adding window " + win + " at " |
| 1247 | + i + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1248 | localmWindows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1249 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1250 | } |
| 1251 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1252 | 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] | 1253 | token.windows.add(tokenWindowsPos, win); |
| 1254 | } |
| 1255 | |
| 1256 | } else { |
| 1257 | // Figure out this window's ordering relative to the window |
| 1258 | // it is attached to. |
| 1259 | final int NA = token.windows.size(); |
| 1260 | final int sublayer = win.mSubLayer; |
| 1261 | int largestSublayer = Integer.MIN_VALUE; |
| 1262 | WindowState windowWithLargestSublayer = null; |
| 1263 | for (i=0; i<NA; i++) { |
| 1264 | WindowState w = token.windows.get(i); |
| 1265 | final int wSublayer = w.mSubLayer; |
| 1266 | if (wSublayer >= largestSublayer) { |
| 1267 | largestSublayer = wSublayer; |
| 1268 | windowWithLargestSublayer = w; |
| 1269 | } |
| 1270 | if (sublayer < 0) { |
| 1271 | // For negative sublayers, we go below all windows |
| 1272 | // in the same sublayer. |
| 1273 | if (wSublayer >= sublayer) { |
| 1274 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1275 | 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] | 1276 | token.windows.add(i, win); |
| 1277 | } |
| 1278 | placeWindowBefore( |
| 1279 | wSublayer >= 0 ? attached : w, win); |
| 1280 | break; |
| 1281 | } |
| 1282 | } else { |
| 1283 | // For positive sublayers, we go above all windows |
| 1284 | // in the same sublayer. |
| 1285 | if (wSublayer > sublayer) { |
| 1286 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1287 | 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] | 1288 | token.windows.add(i, win); |
| 1289 | } |
| 1290 | placeWindowBefore(w, win); |
| 1291 | break; |
| 1292 | } |
| 1293 | } |
| 1294 | } |
| 1295 | if (i >= NA) { |
| 1296 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1297 | 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] | 1298 | token.windows.add(win); |
| 1299 | } |
| 1300 | if (sublayer < 0) { |
| 1301 | placeWindowBefore(attached, win); |
| 1302 | } else { |
| 1303 | placeWindowAfter(largestSublayer >= 0 |
| 1304 | ? windowWithLargestSublayer |
| 1305 | : attached, |
| 1306 | win); |
| 1307 | } |
| 1308 | } |
| 1309 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1310 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1311 | if (win.mAppToken != null && addToToken) { |
| 1312 | win.mAppToken.allAppWindows.add(win); |
| 1313 | } |
| 1314 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1315 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1316 | static boolean canBeImeTarget(WindowState w) { |
| 1317 | final int fl = w.mAttrs.flags |
| 1318 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 1319 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 1320 | return w.isVisibleOrAdding(); |
| 1321 | } |
| 1322 | return false; |
| 1323 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1324 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1325 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1326 | final ArrayList<WindowState> localmWindows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1327 | final int N = localmWindows.size(); |
| 1328 | WindowState w = null; |
| 1329 | int i = N; |
| 1330 | while (i > 0) { |
| 1331 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1332 | w = localmWindows.get(i); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1333 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1334 | //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1335 | // + Integer.toHexString(w.mAttrs.flags)); |
| 1336 | if (canBeImeTarget(w)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1337 | //Slog.i(TAG, "Putting input method here!"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1338 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1339 | // Yet more tricksyness! If this window is a "starting" |
| 1340 | // window, we do actually want to be on top of it, but |
| 1341 | // it is not -really- where input will go. So if the caller |
| 1342 | // is not actually looking to move the IME, look down below |
| 1343 | // for a real window to target... |
| 1344 | if (!willMove |
| 1345 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 1346 | && i > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1347 | WindowState wb = localmWindows.get(i-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1348 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 1349 | i--; |
| 1350 | w = wb; |
| 1351 | } |
| 1352 | } |
| 1353 | break; |
| 1354 | } |
| 1355 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1356 | |
Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1357 | // Now, a special case -- if the last target's window is in the |
| 1358 | // process of exiting, and is above the new target, keep on the |
| 1359 | // last target to avoid flicker. Consider for example a Dialog with |
| 1360 | // the IME shown: when the Dialog is dismissed, we want to keep |
| 1361 | // the IME above it until it is completely gone so it doesn't drop |
| 1362 | // behind the dialog or its full-screen scrim. |
| 1363 | if (mInputMethodTarget != null && w != null |
| 1364 | && mInputMethodTarget.isDisplayedLw() |
| 1365 | && mInputMethodTarget.mExiting) { |
| 1366 | if (mInputMethodTarget.mAnimLayer > w.mAnimLayer) { |
| 1367 | w = mInputMethodTarget; |
| 1368 | i = localmWindows.indexOf(w); |
| 1369 | } |
| 1370 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1371 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1372 | 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] | 1373 | + w + " willMove=" + willMove); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1374 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1375 | if (willMove && w != null) { |
| 1376 | final WindowState curTarget = mInputMethodTarget; |
| 1377 | if (curTarget != null && curTarget.mAppToken != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1378 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1379 | // Now some fun for dealing with window animations that |
| 1380 | // modify the Z order. We need to look at all windows below |
| 1381 | // the current target that are in this app, finding the highest |
| 1382 | // visible one in layering. |
| 1383 | AppWindowToken token = curTarget.mAppToken; |
| 1384 | WindowState highestTarget = null; |
| 1385 | int highestPos = 0; |
| 1386 | if (token.animating || token.animation != null) { |
| 1387 | int pos = 0; |
| 1388 | pos = localmWindows.indexOf(curTarget); |
| 1389 | while (pos >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1390 | WindowState win = localmWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1391 | if (win.mAppToken != token) { |
| 1392 | break; |
| 1393 | } |
| 1394 | if (!win.mRemoved) { |
| 1395 | if (highestTarget == null || win.mAnimLayer > |
| 1396 | highestTarget.mAnimLayer) { |
| 1397 | highestTarget = win; |
| 1398 | highestPos = pos; |
| 1399 | } |
| 1400 | } |
| 1401 | pos--; |
| 1402 | } |
| 1403 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1404 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1405 | if (highestTarget != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1406 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1407 | + mNextAppTransition + " " + highestTarget |
| 1408 | + " animating=" + highestTarget.isAnimating() |
| 1409 | + " layer=" + highestTarget.mAnimLayer |
| 1410 | + " new layer=" + w.mAnimLayer); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1411 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1412 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1413 | // If we are currently setting up for an animation, |
| 1414 | // hold everything until we can find out what will happen. |
| 1415 | mInputMethodTargetWaitingAnim = true; |
| 1416 | mInputMethodTarget = highestTarget; |
| 1417 | return highestPos + 1; |
| 1418 | } else if (highestTarget.isAnimating() && |
| 1419 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 1420 | // If the window we are currently targeting is involved |
| 1421 | // with an animation, and it is on top of the next target |
| 1422 | // we will be over, then hold off on moving until |
| 1423 | // that is done. |
| 1424 | mInputMethodTarget = highestTarget; |
| 1425 | return highestPos + 1; |
| 1426 | } |
| 1427 | } |
| 1428 | } |
| 1429 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1430 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1431 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1432 | if (w != null) { |
| 1433 | if (willMove) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1434 | if (DEBUG_INPUT_METHOD) { |
| 1435 | RuntimeException e = null; |
| 1436 | if (!HIDE_STACK_CRAWLS) { |
| 1437 | e = new RuntimeException(); |
| 1438 | e.fillInStackTrace(); |
| 1439 | } |
| 1440 | Slog.w(TAG, "Moving IM target from " |
| 1441 | + mInputMethodTarget + " to " + w, e); |
| 1442 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1443 | mInputMethodTarget = w; |
| 1444 | if (w.mAppToken != null) { |
| 1445 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 1446 | } else { |
| 1447 | setInputMethodAnimLayerAdjustment(0); |
| 1448 | } |
| 1449 | } |
| 1450 | return i+1; |
| 1451 | } |
| 1452 | if (willMove) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1453 | if (DEBUG_INPUT_METHOD) { |
| 1454 | RuntimeException e = null; |
| 1455 | if (!HIDE_STACK_CRAWLS) { |
| 1456 | e = new RuntimeException(); |
| 1457 | e.fillInStackTrace(); |
| 1458 | } |
| 1459 | Slog.w(TAG, "Moving IM target from " |
| 1460 | + mInputMethodTarget + " to null", e); |
| 1461 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1462 | mInputMethodTarget = null; |
| 1463 | setInputMethodAnimLayerAdjustment(0); |
| 1464 | } |
| 1465 | return -1; |
| 1466 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1467 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1468 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1469 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1470 | if (pos >= 0) { |
| 1471 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1472 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1473 | TAG, "Adding input method window " + win + " at " + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1474 | mWindows.add(pos, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1475 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1476 | moveInputMethodDialogsLocked(pos+1); |
| 1477 | return; |
| 1478 | } |
| 1479 | win.mTargetAppToken = null; |
| 1480 | addWindowToListInOrderLocked(win, true); |
| 1481 | moveInputMethodDialogsLocked(pos); |
| 1482 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1483 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1484 | void setInputMethodAnimLayerAdjustment(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1485 | 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] | 1486 | mInputMethodAnimLayerAdjustment = adj; |
| 1487 | WindowState imw = mInputMethodWindow; |
| 1488 | if (imw != null) { |
| 1489 | imw.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1490 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1491 | + " anim layer: " + imw.mAnimLayer); |
| 1492 | int wi = imw.mChildWindows.size(); |
| 1493 | while (wi > 0) { |
| 1494 | wi--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1495 | WindowState cw = imw.mChildWindows.get(wi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1496 | cw.mAnimLayer = cw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1497 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1498 | + " anim layer: " + cw.mAnimLayer); |
| 1499 | } |
| 1500 | } |
| 1501 | int di = mInputMethodDialogs.size(); |
| 1502 | while (di > 0) { |
| 1503 | di --; |
| 1504 | imw = mInputMethodDialogs.get(di); |
| 1505 | imw.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1506 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1507 | + " anim layer: " + imw.mAnimLayer); |
| 1508 | } |
| 1509 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1510 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1511 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1512 | int wpos = mWindows.indexOf(win); |
| 1513 | if (wpos >= 0) { |
| 1514 | if (wpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1515 | 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] | 1516 | mWindows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1517 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1518 | int NC = win.mChildWindows.size(); |
| 1519 | while (NC > 0) { |
| 1520 | NC--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1521 | WindowState cw = win.mChildWindows.get(NC); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1522 | int cpos = mWindows.indexOf(cw); |
| 1523 | if (cpos >= 0) { |
| 1524 | if (cpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1525 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1526 | + cpos + ": " + cw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1527 | mWindows.remove(cpos); |
| 1528 | } |
| 1529 | } |
| 1530 | } |
| 1531 | return interestingPos; |
| 1532 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1533 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1534 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1535 | addWindowToListInOrderLocked(win, false); |
| 1536 | // This is a hack to get all of the child windows added as well |
| 1537 | // at the right position. Child windows should be rare and |
| 1538 | // this case should be rare, so it shouldn't be that big a deal. |
| 1539 | int wpos = mWindows.indexOf(win); |
| 1540 | if (wpos >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1541 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1542 | + ": " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1543 | mWindows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1544 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1545 | reAddWindowLocked(wpos, win); |
| 1546 | } |
| 1547 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1548 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1549 | void logWindowList(String prefix) { |
| 1550 | int N = mWindows.size(); |
| 1551 | while (N > 0) { |
| 1552 | N--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1553 | Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1554 | } |
| 1555 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1556 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1557 | void moveInputMethodDialogsLocked(int pos) { |
| 1558 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1559 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1560 | final int N = dialogs.size(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1561 | 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] | 1562 | for (int i=0; i<N; i++) { |
| 1563 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1564 | } |
| 1565 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1566 | Slog.v(TAG, "Window list w/pos=" + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1567 | logWindowList(" "); |
| 1568 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1569 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1570 | if (pos >= 0) { |
| 1571 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1572 | if (pos < mWindows.size()) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1573 | WindowState wp = mWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1574 | if (wp == mInputMethodWindow) { |
| 1575 | pos++; |
| 1576 | } |
| 1577 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1578 | 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] | 1579 | for (int i=0; i<N; i++) { |
| 1580 | WindowState win = dialogs.get(i); |
| 1581 | win.mTargetAppToken = targetAppToken; |
| 1582 | pos = reAddWindowLocked(pos, win); |
| 1583 | } |
| 1584 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1585 | Slog.v(TAG, "Final window list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1586 | logWindowList(" "); |
| 1587 | } |
| 1588 | return; |
| 1589 | } |
| 1590 | for (int i=0; i<N; i++) { |
| 1591 | WindowState win = dialogs.get(i); |
| 1592 | win.mTargetAppToken = null; |
| 1593 | reAddWindowToListInOrderLocked(win); |
| 1594 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1595 | Slog.v(TAG, "No IM target, final list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1596 | logWindowList(" "); |
| 1597 | } |
| 1598 | } |
| 1599 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1600 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1601 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1602 | final WindowState imWin = mInputMethodWindow; |
| 1603 | final int DN = mInputMethodDialogs.size(); |
| 1604 | if (imWin == null && DN == 0) { |
| 1605 | return false; |
| 1606 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1607 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1608 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1609 | if (imPos >= 0) { |
| 1610 | // In this case, the input method windows are to be placed |
| 1611 | // immediately above the window they are targeting. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1612 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1613 | // First check to see if the input method windows are already |
| 1614 | // located here, and contiguous. |
| 1615 | final int N = mWindows.size(); |
| 1616 | WindowState firstImWin = imPos < N |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1617 | ? mWindows.get(imPos) : null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1618 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1619 | // Figure out the actual input method window that should be |
| 1620 | // at the bottom of their stack. |
| 1621 | WindowState baseImWin = imWin != null |
| 1622 | ? imWin : mInputMethodDialogs.get(0); |
| 1623 | if (baseImWin.mChildWindows.size() > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1624 | WindowState cw = baseImWin.mChildWindows.get(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1625 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1626 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1627 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1628 | if (firstImWin == baseImWin) { |
| 1629 | // The windows haven't moved... but are they still contiguous? |
| 1630 | // First find the top IM window. |
| 1631 | int pos = imPos+1; |
| 1632 | while (pos < N) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1633 | if (!(mWindows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1634 | break; |
| 1635 | } |
| 1636 | pos++; |
| 1637 | } |
| 1638 | pos++; |
| 1639 | // Now there should be no more input method windows above. |
| 1640 | while (pos < N) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1641 | if ((mWindows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1642 | break; |
| 1643 | } |
| 1644 | pos++; |
| 1645 | } |
| 1646 | if (pos >= N) { |
| 1647 | // All is good! |
| 1648 | return false; |
| 1649 | } |
| 1650 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1651 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1652 | if (imWin != null) { |
| 1653 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1654 | Slog.v(TAG, "Moving IM from " + imPos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1655 | logWindowList(" "); |
| 1656 | } |
| 1657 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1658 | if (DEBUG_INPUT_METHOD) { |
Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1659 | 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] | 1660 | logWindowList(" "); |
| 1661 | } |
| 1662 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1663 | reAddWindowLocked(imPos, imWin); |
| 1664 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1665 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1666 | logWindowList(" "); |
| 1667 | } |
| 1668 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1669 | } else { |
| 1670 | moveInputMethodDialogsLocked(imPos); |
| 1671 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1672 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1673 | } else { |
| 1674 | // In this case, the input method windows go in a fixed layer, |
| 1675 | // because they aren't currently associated with a focus window. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1676 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1677 | if (imWin != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1678 | 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] | 1679 | tmpRemoveWindowLocked(0, imWin); |
| 1680 | imWin.mTargetAppToken = null; |
| 1681 | reAddWindowToListInOrderLocked(imWin); |
| 1682 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1683 | Slog.v(TAG, "List with no IM target:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1684 | logWindowList(" "); |
| 1685 | } |
| 1686 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1687 | } else { |
| 1688 | moveInputMethodDialogsLocked(-1);; |
| 1689 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1690 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1691 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1692 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1693 | if (needAssignLayers) { |
| 1694 | assignLayersLocked(); |
| 1695 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1696 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1697 | return true; |
| 1698 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1699 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1700 | void adjustInputMethodDialogsLocked() { |
| 1701 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1702 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1703 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1704 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1705 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured=" |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1706 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1707 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1708 | ? wallpaperTarget.mAppToken.animation : null) |
| 1709 | + " upper=" + mUpperWallpaperTarget |
| 1710 | + " lower=" + mLowerWallpaperTarget); |
| 1711 | return (wallpaperTarget != null |
| 1712 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1713 | && wallpaperTarget.mAppToken.animation != null))) |
| 1714 | || mUpperWallpaperTarget != null |
| 1715 | || mLowerWallpaperTarget != null; |
| 1716 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1717 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1718 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1719 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1720 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1721 | int adjustWallpaperWindowsLocked() { |
| 1722 | int changed = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1723 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1724 | final int dw = mDisplay.getWidth(); |
| 1725 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1726 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1727 | // First find top-most window that has asked to be on top of the |
| 1728 | // wallpaper; all wallpapers go behind it. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1729 | final ArrayList<WindowState> localmWindows = mWindows; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1730 | int N = localmWindows.size(); |
| 1731 | WindowState w = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1732 | WindowState foundW = null; |
| 1733 | int foundI = 0; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1734 | WindowState topCurW = null; |
| 1735 | int topCurI = 0; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1736 | int windowDetachedI = -1; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1737 | int i = N; |
| 1738 | while (i > 0) { |
| 1739 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1740 | w = localmWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1741 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1742 | if (topCurW == null) { |
| 1743 | topCurW = w; |
| 1744 | topCurI = i; |
| 1745 | } |
| 1746 | continue; |
| 1747 | } |
| 1748 | topCurW = null; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1749 | if (w != mWindowDetachedWallpaper && w.mAppToken != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1750 | // If this window's app token is hidden and not animating, |
| 1751 | // it is of no interest to us. |
| 1752 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1753 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1754 | "Skipping not hidden or animating token: " + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1755 | continue; |
| 1756 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1757 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1758 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay=" |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1759 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1760 | + " commitdrawpending=" + w.mCommitDrawPending); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1761 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1762 | && (mWallpaperTarget == w |
| 1763 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1764 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1765 | "Found wallpaper activity: #" + i + "=" + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1766 | foundW = w; |
| 1767 | foundI = i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1768 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1769 | && w.mAppToken.animation != null) |
| 1770 | || w.mAnimation != null)) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1771 | // The current wallpaper target is animating, so we'll |
| 1772 | // look behind it for another possible target and figure |
| 1773 | // out what is going on below. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1774 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1775 | + ": token animating, looking behind."); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1776 | continue; |
| 1777 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1778 | break; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1779 | } else if (w == mWindowDetachedWallpaper) { |
| 1780 | windowDetachedI = i; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1781 | } |
| 1782 | } |
| 1783 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1784 | if (foundW == null && windowDetachedI >= 0) { |
| 1785 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 1786 | "Found animating detached wallpaper activity: #" + i + "=" + w); |
| 1787 | foundW = w; |
| 1788 | foundI = windowDetachedI; |
| 1789 | } |
| 1790 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1791 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1792 | // If we are currently waiting for an app transition, and either |
| 1793 | // the current target or the next target are involved with it, |
| 1794 | // then hold off on doing anything with the wallpaper. |
| 1795 | // Note that we are checking here for just whether the target |
| 1796 | // is part of an app token... which is potentially overly aggressive |
| 1797 | // (the app token may not be involved in the transition), but good |
| 1798 | // enough (we'll just wait until whatever transition is pending |
| 1799 | // executes). |
| 1800 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1801 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1802 | "Wallpaper not changing: waiting for app anim in current target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1803 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1804 | } |
| 1805 | if (foundW != null && foundW.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1806 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1807 | "Wallpaper not changing: waiting for app anim in found target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1808 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1809 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1810 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1811 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1812 | if (mWallpaperTarget != foundW) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1813 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1814 | Slog.v(TAG, "New wallpaper target: " + foundW |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1815 | + " oldTarget: " + mWallpaperTarget); |
| 1816 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1817 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1818 | mLowerWallpaperTarget = null; |
| 1819 | mUpperWallpaperTarget = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1820 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1821 | WindowState oldW = mWallpaperTarget; |
| 1822 | mWallpaperTarget = foundW; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1823 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1824 | // Now what is happening... if the current and new targets are |
| 1825 | // animating, then we are in our super special mode! |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1826 | if (foundW != null && oldW != null) { |
| 1827 | boolean oldAnim = oldW.mAnimation != null |
| 1828 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1829 | boolean foundAnim = foundW.mAnimation != null |
| 1830 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1831 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1832 | Slog.v(TAG, "New animation: " + foundAnim |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1833 | + " old animation: " + oldAnim); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1834 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1835 | if (foundAnim && oldAnim) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1836 | int oldI = localmWindows.indexOf(oldW); |
| 1837 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1838 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1839 | } |
| 1840 | if (oldI >= 0) { |
| 1841 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1842 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1843 | + "=" + oldW + "; new#" + foundI |
| 1844 | + "=" + foundW); |
| 1845 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1846 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1847 | // Set the new target correctly. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1848 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1849 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1850 | Slog.v(TAG, "Old wallpaper still the target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1851 | } |
| 1852 | mWallpaperTarget = oldW; |
| 1853 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1854 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1855 | // Now set the upper and lower wallpaper targets |
| 1856 | // correctly, and make sure that we are positioning |
| 1857 | // the wallpaper below the lower. |
| 1858 | if (foundI > oldI) { |
| 1859 | // The new target is on top of the old one. |
| 1860 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1861 | Slog.v(TAG, "Found target above old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1862 | } |
| 1863 | mUpperWallpaperTarget = foundW; |
| 1864 | mLowerWallpaperTarget = oldW; |
| 1865 | foundW = oldW; |
| 1866 | foundI = oldI; |
| 1867 | } else { |
| 1868 | // The new target is below the old one. |
| 1869 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1870 | Slog.v(TAG, "Found target below old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1871 | } |
| 1872 | mUpperWallpaperTarget = oldW; |
| 1873 | mLowerWallpaperTarget = foundW; |
| 1874 | } |
| 1875 | } |
| 1876 | } |
| 1877 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1878 | |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1879 | } else if (mLowerWallpaperTarget != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1880 | // Is it time to stop animating? |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1881 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1882 | || (mLowerWallpaperTarget.mAppToken != null |
| 1883 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1884 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1885 | || (mUpperWallpaperTarget.mAppToken != null |
| 1886 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1887 | if (!lowerAnimating || !upperAnimating) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1888 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1889 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1890 | } |
| 1891 | mLowerWallpaperTarget = null; |
| 1892 | mUpperWallpaperTarget = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1893 | } |
| 1894 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1895 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1896 | boolean visible = foundW != null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1897 | if (visible) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1898 | // The window is visible to the compositor... but is it visible |
| 1899 | // to the user? That is what the wallpaper cares about. |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1900 | visible = isWallpaperVisible(foundW); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1901 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1902 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1903 | // If the wallpaper target is animating, we may need to copy |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1904 | // its layer adjustment. Only do this if we are not transfering |
| 1905 | // between two wallpaper targets. |
| 1906 | mWallpaperAnimLayerAdjustment = |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1907 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1908 | ? foundW.mAppToken.animLayerAdjustment : 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1909 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1910 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1911 | * TYPE_LAYER_MULTIPLIER |
| 1912 | + TYPE_LAYER_OFFSET; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1913 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1914 | // Now w is the window we are supposed to be behind... but we |
| 1915 | // 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] | 1916 | // AND any starting window associated with it, AND below the |
| 1917 | // maximum layer the policy allows for wallpapers. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1918 | while (foundI > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1919 | WindowState wb = localmWindows.get(foundI-1); |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1920 | if (wb.mBaseLayer < maxLayer && |
| 1921 | wb.mAttachedWindow != foundW && |
Pal Szasz | 73dc259 | 2010-09-03 11:46:26 +0200 | [diff] [blame] | 1922 | wb.mAttachedWindow != foundW.mAttachedWindow && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1923 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1924 | wb.mToken != foundW.mToken)) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1925 | // This window is not related to the previous one in any |
| 1926 | // interesting way, so stop here. |
| 1927 | break; |
| 1928 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1929 | foundW = wb; |
| 1930 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1931 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1932 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1933 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1934 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1935 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1936 | if (foundW == null && topCurW != null) { |
| 1937 | // There is no wallpaper target, so it goes at the bottom. |
| 1938 | // We will assume it is the same place as last time, if known. |
| 1939 | foundW = topCurW; |
| 1940 | foundI = topCurI+1; |
| 1941 | } else { |
| 1942 | // Okay i is the position immediately above the wallpaper. Look at |
| 1943 | // what is below it for later. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1944 | foundW = foundI > 0 ? localmWindows.get(foundI-1) : null; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1945 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1946 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1947 | if (visible) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1948 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1949 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1950 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1951 | } |
| 1952 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1953 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1954 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1955 | } |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1956 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1957 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1958 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1959 | // are correctly placed. |
| 1960 | int curTokenIndex = mWallpaperTokens.size(); |
| 1961 | while (curTokenIndex > 0) { |
| 1962 | curTokenIndex--; |
| 1963 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1964 | if (token.hidden == visible) { |
| 1965 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1966 | token.hidden = !visible; |
| 1967 | // Need to do a layout to ensure the wallpaper now has the |
| 1968 | // correct size. |
| 1969 | mLayoutNeeded = true; |
| 1970 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1971 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1972 | int curWallpaperIndex = token.windows.size(); |
| 1973 | while (curWallpaperIndex > 0) { |
| 1974 | curWallpaperIndex--; |
| 1975 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1976 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1977 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1978 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1979 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1980 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1981 | // First, make sure the client has the current visibility |
| 1982 | // state. |
| 1983 | if (wallpaper.mWallpaperVisible != visible) { |
| 1984 | wallpaper.mWallpaperVisible = visible; |
| 1985 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1986 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1987 | "Setting visibility of wallpaper " + wallpaper |
| 1988 | + ": " + visible); |
| 1989 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1990 | } catch (RemoteException e) { |
| 1991 | } |
| 1992 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1993 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1994 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1995 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1996 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1997 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1998 | // First, if this window is at the current index, then all |
| 1999 | // is well. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2000 | if (wallpaper == foundW) { |
| 2001 | foundI--; |
| 2002 | foundW = foundI > 0 |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2003 | ? localmWindows.get(foundI-1) : null; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2004 | continue; |
| 2005 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2006 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2007 | // The window didn't match... the current wallpaper window, |
| 2008 | // wherever it is, is in the wrong place, so make sure it is |
| 2009 | // not in the list. |
| 2010 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 2011 | if (oldIndex >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2012 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 2013 | + oldIndex + ": " + wallpaper); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2014 | localmWindows.remove(oldIndex); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2015 | mWindowsChanged = true; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2016 | if (oldIndex < foundI) { |
| 2017 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2018 | } |
| 2019 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2020 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2021 | // Now stick it in. |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2022 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 2023 | Slog.v(TAG, "Moving wallpaper " + wallpaper |
| 2024 | + " from " + oldIndex + " to " + foundI); |
| 2025 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2026 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2027 | localmWindows.add(foundI, wallpaper); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2028 | mWindowsChanged = true; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2029 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2030 | } |
| 2031 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2032 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2033 | return changed; |
| 2034 | } |
| 2035 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2036 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2037 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2038 | "Setting wallpaper layer adj to " + adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2039 | mWallpaperAnimLayerAdjustment = adj; |
| 2040 | int curTokenIndex = mWallpaperTokens.size(); |
| 2041 | while (curTokenIndex > 0) { |
| 2042 | curTokenIndex--; |
| 2043 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2044 | int curWallpaperIndex = token.windows.size(); |
| 2045 | while (curWallpaperIndex > 0) { |
| 2046 | curWallpaperIndex--; |
| 2047 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2048 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2049 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2050 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2051 | } |
| 2052 | } |
| 2053 | } |
| 2054 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2055 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 2056 | boolean sync) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2057 | boolean changed = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2058 | boolean rawChanged = false; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2059 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2060 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2061 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 2062 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 2063 | changed = wallpaperWin.mXOffset != offset; |
| 2064 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2065 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2066 | + wallpaperWin + " x: " + offset); |
| 2067 | wallpaperWin.mXOffset = offset; |
| 2068 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2069 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2070 | wallpaperWin.mWallpaperX = wpx; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2071 | wallpaperWin.mWallpaperXStep = wpxs; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2072 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2073 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2074 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2075 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2076 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2077 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 2078 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 2079 | if (wallpaperWin.mYOffset != offset) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2080 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2081 | + wallpaperWin + " y: " + offset); |
| 2082 | changed = true; |
| 2083 | wallpaperWin.mYOffset = offset; |
| 2084 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2085 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2086 | wallpaperWin.mWallpaperY = wpy; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2087 | wallpaperWin.mWallpaperYStep = wpys; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2088 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2089 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2090 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2091 | if (rawChanged) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2092 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2093 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2094 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 2095 | + " y=" + wallpaperWin.mWallpaperY); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2096 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2097 | mWaitingOnWallpaper = wallpaperWin; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2098 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2099 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2100 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 2101 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2102 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2103 | if (mWaitingOnWallpaper != null) { |
| 2104 | long start = SystemClock.uptimeMillis(); |
| 2105 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 2106 | < start) { |
| 2107 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2108 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2109 | "Waiting for offset complete..."); |
| 2110 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 2111 | } catch (InterruptedException e) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2112 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2113 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2114 | if ((start+WALLPAPER_TIMEOUT) |
| 2115 | < SystemClock.uptimeMillis()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2116 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2117 | + wallpaperWin); |
| 2118 | mLastWallpaperTimeoutTime = start; |
| 2119 | } |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2120 | } |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2121 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2122 | } |
| 2123 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2124 | } catch (RemoteException e) { |
| 2125 | } |
| 2126 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2127 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2128 | return changed; |
| 2129 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2130 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2131 | void wallpaperOffsetsComplete(IBinder window) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2132 | synchronized (mWindowMap) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2133 | if (mWaitingOnWallpaper != null && |
| 2134 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2135 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2136 | mWindowMap.notifyAll(); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2137 | } |
| 2138 | } |
| 2139 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2140 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2141 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2142 | final int dw = mDisplay.getWidth(); |
| 2143 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2144 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2145 | boolean changed = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2146 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2147 | WindowState target = mWallpaperTarget; |
| 2148 | if (target != null) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2149 | if (target.mWallpaperX >= 0) { |
| 2150 | mLastWallpaperX = target.mWallpaperX; |
| 2151 | } else if (changingTarget.mWallpaperX >= 0) { |
| 2152 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 2153 | } |
| 2154 | if (target.mWallpaperY >= 0) { |
| 2155 | mLastWallpaperY = target.mWallpaperY; |
| 2156 | } else if (changingTarget.mWallpaperY >= 0) { |
| 2157 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 2158 | } |
| 2159 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2160 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2161 | int curTokenIndex = mWallpaperTokens.size(); |
| 2162 | while (curTokenIndex > 0) { |
| 2163 | curTokenIndex--; |
| 2164 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2165 | int curWallpaperIndex = token.windows.size(); |
| 2166 | while (curWallpaperIndex > 0) { |
| 2167 | curWallpaperIndex--; |
| 2168 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2169 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 2170 | wallpaper.computeShownFrameLocked(); |
| 2171 | changed = true; |
| 2172 | // We only want to be synchronous with one wallpaper. |
| 2173 | sync = false; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2174 | } |
| 2175 | } |
| 2176 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2177 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2178 | return changed; |
| 2179 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2180 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2181 | void updateWallpaperVisibilityLocked() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2182 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2183 | final int dw = mDisplay.getWidth(); |
| 2184 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2185 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2186 | int curTokenIndex = mWallpaperTokens.size(); |
| 2187 | while (curTokenIndex > 0) { |
| 2188 | curTokenIndex--; |
| 2189 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2190 | if (token.hidden == visible) { |
| 2191 | token.hidden = !visible; |
| 2192 | // Need to do a layout to ensure the wallpaper now has the |
| 2193 | // correct size. |
| 2194 | mLayoutNeeded = true; |
| 2195 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2196 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2197 | int curWallpaperIndex = token.windows.size(); |
| 2198 | while (curWallpaperIndex > 0) { |
| 2199 | curWallpaperIndex--; |
| 2200 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2201 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2202 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2203 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2204 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2205 | if (wallpaper.mWallpaperVisible != visible) { |
| 2206 | wallpaper.mWallpaperVisible = visible; |
| 2207 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2208 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2209 | "Updating visibility of wallpaper " + wallpaper |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2210 | + ": " + visible); |
| 2211 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 2212 | } catch (RemoteException e) { |
| 2213 | } |
| 2214 | } |
| 2215 | } |
| 2216 | } |
| 2217 | } |
Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 2218 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2219 | public int addWindow(Session session, IWindow client, |
| 2220 | WindowManager.LayoutParams attrs, int viewVisibility, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2221 | Rect outContentInsets, InputChannel outInputChannel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2222 | int res = mPolicy.checkAddPermission(attrs); |
| 2223 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2224 | return res; |
| 2225 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2226 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2227 | boolean reportNewConfig = false; |
| 2228 | WindowState attachedWindow = null; |
| 2229 | WindowState win = null; |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2230 | long origId; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2231 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2232 | synchronized(mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2233 | if (mDisplay == null) { |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2234 | throw new IllegalStateException("Display has not been initialialized"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2235 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2236 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2237 | if (mWindowMap.containsKey(client.asBinder())) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2238 | Slog.w(TAG, "Window " + client + " is already added"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2239 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 2240 | } |
| 2241 | |
| 2242 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2243 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2244 | if (attachedWindow == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2245 | 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] | 2246 | + attrs.token + ". Aborting."); |
| 2247 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2248 | } |
| 2249 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 2250 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2251 | 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] | 2252 | + attrs.token + ". Aborting."); |
| 2253 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2254 | } |
| 2255 | } |
| 2256 | |
| 2257 | boolean addToken = false; |
| 2258 | WindowToken token = mTokenMap.get(attrs.token); |
| 2259 | if (token == null) { |
| 2260 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2261 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2262 | 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] | 2263 | + attrs.token + ". Aborting."); |
| 2264 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2265 | } |
| 2266 | if (attrs.type == TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2267 | 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] | 2268 | + attrs.token + ". Aborting."); |
| 2269 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2270 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2271 | if (attrs.type == TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2272 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2273 | + attrs.token + ". Aborting."); |
| 2274 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2275 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2276 | token = new WindowToken(attrs.token, -1, false); |
| 2277 | addToken = true; |
| 2278 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2279 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 2280 | AppWindowToken atoken = token.appWindowToken; |
| 2281 | if (atoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2282 | 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] | 2283 | + token + ". Aborting."); |
| 2284 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 2285 | } else if (atoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2286 | 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] | 2287 | + token + ". Aborting."); |
| 2288 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2289 | } |
| 2290 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 2291 | // No need for this guy! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2292 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2293 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 2294 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 2295 | } |
| 2296 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 2297 | if (token.windowType != TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2298 | 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] | 2299 | + attrs.token + ". Aborting."); |
| 2300 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2301 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2302 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 2303 | if (token.windowType != TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2304 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2305 | + attrs.token + ". Aborting."); |
| 2306 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2307 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2308 | } |
| 2309 | |
| 2310 | win = new WindowState(session, client, token, |
| 2311 | attachedWindow, attrs, viewVisibility); |
| 2312 | if (win.mDeathRecipient == null) { |
| 2313 | // Client has apparently died, so there is no reason to |
| 2314 | // continue. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2315 | Slog.w(TAG, "Adding window client " + client.asBinder() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2316 | + " that is dead, aborting."); |
| 2317 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2318 | } |
| 2319 | |
| 2320 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2321 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2322 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 2323 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2324 | return res; |
| 2325 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2326 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2327 | if (outInputChannel != null) { |
| 2328 | String name = win.makeInputChannelName(); |
| 2329 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 2330 | win.mInputChannel = inputChannels[0]; |
| 2331 | inputChannels[1].transferToBinderOutParameter(outInputChannel); |
| 2332 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 2333 | mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2334 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2335 | |
| 2336 | // From now on, no exceptions or errors allowed! |
| 2337 | |
| 2338 | res = WindowManagerImpl.ADD_OKAY; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2339 | |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2340 | origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2341 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2342 | if (addToken) { |
| 2343 | mTokenMap.put(attrs.token, token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2344 | } |
| 2345 | win.attach(); |
| 2346 | mWindowMap.put(client.asBinder(), win); |
| 2347 | |
| 2348 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 2349 | token.appWindowToken != null) { |
| 2350 | token.appWindowToken.startingWindow = win; |
| 2351 | } |
| 2352 | |
| 2353 | boolean imMayMove = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2354 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2355 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 2356 | mInputMethodWindow = win; |
| 2357 | addInputMethodWindowToListLocked(win); |
| 2358 | imMayMove = false; |
| 2359 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2360 | mInputMethodDialogs.add(win); |
| 2361 | addWindowToListInOrderLocked(win, true); |
| 2362 | adjustInputMethodDialogsLocked(); |
| 2363 | imMayMove = false; |
| 2364 | } else { |
| 2365 | addWindowToListInOrderLocked(win, true); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2366 | if (attrs.type == TYPE_WALLPAPER) { |
| 2367 | mLastWallpaperTimeoutTime = 0; |
| 2368 | adjustWallpaperWindowsLocked(); |
| 2369 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2370 | adjustWallpaperWindowsLocked(); |
| 2371 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2372 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2373 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2374 | win.mEnterAnimationPending = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2375 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2376 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2377 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2378 | if (mInTouchMode) { |
| 2379 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 2380 | } |
| 2381 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 2382 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 2383 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2384 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2385 | boolean focusChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2386 | if (win.canReceiveKeys()) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2387 | focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS, |
| 2388 | false /*updateInputWindows*/); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2389 | if (focusChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2390 | imMayMove = false; |
| 2391 | } |
| 2392 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2393 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2394 | if (imMayMove) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2395 | moveInputMethodWindowsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2396 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2397 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2398 | assignLayersLocked(); |
| 2399 | // Don't do layout here, the window must call |
| 2400 | // relayout to be displayed, so we'll do it there. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2401 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2402 | //dump(); |
| 2403 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2404 | if (focusChanged) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2405 | finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2406 | } |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2407 | mInputMonitor.updateInputWindowsLw(); |
| 2408 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2409 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2410 | TAG, "New client " + client.asBinder() |
| 2411 | + ": window=" + win); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2412 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2413 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2414 | reportNewConfig = true; |
| 2415 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2416 | } |
| 2417 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2418 | if (reportNewConfig) { |
| 2419 | sendNewConfiguration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2420 | } |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2421 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2422 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2423 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2424 | return res; |
| 2425 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2426 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2427 | public void removeWindow(Session session, IWindow client) { |
| 2428 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2429 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2430 | if (win == null) { |
| 2431 | return; |
| 2432 | } |
| 2433 | removeWindowLocked(session, win); |
| 2434 | } |
| 2435 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2436 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2437 | public void removeWindowLocked(Session session, WindowState win) { |
| 2438 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2439 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2440 | TAG, "Remove " + win + " client=" |
| 2441 | + Integer.toHexString(System.identityHashCode( |
| 2442 | win.mClient.asBinder())) |
| 2443 | + ", surface=" + win.mSurface); |
| 2444 | |
| 2445 | final long origId = Binder.clearCallingIdentity(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2446 | |
| 2447 | win.disposeInputChannel(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2448 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2449 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2450 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2451 | + " mExiting=" + win.mExiting |
| 2452 | + " isAnimating=" + win.isAnimating() |
| 2453 | + " app-animation=" |
| 2454 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2455 | + " inPendingTransaction=" |
| 2456 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2457 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2458 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2459 | boolean wasVisible = false; |
| 2460 | // First, see if we need to run an animation. If we do, we have |
| 2461 | // to hold off on removing the window until the animation is done. |
| 2462 | // If the display is frozen, just remove immediately, since the |
| 2463 | // animation wouldn't be seen. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2464 | if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2465 | // If we are not currently running the exit animation, we |
| 2466 | // need to see about starting one. |
| 2467 | if (wasVisible=win.isWinVisibleLw()) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2468 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2469 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2470 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2471 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2472 | } |
| 2473 | // Try starting an animation. |
| 2474 | if (applyAnimationLocked(win, transit, false)) { |
| 2475 | win.mExiting = true; |
| 2476 | } |
| 2477 | } |
| 2478 | if (win.mExiting || win.isAnimating()) { |
| 2479 | // The exit animation is running... wait for it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2480 | //Slog.i(TAG, "*** Running exit animation..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2481 | win.mExiting = true; |
| 2482 | win.mRemoveOnExit = true; |
| 2483 | mLayoutNeeded = true; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2484 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 2485 | false /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2486 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2487 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2488 | if (win.mAppToken != null) { |
| 2489 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2490 | } |
| 2491 | //dump(); |
| 2492 | Binder.restoreCallingIdentity(origId); |
| 2493 | return; |
| 2494 | } |
| 2495 | } |
| 2496 | |
| 2497 | removeWindowInnerLocked(session, win); |
| 2498 | // Removing a visible window will effect the computed orientation |
| 2499 | // So just update orientation if needed. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2500 | if (wasVisible && computeForcedAppOrientationLocked() |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2501 | != mForcedAppOrientation |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2502 | && updateOrientationFromAppTokensLocked(false)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2503 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2504 | } |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2505 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2506 | Binder.restoreCallingIdentity(origId); |
| 2507 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2508 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2509 | private void removeWindowInnerLocked(Session session, WindowState win) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2510 | if (win.mRemoved) { |
| 2511 | // Nothing to do. |
| 2512 | return; |
| 2513 | } |
| 2514 | |
| 2515 | for (int i=win.mChildWindows.size()-1; i>=0; i--) { |
| 2516 | WindowState cwin = win.mChildWindows.get(i); |
| 2517 | Slog.w(TAG, "Force-removing child win " + cwin + " from container " |
| 2518 | + win); |
| 2519 | removeWindowInnerLocked(cwin.mSession, cwin); |
| 2520 | } |
| 2521 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2522 | win.mRemoved = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2523 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2524 | if (mInputMethodTarget == win) { |
| 2525 | moveInputMethodWindowsIfNeededLocked(false); |
| 2526 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2527 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2528 | if (false) { |
| 2529 | RuntimeException e = new RuntimeException("here"); |
| 2530 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2531 | Slog.w(TAG, "Removing window " + win, e); |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2532 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2533 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2534 | mPolicy.removeWindowLw(win); |
| 2535 | win.removeLocked(); |
| 2536 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2537 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2538 | mWindowMap.remove(win.mClient.asBinder()); |
| 2539 | mWindows.remove(win); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2540 | mPendingRemove.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2541 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2542 | 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] | 2543 | |
| 2544 | if (mInputMethodWindow == win) { |
| 2545 | mInputMethodWindow = null; |
| 2546 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2547 | mInputMethodDialogs.remove(win); |
| 2548 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2549 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2550 | final WindowToken token = win.mToken; |
| 2551 | final AppWindowToken atoken = win.mAppToken; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2552 | 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] | 2553 | token.windows.remove(win); |
| 2554 | if (atoken != null) { |
| 2555 | atoken.allAppWindows.remove(win); |
| 2556 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2557 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2558 | TAG, "**** Removing window " + win + ": count=" |
| 2559 | + token.windows.size()); |
| 2560 | if (token.windows.size() == 0) { |
| 2561 | if (!token.explicit) { |
| 2562 | mTokenMap.remove(token.token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2563 | } else if (atoken != null) { |
| 2564 | atoken.firstWindowDrawn = false; |
| 2565 | } |
| 2566 | } |
| 2567 | |
| 2568 | if (atoken != null) { |
| 2569 | if (atoken.startingWindow == win) { |
| 2570 | atoken.startingWindow = null; |
| 2571 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2572 | // If this is the last window and we had requested a starting |
| 2573 | // transition window, well there is no point now. |
| 2574 | atoken.startingData = null; |
| 2575 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2576 | // If this is the last window except for a starting transition |
| 2577 | // window, we need to get rid of the starting transition. |
| 2578 | if (DEBUG_STARTING_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2579 | Slog.v(TAG, "Schedule remove starting " + token |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2580 | + ": no more real windows"); |
| 2581 | } |
| 2582 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2583 | mH.sendMessage(m); |
| 2584 | } |
| 2585 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2586 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2587 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2588 | mLastWallpaperTimeoutTime = 0; |
| 2589 | adjustWallpaperWindowsLocked(); |
| 2590 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2591 | adjustWallpaperWindowsLocked(); |
| 2592 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2593 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2594 | if (!mInLayout) { |
| 2595 | assignLayersLocked(); |
| 2596 | mLayoutNeeded = true; |
| 2597 | performLayoutAndPlaceSurfacesLocked(); |
| 2598 | if (win.mAppToken != null) { |
| 2599 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2600 | } |
| 2601 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2602 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2603 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2604 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2605 | } |
| 2606 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2607 | private static void logSurface(WindowState w, String msg, RuntimeException where) { |
| 2608 | String str = " SURFACE " + Integer.toHexString(w.hashCode()) |
| 2609 | + ": " + msg + " / " + w.mAttrs.getTitle(); |
| 2610 | if (where != null) { |
| 2611 | Slog.i(TAG, str, where); |
| 2612 | } else { |
| 2613 | Slog.i(TAG, str); |
| 2614 | } |
| 2615 | } |
| 2616 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2617 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 2618 | long origId = Binder.clearCallingIdentity(); |
| 2619 | try { |
| 2620 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2621 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2622 | if ((w != null) && (w.mSurface != null)) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2623 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 2624 | ">>> OPEN TRANSACTION setTransparentRegion"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2625 | Surface.openTransaction(); |
| 2626 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2627 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 2628 | "transparentRegionHint=" + region, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2629 | w.mSurface.setTransparentRegionHint(region); |
| 2630 | } finally { |
| 2631 | Surface.closeTransaction(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2632 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 2633 | "<<< CLOSE TRANSACTION setTransparentRegion"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2634 | } |
| 2635 | } |
| 2636 | } |
| 2637 | } finally { |
| 2638 | Binder.restoreCallingIdentity(origId); |
| 2639 | } |
| 2640 | } |
| 2641 | |
| 2642 | void setInsetsWindow(Session session, IWindow client, |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2643 | int touchableInsets, Rect contentInsets, |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2644 | Rect visibleInsets, Region touchableRegion) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2645 | long origId = Binder.clearCallingIdentity(); |
| 2646 | try { |
| 2647 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2648 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2649 | if (w != null) { |
| 2650 | w.mGivenInsetsPending = false; |
| 2651 | w.mGivenContentInsets.set(contentInsets); |
| 2652 | w.mGivenVisibleInsets.set(visibleInsets); |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2653 | w.mGivenTouchableRegion.set(touchableRegion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2654 | w.mTouchableInsets = touchableInsets; |
| 2655 | mLayoutNeeded = true; |
| 2656 | performLayoutAndPlaceSurfacesLocked(); |
| 2657 | } |
| 2658 | } |
| 2659 | } finally { |
| 2660 | Binder.restoreCallingIdentity(origId); |
| 2661 | } |
| 2662 | } |
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 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2665 | Rect outDisplayFrame) { |
| 2666 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2667 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2668 | if (win == null) { |
| 2669 | outDisplayFrame.setEmpty(); |
| 2670 | return; |
| 2671 | } |
| 2672 | outDisplayFrame.set(win.mDisplayFrame); |
| 2673 | } |
| 2674 | } |
| 2675 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2676 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2677 | float xStep, float yStep) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2678 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2679 | window.mWallpaperX = x; |
| 2680 | window.mWallpaperY = y; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2681 | window.mWallpaperXStep = xStep; |
| 2682 | window.mWallpaperYStep = yStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2683 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2684 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2685 | } |
| 2686 | } |
| 2687 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2688 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2689 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2690 | synchronized (mWindowMap) { |
| 2691 | if (mWaitingOnWallpaper != null && |
| 2692 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2693 | mWaitingOnWallpaper = null; |
| 2694 | mWindowMap.notifyAll(); |
| 2695 | } |
| 2696 | } |
| 2697 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2698 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2699 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2700 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2701 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2702 | || window == mUpperWallpaperTarget) { |
| 2703 | boolean doWait = sync; |
| 2704 | int curTokenIndex = mWallpaperTokens.size(); |
| 2705 | while (curTokenIndex > 0) { |
| 2706 | curTokenIndex--; |
| 2707 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2708 | int curWallpaperIndex = token.windows.size(); |
| 2709 | while (curWallpaperIndex > 0) { |
| 2710 | curWallpaperIndex--; |
| 2711 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2712 | try { |
| 2713 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2714 | x, y, z, extras, sync); |
| 2715 | // We only want to be synchronous with one wallpaper. |
| 2716 | sync = false; |
| 2717 | } catch (RemoteException e) { |
| 2718 | } |
| 2719 | } |
| 2720 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2721 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2722 | if (doWait) { |
| 2723 | // XXX Need to wait for result. |
| 2724 | } |
| 2725 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2726 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2727 | return null; |
| 2728 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2729 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2730 | public int relayoutWindow(Session session, IWindow client, |
| 2731 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2732 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2733 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2734 | Configuration outConfig, Surface outSurface) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2735 | boolean displayed = false; |
| 2736 | boolean inTouchMode; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2737 | boolean configChanged; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2738 | long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2739 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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) { |
| 2743 | return 0; |
| 2744 | } |
| 2745 | win.mRequestedWidth = requestedWidth; |
| 2746 | win.mRequestedHeight = requestedHeight; |
| 2747 | |
| 2748 | if (attrs != null) { |
| 2749 | mPolicy.adjustWindowParamsLw(attrs); |
| 2750 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2751 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2752 | int attrChanges = 0; |
| 2753 | int flagChanges = 0; |
| 2754 | if (attrs != null) { |
| 2755 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2756 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2757 | } |
| 2758 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2759 | 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] | 2760 | |
| 2761 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2762 | win.mAlpha = attrs.alpha; |
| 2763 | } |
| 2764 | |
| 2765 | final boolean scaledWindow = |
| 2766 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2767 | |
| 2768 | if (scaledWindow) { |
| 2769 | // requested{Width|Height} Surface's physical size |
| 2770 | // attrs.{width|height} Size on screen |
| 2771 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2772 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2773 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2774 | (attrs.height / (float)requestedHeight) : 1.0f; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2775 | } else { |
| 2776 | win.mHScale = win.mVScale = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2777 | } |
| 2778 | |
| 2779 | boolean imMayMove = (flagChanges&( |
| 2780 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2781 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2782 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2783 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2784 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2785 | || (!win.mRelayoutCalled); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2786 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2787 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2788 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2789 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2790 | win.mRelayoutCalled = true; |
| 2791 | final int oldVisibility = win.mViewVisibility; |
| 2792 | win.mViewVisibility = viewVisibility; |
| 2793 | if (viewVisibility == View.VISIBLE && |
| 2794 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2795 | displayed = !win.isVisibleLw(); |
| 2796 | if (win.mExiting) { |
| 2797 | win.mExiting = false; |
Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 2798 | if (win.mAnimation != null) { |
| 2799 | win.mAnimation.cancel(); |
| 2800 | win.mAnimation = null; |
| 2801 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2802 | } |
| 2803 | if (win.mDestroying) { |
| 2804 | win.mDestroying = false; |
| 2805 | mDestroySurface.remove(win); |
| 2806 | } |
| 2807 | if (oldVisibility == View.GONE) { |
| 2808 | win.mEnterAnimationPending = true; |
| 2809 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2810 | if (displayed) { |
| 2811 | if (win.mSurface != null && !win.mDrawPending |
| 2812 | && !win.mCommitDrawPending && !mDisplayFrozen |
| 2813 | && mPolicy.isScreenOn()) { |
| 2814 | applyEnterAnimationLocked(win); |
| 2815 | } |
| 2816 | if ((win.mAttrs.flags |
| 2817 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2818 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2819 | "Relayout window turning screen on: " + win); |
| 2820 | win.mTurnOnScreen = true; |
| 2821 | } |
| 2822 | int diff = 0; |
| 2823 | if (win.mConfiguration != mCurConfiguration |
| 2824 | && (win.mConfiguration == null |
| 2825 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2826 | win.mConfiguration = mCurConfiguration; |
| 2827 | if (DEBUG_CONFIGURATION) { |
| 2828 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2829 | + win.mConfiguration + " / 0x" |
| 2830 | + Integer.toHexString(diff)); |
| 2831 | } |
| 2832 | outConfig.setTo(mCurConfiguration); |
| 2833 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2834 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2835 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2836 | // To change the format, we need to re-build the surface. |
| 2837 | win.destroySurfaceLocked(); |
| 2838 | displayed = true; |
| 2839 | } |
| 2840 | try { |
| 2841 | Surface surface = win.createSurfaceLocked(); |
| 2842 | if (surface != null) { |
| 2843 | outSurface.copyFrom(surface); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2844 | win.mReportDestroySurface = false; |
| 2845 | win.mSurfacePendingDestroy = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2846 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2847 | " OUT SURFACE " + outSurface + ": copied"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2848 | } else { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2849 | // For some reason there isn't a surface. Clear the |
| 2850 | // caller's object so they see the same state. |
| 2851 | outSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2852 | } |
| 2853 | } catch (Exception e) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2854 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2855 | mInputMonitor.updateInputWindowsLw(); |
| 2856 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2857 | Slog.w(TAG, "Exception thrown when creating surface for client " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2858 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2859 | e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2860 | Binder.restoreCallingIdentity(origId); |
| 2861 | return 0; |
| 2862 | } |
| 2863 | if (displayed) { |
| 2864 | focusMayChange = true; |
| 2865 | } |
| 2866 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2867 | && mInputMethodWindow == null) { |
| 2868 | mInputMethodWindow = win; |
| 2869 | imMayMove = true; |
| 2870 | } |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2871 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2872 | && win.mAppToken != null |
| 2873 | && win.mAppToken.startingWindow != null) { |
| 2874 | // Special handling of starting window over the base |
| 2875 | // window of the app: propagate lock screen flags to it, |
| 2876 | // to provide the correct semantics while starting. |
| 2877 | final int mask = |
| 2878 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2879 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2880 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2881 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2882 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2883 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2884 | } else { |
| 2885 | win.mEnterAnimationPending = false; |
| 2886 | if (win.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2887 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2888 | + ": mExiting=" + win.mExiting |
| 2889 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2890 | // If we are not currently running the exit animation, we |
| 2891 | // need to see about starting one. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2892 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2893 | // Try starting an animation; if there isn't one, we |
| 2894 | // can destroy the surface right away. |
| 2895 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2896 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2897 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2898 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2899 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2900 | applyAnimationLocked(win, transit, false)) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2901 | focusMayChange = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2902 | win.mExiting = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2903 | } else if (win.isAnimating()) { |
| 2904 | // Currently in a hide animation... turn this into |
| 2905 | // an exit. |
| 2906 | win.mExiting = true; |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2907 | } else if (win == mWallpaperTarget) { |
| 2908 | // If the wallpaper is currently behind this |
| 2909 | // window, we need to change both of them inside |
| 2910 | // of a transaction to avoid artifacts. |
| 2911 | win.mExiting = true; |
| 2912 | win.mAnimating = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2913 | } else { |
| 2914 | if (mInputMethodWindow == win) { |
| 2915 | mInputMethodWindow = null; |
| 2916 | } |
| 2917 | win.destroySurfaceLocked(); |
| 2918 | } |
| 2919 | } |
| 2920 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2921 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2922 | if (win.mSurface == null || (win.getAttrs().flags |
| 2923 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2924 | || win.mSurfacePendingDestroy) { |
| 2925 | // We are being called from a local process, which |
| 2926 | // means outSurface holds its current surface. Ensure the |
| 2927 | // surface object is cleared, but we don't want it actually |
| 2928 | // destroyed at this point. |
| 2929 | win.mSurfacePendingDestroy = false; |
| 2930 | outSurface.release(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2931 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2932 | } else if (win.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2933 | if (DEBUG_VISIBILITY) Slog.i(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2934 | "Keeping surface, will report destroy: " + win); |
| 2935 | win.mReportDestroySurface = true; |
| 2936 | outSurface.copyFrom(win.mSurface); |
| 2937 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2938 | } |
| 2939 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2940 | if (focusMayChange) { |
| 2941 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2942 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 2943 | false /*updateInputWindows*/)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2944 | imMayMove = false; |
| 2945 | } |
| 2946 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2947 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2948 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2949 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2950 | // reassign them at this point if the IM window state gets shuffled |
| 2951 | boolean assignLayers = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2952 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2953 | if (imMayMove) { |
Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2954 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2955 | // Little hack here -- we -should- be able to rely on the |
| 2956 | // function to return true if the IME has moved and needs |
| 2957 | // its layer recomputed. However, if the IME was hidden |
| 2958 | // and isn't actually moved in the list, its layer may be |
| 2959 | // 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] | 2960 | assignLayers = true; |
| 2961 | } |
| 2962 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2963 | if (wallpaperMayMove) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2964 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2965 | assignLayers = true; |
| 2966 | } |
| 2967 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2968 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2969 | mLayoutNeeded = true; |
| 2970 | win.mGivenInsetsPending = insetsPending; |
| 2971 | if (assignLayers) { |
| 2972 | assignLayersLocked(); |
| 2973 | } |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2974 | configChanged = updateOrientationFromAppTokensLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2975 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2976 | if (displayed && win.mIsWallpaper) { |
| 2977 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2978 | mDisplay.getHeight(), false); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2979 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2980 | if (win.mAppToken != null) { |
| 2981 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2982 | } |
| 2983 | outFrame.set(win.mFrame); |
| 2984 | outContentInsets.set(win.mContentInsets); |
| 2985 | outVisibleInsets.set(win.mVisibleInsets); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2986 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2987 | TAG, "Relayout given client " + client.asBinder() |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2988 | + ", requestedWidth=" + requestedWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2989 | + ", requestedHeight=" + requestedHeight |
| 2990 | + ", viewVisibility=" + viewVisibility |
| 2991 | + "\nRelayout returning frame=" + outFrame |
| 2992 | + ", surface=" + outSurface); |
| 2993 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2994 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2995 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2996 | |
| 2997 | inTouchMode = mInTouchMode; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2998 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2999 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3000 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3001 | } |
| 3002 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3003 | if (configChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3004 | sendNewConfiguration(); |
| 3005 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3006 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3007 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3008 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3009 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 3010 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 3011 | } |
| 3012 | |
| 3013 | public void finishDrawingWindow(Session session, IWindow client) { |
| 3014 | final long origId = Binder.clearCallingIdentity(); |
| 3015 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3016 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3017 | if (win != null && win.finishDrawingLocked()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 3018 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 3019 | adjustWallpaperWindowsLocked(); |
| 3020 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3021 | mLayoutNeeded = true; |
| 3022 | performLayoutAndPlaceSurfacesLocked(); |
| 3023 | } |
| 3024 | } |
| 3025 | Binder.restoreCallingIdentity(origId); |
| 3026 | } |
| 3027 | |
| 3028 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 3029 | 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] | 3030 | + (lp != null ? lp.packageName : null) |
| 3031 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 3032 | if (lp != null && lp.windowAnimations != 0) { |
| 3033 | // If this is a system resource, don't try to load it from the |
| 3034 | // application resources. It is nice to avoid loading application |
| 3035 | // resources if we can. |
| 3036 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 3037 | int resId = lp.windowAnimations; |
| 3038 | if ((resId&0xFF000000) == 0x01000000) { |
| 3039 | packageName = "android"; |
| 3040 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3041 | 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] | 3042 | + packageName); |
| 3043 | return AttributeCache.instance().get(packageName, resId, |
| 3044 | com.android.internal.R.styleable.WindowAnimation); |
| 3045 | } |
| 3046 | return null; |
| 3047 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3048 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3049 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 3050 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3051 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 3052 | if (packageName != null) { |
| 3053 | if ((resId&0xFF000000) == 0x01000000) { |
| 3054 | packageName = "android"; |
| 3055 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3056 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3057 | + packageName); |
| 3058 | return AttributeCache.instance().get(packageName, resId, |
| 3059 | com.android.internal.R.styleable.WindowAnimation); |
| 3060 | } |
| 3061 | return null; |
| 3062 | } |
| 3063 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3064 | private void applyEnterAnimationLocked(WindowState win) { |
| 3065 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 3066 | if (win.mEnterAnimationPending) { |
| 3067 | win.mEnterAnimationPending = false; |
| 3068 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 3069 | } |
| 3070 | |
| 3071 | applyAnimationLocked(win, transit, true); |
| 3072 | } |
| 3073 | |
| 3074 | private boolean applyAnimationLocked(WindowState win, |
| 3075 | int transit, boolean isEntrance) { |
| 3076 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 3077 | // If we are trying to apply an animation, but already running |
| 3078 | // an animation of the same type, then just leave that one alone. |
| 3079 | return true; |
| 3080 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3081 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3082 | // Only apply an animation if the display isn't frozen. If it is |
| 3083 | // frozen, there is no reason to animate and it can cause strange |
| 3084 | // artifacts when we unfreeze the display if some different animation |
| 3085 | // is running. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3086 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3087 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 3088 | int attr = -1; |
| 3089 | Animation a = null; |
| 3090 | if (anim != 0) { |
| 3091 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 3092 | } else { |
| 3093 | switch (transit) { |
| 3094 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 3095 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 3096 | break; |
| 3097 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 3098 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 3099 | break; |
| 3100 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 3101 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 3102 | break; |
| 3103 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 3104 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 3105 | break; |
| 3106 | } |
| 3107 | if (attr >= 0) { |
| 3108 | a = loadAnimation(win.mAttrs, attr); |
| 3109 | } |
| 3110 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3111 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3112 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 3113 | + " mAnimation=" + win.mAnimation |
| 3114 | + " isEntrance=" + isEntrance); |
| 3115 | if (a != null) { |
| 3116 | if (DEBUG_ANIM) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3117 | RuntimeException e = null; |
| 3118 | if (!HIDE_STACK_CRAWLS) { |
| 3119 | e = new RuntimeException(); |
| 3120 | e.fillInStackTrace(); |
| 3121 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3122 | Slog.v(TAG, "Loaded animation " + a + " for " + win, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3123 | } |
| 3124 | win.setAnimation(a); |
| 3125 | win.mAnimationIsEntrance = isEntrance; |
| 3126 | } |
| 3127 | } else { |
| 3128 | win.clearAnimation(); |
| 3129 | } |
| 3130 | |
| 3131 | return win.mAnimation != null; |
| 3132 | } |
| 3133 | |
| 3134 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 3135 | int anim = 0; |
| 3136 | Context context = mContext; |
| 3137 | if (animAttr >= 0) { |
| 3138 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 3139 | if (ent != null) { |
| 3140 | context = ent.context; |
| 3141 | anim = ent.array.getResourceId(animAttr, 0); |
| 3142 | } |
| 3143 | } |
| 3144 | if (anim != 0) { |
| 3145 | return AnimationUtils.loadAnimation(context, anim); |
| 3146 | } |
| 3147 | return null; |
| 3148 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3149 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3150 | private Animation loadAnimation(String packageName, int resId) { |
| 3151 | int anim = 0; |
| 3152 | Context context = mContext; |
| 3153 | if (resId >= 0) { |
| 3154 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 3155 | if (ent != null) { |
| 3156 | context = ent.context; |
| 3157 | anim = resId; |
| 3158 | } |
| 3159 | } |
| 3160 | if (anim != 0) { |
| 3161 | return AnimationUtils.loadAnimation(context, anim); |
| 3162 | } |
| 3163 | return null; |
| 3164 | } |
| 3165 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3166 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 3167 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 3168 | // Only apply an animation if the display isn't frozen. If it is |
| 3169 | // frozen, there is no reason to animate and it can cause strange |
| 3170 | // artifacts when we unfreeze the display if some different animation |
| 3171 | // is running. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3172 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3173 | Animation a; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 3174 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3175 | a = new FadeInOutAnimation(enter); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3176 | if (DEBUG_ANIM) Slog.v(TAG, |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3177 | "applying FadeInOutAnimation for a window in compatibility mode"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3178 | } else if (mNextAppTransitionPackage != null) { |
| 3179 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 3180 | mNextAppTransitionEnter : mNextAppTransitionExit); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3181 | } else { |
| 3182 | int animAttr = 0; |
| 3183 | switch (transit) { |
| 3184 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 3185 | animAttr = enter |
| 3186 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 3187 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 3188 | break; |
| 3189 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 3190 | animAttr = enter |
| 3191 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 3192 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 3193 | break; |
| 3194 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 3195 | animAttr = enter |
| 3196 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 3197 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 3198 | break; |
| 3199 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 3200 | animAttr = enter |
| 3201 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 3202 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 3203 | break; |
| 3204 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 3205 | animAttr = enter |
| 3206 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 3207 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 3208 | break; |
| 3209 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 3210 | animAttr = enter |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 3211 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3212 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 3213 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3214 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3215 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3216 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 3217 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3218 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3219 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3220 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3221 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 3222 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 3223 | break; |
| 3224 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 3225 | animAttr = enter |
| 3226 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 3227 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 3228 | break; |
| 3229 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 3230 | animAttr = enter |
| 3231 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 3232 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3233 | break; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3234 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3235 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3236 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3237 | + " anim=" + a |
| 3238 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 3239 | + " transit=" + transit); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3240 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3241 | if (a != null) { |
| 3242 | if (DEBUG_ANIM) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3243 | RuntimeException e = null; |
| 3244 | if (!HIDE_STACK_CRAWLS) { |
| 3245 | e = new RuntimeException(); |
| 3246 | e.fillInStackTrace(); |
| 3247 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3248 | Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3249 | } |
| 3250 | wtoken.setAnimation(a); |
| 3251 | } |
| 3252 | } else { |
| 3253 | wtoken.clearAnimation(); |
| 3254 | } |
| 3255 | |
| 3256 | return wtoken.animation != null; |
| 3257 | } |
| 3258 | |
| 3259 | // ------------------------------------------------------------- |
| 3260 | // Application Window Tokens |
| 3261 | // ------------------------------------------------------------- |
| 3262 | |
| 3263 | public void validateAppTokens(List tokens) { |
| 3264 | int v = tokens.size()-1; |
| 3265 | int m = mAppTokens.size()-1; |
| 3266 | while (v >= 0 && m >= 0) { |
| 3267 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3268 | if (wtoken.removed) { |
| 3269 | m--; |
| 3270 | continue; |
| 3271 | } |
| 3272 | if (tokens.get(v) != wtoken.token) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3273 | 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] | 3274 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 3275 | } |
| 3276 | v--; |
| 3277 | m--; |
| 3278 | } |
| 3279 | while (v >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3280 | 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] | 3281 | v--; |
| 3282 | } |
| 3283 | while (m >= 0) { |
| 3284 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3285 | if (!wtoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3286 | Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3287 | } |
| 3288 | m--; |
| 3289 | } |
| 3290 | } |
| 3291 | |
| 3292 | boolean checkCallingPermission(String permission, String func) { |
| 3293 | // Quick check: if the calling permission is me, it's all okay. |
| 3294 | if (Binder.getCallingPid() == Process.myPid()) { |
| 3295 | return true; |
| 3296 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3297 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3298 | if (mContext.checkCallingPermission(permission) |
| 3299 | == PackageManager.PERMISSION_GRANTED) { |
| 3300 | return true; |
| 3301 | } |
| 3302 | String msg = "Permission Denial: " + func + " from pid=" |
| 3303 | + Binder.getCallingPid() |
| 3304 | + ", uid=" + Binder.getCallingUid() |
| 3305 | + " requires " + permission; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3306 | Slog.w(TAG, msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3307 | return false; |
| 3308 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3309 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3310 | AppWindowToken findAppWindowToken(IBinder token) { |
| 3311 | WindowToken wtoken = mTokenMap.get(token); |
| 3312 | if (wtoken == null) { |
| 3313 | return null; |
| 3314 | } |
| 3315 | return wtoken.appWindowToken; |
| 3316 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3317 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3318 | public void addWindowToken(IBinder token, int type) { |
| 3319 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3320 | "addWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3321 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3322 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3323 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3324 | synchronized(mWindowMap) { |
| 3325 | WindowToken wtoken = mTokenMap.get(token); |
| 3326 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3327 | 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] | 3328 | return; |
| 3329 | } |
| 3330 | wtoken = new WindowToken(token, type, true); |
| 3331 | mTokenMap.put(token, wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3332 | if (type == TYPE_WALLPAPER) { |
| 3333 | mWallpaperTokens.add(wtoken); |
| 3334 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3335 | } |
| 3336 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3337 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3338 | public void removeWindowToken(IBinder token) { |
| 3339 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3340 | "removeWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3341 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3342 | } |
| 3343 | |
| 3344 | final long origId = Binder.clearCallingIdentity(); |
| 3345 | synchronized(mWindowMap) { |
| 3346 | WindowToken wtoken = mTokenMap.remove(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3347 | if (wtoken != null) { |
| 3348 | boolean delayed = false; |
| 3349 | if (!wtoken.hidden) { |
| 3350 | wtoken.hidden = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3351 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3352 | final int N = wtoken.windows.size(); |
| 3353 | boolean changed = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3354 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3355 | for (int i=0; i<N; i++) { |
| 3356 | WindowState win = wtoken.windows.get(i); |
| 3357 | |
| 3358 | if (win.isAnimating()) { |
| 3359 | delayed = true; |
| 3360 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3361 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3362 | if (win.isVisibleNow()) { |
| 3363 | applyAnimationLocked(win, |
| 3364 | WindowManagerPolicy.TRANSIT_EXIT, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3365 | changed = true; |
| 3366 | } |
| 3367 | } |
| 3368 | |
| 3369 | if (changed) { |
| 3370 | mLayoutNeeded = true; |
| 3371 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3372 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, |
| 3373 | false /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3374 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3375 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3376 | if (delayed) { |
| 3377 | mExitingTokens.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3378 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 3379 | mWallpaperTokens.remove(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3380 | } |
| 3381 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3382 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3383 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3384 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3385 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3386 | 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] | 3387 | } |
| 3388 | } |
| 3389 | Binder.restoreCallingIdentity(origId); |
| 3390 | } |
| 3391 | |
| 3392 | public void addAppToken(int addPos, IApplicationToken token, |
| 3393 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 3394 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3395 | "addAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3396 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3397 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3398 | |
| 3399 | // Get the dispatching timeout here while we are not holding any locks so that it |
| 3400 | // can be cached by the AppWindowToken. The timeout value is used later by the |
| 3401 | // input dispatcher in code that does hold locks. If we did not cache the value |
| 3402 | // here we would run the chance of introducing a deadlock between the window manager |
| 3403 | // (which holds locks while updating the input dispatcher state) and the activity manager |
| 3404 | // (which holds locks while querying the application token). |
| 3405 | long inputDispatchingTimeoutNanos; |
| 3406 | try { |
| 3407 | inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L; |
| 3408 | } catch (RemoteException ex) { |
| 3409 | Slog.w(TAG, "Could not get dispatching timeout.", ex); |
| 3410 | inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 3411 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3412 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3413 | synchronized(mWindowMap) { |
| 3414 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3415 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3416 | 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] | 3417 | return; |
| 3418 | } |
| 3419 | wtoken = new AppWindowToken(token); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3420 | wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3421 | wtoken.groupId = groupId; |
| 3422 | wtoken.appFullscreen = fullscreen; |
| 3423 | wtoken.requestedOrientation = requestedOrientation; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3424 | 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] | 3425 | mAppTokens.add(addPos, wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3426 | mTokenMap.put(token.asBinder(), wtoken); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3427 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3428 | // Application tokens start out hidden. |
| 3429 | wtoken.hidden = true; |
| 3430 | wtoken.hiddenRequested = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3431 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3432 | //dump(); |
| 3433 | } |
| 3434 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3435 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3436 | public void setAppGroupId(IBinder token, int groupId) { |
| 3437 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3438 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3439 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3440 | } |
| 3441 | |
| 3442 | synchronized(mWindowMap) { |
| 3443 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3444 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3445 | 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] | 3446 | return; |
| 3447 | } |
| 3448 | wtoken.groupId = groupId; |
| 3449 | } |
| 3450 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3451 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3452 | public int getOrientationFromWindowsLocked() { |
| 3453 | int pos = mWindows.size() - 1; |
| 3454 | while (pos >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3455 | WindowState wtoken = mWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3456 | pos--; |
| 3457 | if (wtoken.mAppToken != null) { |
| 3458 | // We hit an application window. so the orientation will be determined by the |
| 3459 | // app window. No point in continuing further. |
| 3460 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3461 | } |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3462 | if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3463 | continue; |
| 3464 | } |
| 3465 | int req = wtoken.mAttrs.screenOrientation; |
| 3466 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 3467 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 3468 | continue; |
| 3469 | } else { |
| 3470 | return req; |
| 3471 | } |
| 3472 | } |
| 3473 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3474 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3475 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3476 | public int getOrientationFromAppTokensLocked() { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3477 | int pos = mAppTokens.size() - 1; |
| 3478 | int curGroup = 0; |
| 3479 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3480 | boolean findingBehind = false; |
| 3481 | boolean haveGroup = false; |
| 3482 | boolean lastFullscreen = false; |
| 3483 | while (pos >= 0) { |
| 3484 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 3485 | pos--; |
| 3486 | // if we're about to tear down this window and not seek for |
| 3487 | // the behind activity, don't use it for orientation |
| 3488 | if (!findingBehind |
| 3489 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| 3490 | continue; |
| 3491 | } |
| 3492 | |
| 3493 | if (!haveGroup) { |
| 3494 | // We ignore any hidden applications on the top. |
| 3495 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3496 | continue; |
| 3497 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3498 | haveGroup = true; |
| 3499 | curGroup = wtoken.groupId; |
| 3500 | lastOrientation = wtoken.requestedOrientation; |
| 3501 | } else if (curGroup != wtoken.groupId) { |
| 3502 | // If we have hit a new application group, and the bottom |
| 3503 | // of the previous group didn't explicitly say to use |
| 3504 | // the orientation behind it, and the last app was |
| 3505 | // full screen, then we'll stick with the |
| 3506 | // user's orientation. |
| 3507 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3508 | && lastFullscreen) { |
| 3509 | return lastOrientation; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3510 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3511 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3512 | int or = wtoken.requestedOrientation; |
| 3513 | // If this application is fullscreen, and didn't explicitly say |
| 3514 | // to use the orientation behind it, then just take whatever |
| 3515 | // orientation it has and ignores whatever is under it. |
| 3516 | lastFullscreen = wtoken.appFullscreen; |
| 3517 | if (lastFullscreen |
| 3518 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| 3519 | return or; |
| 3520 | } |
| 3521 | // If this application has requested an explicit orientation, |
| 3522 | // then use it. |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 3523 | if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 3524 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3525 | return or; |
| 3526 | } |
| 3527 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| 3528 | } |
| 3529 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3530 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3531 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3532 | public Configuration updateOrientationFromAppTokens( |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3533 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3534 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3535 | "updateOrientationFromAppTokens()")) { |
| 3536 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3537 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3538 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3539 | Configuration config = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3540 | long ident = Binder.clearCallingIdentity(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3541 | |
| 3542 | synchronized(mWindowMap) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3543 | if (updateOrientationFromAppTokensLocked(false)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3544 | if (freezeThisOneIfNeeded != null) { |
| 3545 | AppWindowToken wtoken = findAppWindowToken( |
| 3546 | freezeThisOneIfNeeded); |
| 3547 | if (wtoken != null) { |
| 3548 | startAppFreezingScreenLocked(wtoken, |
| 3549 | ActivityInfo.CONFIG_ORIENTATION); |
| 3550 | } |
| 3551 | } |
| 3552 | config = computeNewConfigurationLocked(); |
| 3553 | |
| 3554 | } else if (currentConfig != null) { |
| 3555 | // No obvious action we need to take, but if our current |
Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3556 | // state mismatches the activity manager's, update it, |
| 3557 | // disregarding font scale, which should remain set to |
| 3558 | // the value of the previous configuration. |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3559 | mTempConfiguration.setToDefaults(); |
Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3560 | mTempConfiguration.fontScale = currentConfig.fontScale; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3561 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3562 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3563 | mWaitingForConfig = true; |
| 3564 | mLayoutNeeded = true; |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3565 | startFreezingDisplayLocked(false); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3566 | config = new Configuration(mTempConfiguration); |
| 3567 | } |
| 3568 | } |
| 3569 | } |
| 3570 | } |
| 3571 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3572 | Binder.restoreCallingIdentity(ident); |
| 3573 | return config; |
| 3574 | } |
| 3575 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3576 | /* |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3577 | * Determine the new desired orientation of the display, returning |
| 3578 | * a non-null new Configuration if it has changed from the current |
| 3579 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3580 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3581 | * SCREEN. This will typically be done for you if you call |
| 3582 | * sendNewConfiguration(). |
| 3583 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3584 | * The orientation is computed from non-application windows first. If none of |
| 3585 | * the non-application windows specify orientation, the orientation is computed from |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3586 | * application tokens. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3587 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3588 | * android.os.IBinder) |
| 3589 | */ |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3590 | boolean updateOrientationFromAppTokensLocked(boolean inTransaction) { |
| 3591 | if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) { |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3592 | // If the display is frozen, some activities may be in the middle |
| 3593 | // of restarting, and thus have removed their old window. If the |
| 3594 | // window has the flag to hide the lock screen, then the lock screen |
| 3595 | // can re-appear and inflict its own orientation on us. Keep the |
| 3596 | // orientation stable until this all settles down. |
| 3597 | return false; |
| 3598 | } |
| 3599 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3600 | boolean changed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3601 | long ident = Binder.clearCallingIdentity(); |
| 3602 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3603 | int req = computeForcedAppOrientationLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3604 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3605 | if (req != mForcedAppOrientation) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3606 | mForcedAppOrientation = req; |
| 3607 | //send a message to Policy indicating orientation change to take |
| 3608 | //action like disabling/enabling sensors etc., |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3609 | mPolicy.setCurrentOrientationLw(req); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3610 | if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION, |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3611 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE, |
| 3612 | inTransaction)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3613 | changed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3614 | } |
| 3615 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3616 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3617 | return changed; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3618 | } finally { |
| 3619 | Binder.restoreCallingIdentity(ident); |
| 3620 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3621 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3622 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3623 | int computeForcedAppOrientationLocked() { |
| 3624 | int req = getOrientationFromWindowsLocked(); |
| 3625 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3626 | req = getOrientationFromAppTokensLocked(); |
| 3627 | } |
| 3628 | return req; |
| 3629 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3630 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3631 | public void setNewConfiguration(Configuration config) { |
| 3632 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3633 | "setNewConfiguration()")) { |
| 3634 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3635 | } |
| 3636 | |
| 3637 | synchronized(mWindowMap) { |
| 3638 | mCurConfiguration = new Configuration(config); |
| 3639 | mWaitingForConfig = false; |
| 3640 | performLayoutAndPlaceSurfacesLocked(); |
| 3641 | } |
| 3642 | } |
| 3643 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3644 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3645 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3646 | "setAppOrientation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3647 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3648 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3649 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3650 | synchronized(mWindowMap) { |
| 3651 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3652 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3653 | 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] | 3654 | return; |
| 3655 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3656 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3657 | wtoken.requestedOrientation = requestedOrientation; |
| 3658 | } |
| 3659 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3660 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3661 | public int getAppOrientation(IApplicationToken token) { |
| 3662 | synchronized(mWindowMap) { |
| 3663 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3664 | if (wtoken == null) { |
| 3665 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3666 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3667 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3668 | return wtoken.requestedOrientation; |
| 3669 | } |
| 3670 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3671 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3672 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3673 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3674 | "setFocusedApp()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3675 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3676 | } |
| 3677 | |
| 3678 | synchronized(mWindowMap) { |
| 3679 | boolean changed = false; |
| 3680 | if (token == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3681 | 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] | 3682 | changed = mFocusedApp != null; |
| 3683 | mFocusedApp = null; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3684 | if (changed) { |
| 3685 | mInputMonitor.setFocusedAppLw(null); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3686 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3687 | } else { |
| 3688 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3689 | if (newFocus == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3690 | 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] | 3691 | return; |
| 3692 | } |
| 3693 | changed = mFocusedApp != newFocus; |
| 3694 | mFocusedApp = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3695 | if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3696 | if (changed) { |
| 3697 | mInputMonitor.setFocusedAppLw(newFocus); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3698 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3699 | } |
| 3700 | |
| 3701 | if (moveFocusNow && changed) { |
| 3702 | final long origId = Binder.clearCallingIdentity(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3703 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3704 | Binder.restoreCallingIdentity(origId); |
| 3705 | } |
| 3706 | } |
| 3707 | } |
| 3708 | |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 3709 | public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3710 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3711 | "prepareAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3712 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3713 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3714 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3715 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3716 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3717 | TAG, "Prepare app transition: transit=" + transit |
| 3718 | + " mNextAppTransition=" + mNextAppTransition); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3719 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3720 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3721 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3722 | mNextAppTransition = transit; |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 3723 | } else if (!alwaysKeepCurrent) { |
| 3724 | if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3725 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3726 | // Opening a new task always supersedes a close for the anim. |
| 3727 | mNextAppTransition = transit; |
| 3728 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3729 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3730 | // Opening a new activity always supersedes a close for the anim. |
| 3731 | mNextAppTransition = transit; |
| 3732 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3733 | } |
| 3734 | mAppTransitionReady = false; |
| 3735 | mAppTransitionTimeout = false; |
| 3736 | mStartingIconInTransition = false; |
| 3737 | mSkipAppTransitionAnimation = false; |
| 3738 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3739 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3740 | 5000); |
| 3741 | } |
| 3742 | } |
| 3743 | } |
| 3744 | |
| 3745 | public int getPendingAppTransition() { |
| 3746 | return mNextAppTransition; |
| 3747 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3748 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3749 | public void overridePendingAppTransition(String packageName, |
| 3750 | int enterAnim, int exitAnim) { |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3751 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3752 | mNextAppTransitionPackage = packageName; |
| 3753 | mNextAppTransitionEnter = enterAnim; |
| 3754 | mNextAppTransitionExit = exitAnim; |
| 3755 | } |
| 3756 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3757 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3758 | public void executeAppTransition() { |
| 3759 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3760 | "executeAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3761 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3762 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3763 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3764 | synchronized(mWindowMap) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3765 | if (DEBUG_APP_TRANSITIONS) { |
| 3766 | RuntimeException e = new RuntimeException("here"); |
| 3767 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3768 | Slog.w(TAG, "Execute app transition: mNextAppTransition=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3769 | + mNextAppTransition, e); |
| 3770 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3771 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3772 | mAppTransitionReady = true; |
| 3773 | final long origId = Binder.clearCallingIdentity(); |
| 3774 | performLayoutAndPlaceSurfacesLocked(); |
| 3775 | Binder.restoreCallingIdentity(origId); |
| 3776 | } |
| 3777 | } |
| 3778 | } |
| 3779 | |
| 3780 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3781 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 3782 | int windowFlags, IBinder transferFrom, boolean createIfNeeded) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3783 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3784 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3785 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3786 | } |
| 3787 | |
| 3788 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3789 | if (DEBUG_STARTING_WINDOW) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3790 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3791 | + " transferFrom=" + transferFrom); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3792 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3793 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3794 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3795 | 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] | 3796 | return; |
| 3797 | } |
| 3798 | |
| 3799 | // If the display is frozen, we won't do anything until the |
| 3800 | // actual window is displayed so there is no reason to put in |
| 3801 | // the starting window. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3802 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3803 | return; |
| 3804 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3805 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3806 | if (wtoken.startingData != null) { |
| 3807 | return; |
| 3808 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3809 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3810 | if (transferFrom != null) { |
| 3811 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3812 | if (ttoken != null) { |
| 3813 | WindowState startingWindow = ttoken.startingWindow; |
| 3814 | if (startingWindow != null) { |
| 3815 | if (mStartingIconInTransition) { |
| 3816 | // In this case, the starting icon has already |
| 3817 | // been displayed, so start letting windows get |
| 3818 | // shown immediately without any more transitions. |
| 3819 | mSkipAppTransitionAnimation = true; |
| 3820 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3821 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3822 | "Moving existing starting from " + ttoken |
| 3823 | + " to " + wtoken); |
| 3824 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3825 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3826 | // Transfer the starting window over to the new |
| 3827 | // token. |
| 3828 | wtoken.startingData = ttoken.startingData; |
| 3829 | wtoken.startingView = ttoken.startingView; |
| 3830 | wtoken.startingWindow = startingWindow; |
| 3831 | ttoken.startingData = null; |
| 3832 | ttoken.startingView = null; |
| 3833 | ttoken.startingWindow = null; |
| 3834 | ttoken.startingMoved = true; |
| 3835 | startingWindow.mToken = wtoken; |
Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3836 | startingWindow.mRootToken = wtoken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3837 | startingWindow.mAppToken = wtoken; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3838 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3839 | "Removing starting window: " + startingWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3840 | mWindows.remove(startingWindow); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3841 | mWindowsChanged = true; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3842 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing starting " + startingWindow |
| 3843 | + " from " + ttoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3844 | ttoken.windows.remove(startingWindow); |
| 3845 | ttoken.allAppWindows.remove(startingWindow); |
| 3846 | addWindowToListInOrderLocked(startingWindow, true); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3847 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3848 | // Propagate other interesting state between the |
| 3849 | // tokens. If the old token is displayed, we should |
| 3850 | // immediately force the new one to be displayed. If |
| 3851 | // it is animating, we need to move that animation to |
| 3852 | // the new one. |
| 3853 | if (ttoken.allDrawn) { |
| 3854 | wtoken.allDrawn = true; |
| 3855 | } |
| 3856 | if (ttoken.firstWindowDrawn) { |
| 3857 | wtoken.firstWindowDrawn = true; |
| 3858 | } |
| 3859 | if (!ttoken.hidden) { |
| 3860 | wtoken.hidden = false; |
| 3861 | wtoken.hiddenRequested = false; |
| 3862 | wtoken.willBeHidden = false; |
| 3863 | } |
| 3864 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3865 | wtoken.clientHidden = ttoken.clientHidden; |
| 3866 | wtoken.sendAppVisibilityToClients(); |
| 3867 | } |
| 3868 | if (ttoken.animation != null) { |
| 3869 | wtoken.animation = ttoken.animation; |
| 3870 | wtoken.animating = ttoken.animating; |
| 3871 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3872 | ttoken.animation = null; |
| 3873 | ttoken.animLayerAdjustment = 0; |
| 3874 | wtoken.updateLayers(); |
| 3875 | ttoken.updateLayers(); |
| 3876 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3877 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3878 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 3879 | true /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3880 | mLayoutNeeded = true; |
| 3881 | performLayoutAndPlaceSurfacesLocked(); |
| 3882 | Binder.restoreCallingIdentity(origId); |
| 3883 | return; |
| 3884 | } else if (ttoken.startingData != null) { |
| 3885 | // The previous app was getting ready to show a |
| 3886 | // starting window, but hasn't yet done so. Steal it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3887 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3888 | "Moving pending starting from " + ttoken |
| 3889 | + " to " + wtoken); |
| 3890 | wtoken.startingData = ttoken.startingData; |
| 3891 | ttoken.startingData = null; |
| 3892 | ttoken.startingMoved = true; |
| 3893 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3894 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3895 | // want to process the message ASAP, before any other queued |
| 3896 | // messages. |
| 3897 | mH.sendMessageAtFrontOfQueue(m); |
| 3898 | return; |
| 3899 | } |
| 3900 | } |
| 3901 | } |
| 3902 | |
| 3903 | // There is no existing starting window, and the caller doesn't |
| 3904 | // want us to create one, so that's it! |
| 3905 | if (!createIfNeeded) { |
| 3906 | return; |
| 3907 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3908 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3909 | // If this is a translucent or wallpaper window, then don't |
| 3910 | // show a starting window -- the current effect (a full-screen |
| 3911 | // opaque starting window that fades away to the real contents |
| 3912 | // when it is ready) does not work for this. |
| 3913 | if (theme != 0) { |
| 3914 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3915 | com.android.internal.R.styleable.Window); |
| 3916 | if (ent.array.getBoolean( |
| 3917 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3918 | return; |
| 3919 | } |
| 3920 | if (ent.array.getBoolean( |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3921 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3922 | return; |
| 3923 | } |
| 3924 | if (ent.array.getBoolean( |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3925 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3926 | return; |
| 3927 | } |
| 3928 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3929 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3930 | mStartingIconInTransition = true; |
| 3931 | wtoken.startingData = new StartingData( |
| 3932 | pkg, theme, nonLocalizedLabel, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 3933 | labelRes, icon, windowFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3934 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3935 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3936 | // want to process the message ASAP, before any other queued |
| 3937 | // messages. |
| 3938 | mH.sendMessageAtFrontOfQueue(m); |
| 3939 | } |
| 3940 | } |
| 3941 | |
| 3942 | public void setAppWillBeHidden(IBinder token) { |
| 3943 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3944 | "setAppWillBeHidden()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3945 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3946 | } |
| 3947 | |
| 3948 | AppWindowToken wtoken; |
| 3949 | |
| 3950 | synchronized(mWindowMap) { |
| 3951 | wtoken = findAppWindowToken(token); |
| 3952 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3953 | 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] | 3954 | return; |
| 3955 | } |
| 3956 | wtoken.willBeHidden = true; |
| 3957 | } |
| 3958 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3959 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3960 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3961 | boolean visible, int transit, boolean performLayout) { |
| 3962 | boolean delayed = false; |
| 3963 | |
| 3964 | if (wtoken.clientHidden == visible) { |
| 3965 | wtoken.clientHidden = !visible; |
| 3966 | wtoken.sendAppVisibilityToClients(); |
| 3967 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3968 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3969 | wtoken.willBeHidden = false; |
| 3970 | if (wtoken.hidden == visible) { |
| 3971 | final int N = wtoken.allAppWindows.size(); |
| 3972 | boolean changed = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3973 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3974 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3975 | + " performLayout=" + performLayout); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3976 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3977 | boolean runningAppAnimation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3978 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3979 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3980 | if (wtoken.animation == sDummyAnimation) { |
| 3981 | wtoken.animation = null; |
| 3982 | } |
| 3983 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 3984 | changed = true; |
| 3985 | if (wtoken.animation != null) { |
| 3986 | delayed = runningAppAnimation = true; |
| 3987 | } |
| 3988 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3989 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3990 | for (int i=0; i<N; i++) { |
| 3991 | WindowState win = wtoken.allAppWindows.get(i); |
| 3992 | if (win == wtoken.startingWindow) { |
| 3993 | continue; |
| 3994 | } |
| 3995 | |
| 3996 | if (win.isAnimating()) { |
| 3997 | delayed = true; |
| 3998 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3999 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4000 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4001 | //win.dump(" "); |
| 4002 | if (visible) { |
| 4003 | if (!win.isVisibleNow()) { |
| 4004 | if (!runningAppAnimation) { |
| 4005 | applyAnimationLocked(win, |
| 4006 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 4007 | } |
| 4008 | changed = true; |
| 4009 | } |
| 4010 | } else if (win.isVisibleNow()) { |
| 4011 | if (!runningAppAnimation) { |
| 4012 | applyAnimationLocked(win, |
| 4013 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 4014 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4015 | changed = true; |
| 4016 | } |
| 4017 | } |
| 4018 | |
| 4019 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 4020 | if (!visible) { |
| 4021 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 4022 | } else { |
| 4023 | // If we are being set visible, and the starting window is |
| 4024 | // not yet displayed, then make sure it doesn't get displayed. |
| 4025 | WindowState swin = wtoken.startingWindow; |
| 4026 | if (swin != null && (swin.mDrawPending |
| 4027 | || swin.mCommitDrawPending)) { |
| 4028 | swin.mPolicyVisibility = false; |
| 4029 | swin.mPolicyVisibilityAfterAnim = false; |
| 4030 | } |
| 4031 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4032 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4033 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4034 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 4035 | + wtoken.hiddenRequested); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4036 | |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 4037 | if (changed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4038 | mLayoutNeeded = true; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4039 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 4040 | if (performLayout) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4041 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4042 | false /*updateInputWindows*/); |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 4043 | performLayoutAndPlaceSurfacesLocked(); |
| 4044 | } |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4045 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4046 | } |
| 4047 | } |
| 4048 | |
| 4049 | if (wtoken.animation != null) { |
| 4050 | delayed = true; |
| 4051 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4052 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4053 | return delayed; |
| 4054 | } |
| 4055 | |
| 4056 | public void setAppVisibility(IBinder token, boolean visible) { |
| 4057 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4058 | "setAppVisibility()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4059 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4060 | } |
| 4061 | |
| 4062 | AppWindowToken wtoken; |
| 4063 | |
| 4064 | synchronized(mWindowMap) { |
| 4065 | wtoken = findAppWindowToken(token); |
| 4066 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4067 | 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] | 4068 | return; |
| 4069 | } |
| 4070 | |
| 4071 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 4072 | RuntimeException e = null; |
| 4073 | if (!HIDE_STACK_CRAWLS) { |
| 4074 | e = new RuntimeException(); |
| 4075 | e.fillInStackTrace(); |
| 4076 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4077 | Slog.v(TAG, "setAppVisibility(" + token + ", " + visible |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4078 | + "): mNextAppTransition=" + mNextAppTransition |
| 4079 | + " hidden=" + wtoken.hidden |
| 4080 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 4081 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4082 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4083 | // If we are preparing an app transition, then delay changing |
| 4084 | // the visibility of this token until we execute that transition. |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 4085 | if (!mDisplayFrozen && mPolicy.isScreenOn() |
| 4086 | && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4087 | // Already in requested state, don't do anything more. |
| 4088 | if (wtoken.hiddenRequested != visible) { |
| 4089 | return; |
| 4090 | } |
| 4091 | wtoken.hiddenRequested = !visible; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4092 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4093 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4094 | TAG, "Setting dummy animation on: " + wtoken); |
| 4095 | wtoken.setDummyAnimation(); |
| 4096 | mOpeningApps.remove(wtoken); |
| 4097 | mClosingApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4098 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4099 | wtoken.inPendingTransaction = true; |
| 4100 | if (visible) { |
| 4101 | mOpeningApps.add(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4102 | wtoken.startingDisplayed = false; |
| 4103 | wtoken.startingMoved = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4104 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4105 | // If the token is currently hidden (should be the |
| 4106 | // common case), then we need to set up to wait for |
| 4107 | // its windows to be ready. |
| 4108 | if (wtoken.hidden) { |
| 4109 | wtoken.allDrawn = false; |
| 4110 | wtoken.waitingToShow = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4111 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4112 | if (wtoken.clientHidden) { |
| 4113 | // In the case where we are making an app visible |
| 4114 | // but holding off for a transition, we still need |
| 4115 | // to tell the client to make its windows visible so |
| 4116 | // they get drawn. Otherwise, we will wait on |
| 4117 | // performing the transition until all windows have |
| 4118 | // been drawn, they never will be, and we are sad. |
| 4119 | wtoken.clientHidden = false; |
| 4120 | wtoken.sendAppVisibilityToClients(); |
| 4121 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4122 | } |
| 4123 | } else { |
| 4124 | mClosingApps.add(wtoken); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4125 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4126 | // If the token is currently visible (should be the |
| 4127 | // common case), then set up to wait for it to be hidden. |
| 4128 | if (!wtoken.hidden) { |
| 4129 | wtoken.waitingToHide = true; |
| 4130 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4131 | } |
| 4132 | return; |
| 4133 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4134 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4135 | final long origId = Binder.clearCallingIdentity(); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4136 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4137 | wtoken.updateReportedVisibilityLocked(); |
| 4138 | Binder.restoreCallingIdentity(origId); |
| 4139 | } |
| 4140 | } |
| 4141 | |
| 4142 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4143 | boolean unfreezeSurfaceNow, boolean force) { |
| 4144 | if (wtoken.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4145 | 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] | 4146 | + " force=" + force); |
| 4147 | final int N = wtoken.allAppWindows.size(); |
| 4148 | boolean unfrozeWindows = false; |
| 4149 | for (int i=0; i<N; i++) { |
| 4150 | WindowState w = wtoken.allAppWindows.get(i); |
| 4151 | if (w.mAppFreezing) { |
| 4152 | w.mAppFreezing = false; |
| 4153 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 4154 | w.mOrientationChanging = true; |
| 4155 | } |
| 4156 | unfrozeWindows = true; |
| 4157 | } |
| 4158 | } |
| 4159 | if (force || unfrozeWindows) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4160 | 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] | 4161 | wtoken.freezingScreen = false; |
| 4162 | mAppsFreezingScreen--; |
| 4163 | } |
| 4164 | if (unfreezeSurfaceNow) { |
| 4165 | if (unfrozeWindows) { |
| 4166 | mLayoutNeeded = true; |
| 4167 | performLayoutAndPlaceSurfacesLocked(); |
| 4168 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4169 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4170 | } |
| 4171 | } |
| 4172 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4173 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4174 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4175 | int configChanges) { |
| 4176 | if (DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 4177 | RuntimeException e = null; |
| 4178 | if (!HIDE_STACK_CRAWLS) { |
| 4179 | e = new RuntimeException(); |
| 4180 | e.fillInStackTrace(); |
| 4181 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4182 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4183 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 4184 | + wtoken.freezingScreen, e); |
| 4185 | } |
| 4186 | if (!wtoken.hiddenRequested) { |
| 4187 | if (!wtoken.freezingScreen) { |
| 4188 | wtoken.freezingScreen = true; |
| 4189 | mAppsFreezingScreen++; |
| 4190 | if (mAppsFreezingScreen == 1) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4191 | startFreezingDisplayLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4192 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 4193 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 4194 | 5000); |
| 4195 | } |
| 4196 | } |
| 4197 | final int N = wtoken.allAppWindows.size(); |
| 4198 | for (int i=0; i<N; i++) { |
| 4199 | WindowState w = wtoken.allAppWindows.get(i); |
| 4200 | w.mAppFreezing = true; |
| 4201 | } |
| 4202 | } |
| 4203 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4204 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4205 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 4206 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4207 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4208 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4209 | } |
| 4210 | |
| 4211 | synchronized(mWindowMap) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 4212 | if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4213 | 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] | 4214 | return; |
| 4215 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4216 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4217 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4218 | if (wtoken == null || wtoken.appToken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4219 | 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] | 4220 | return; |
| 4221 | } |
| 4222 | final long origId = Binder.clearCallingIdentity(); |
| 4223 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 4224 | Binder.restoreCallingIdentity(origId); |
| 4225 | } |
| 4226 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4227 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4228 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 4229 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4230 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4231 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4232 | } |
| 4233 | |
| 4234 | synchronized(mWindowMap) { |
| 4235 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4236 | if (wtoken == null || wtoken.appToken == null) { |
| 4237 | return; |
| 4238 | } |
| 4239 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4240 | 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] | 4241 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 4242 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 4243 | Binder.restoreCallingIdentity(origId); |
| 4244 | } |
| 4245 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4246 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4247 | public void removeAppToken(IBinder token) { |
| 4248 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4249 | "removeAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4250 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4251 | } |
| 4252 | |
| 4253 | AppWindowToken wtoken = null; |
| 4254 | AppWindowToken startingToken = null; |
| 4255 | boolean delayed = false; |
| 4256 | |
| 4257 | final long origId = Binder.clearCallingIdentity(); |
| 4258 | synchronized(mWindowMap) { |
| 4259 | WindowToken basewtoken = mTokenMap.remove(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4260 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4261 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4262 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4263 | wtoken.inPendingTransaction = false; |
| 4264 | mOpeningApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4265 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4266 | if (mClosingApps.contains(wtoken)) { |
| 4267 | delayed = true; |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4268 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4269 | mClosingApps.add(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4270 | wtoken.waitingToHide = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4271 | delayed = true; |
| 4272 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4273 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4274 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 4275 | + " animation=" + wtoken.animation |
| 4276 | + " animating=" + wtoken.animating); |
| 4277 | if (delayed) { |
| 4278 | // 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] | 4279 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4280 | "removeAppToken make exiting: " + wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4281 | mExitingAppTokens.add(wtoken); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 4282 | } else { |
| 4283 | // Make sure there is no animation running on this token, |
| 4284 | // so any windows associated with it will be removed as |
| 4285 | // soon as their animations are complete |
| 4286 | wtoken.animation = null; |
| 4287 | wtoken.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4288 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4289 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4290 | "removeAppToken: " + wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4291 | mAppTokens.remove(wtoken); |
| 4292 | wtoken.removed = true; |
| 4293 | if (wtoken.startingData != null) { |
| 4294 | startingToken = wtoken; |
| 4295 | } |
| 4296 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 4297 | if (mFocusedApp == wtoken) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4298 | 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] | 4299 | mFocusedApp = null; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4300 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4301 | mInputMonitor.setFocusedAppLw(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4302 | } |
| 4303 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4304 | 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] | 4305 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4306 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4307 | if (!delayed && wtoken != null) { |
| 4308 | wtoken.updateReportedVisibilityLocked(); |
| 4309 | } |
| 4310 | } |
| 4311 | Binder.restoreCallingIdentity(origId); |
| 4312 | |
| 4313 | if (startingToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4314 | 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] | 4315 | + startingToken + ": app token removed"); |
| 4316 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 4317 | mH.sendMessage(m); |
| 4318 | } |
| 4319 | } |
| 4320 | |
| 4321 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 4322 | final int NW = token.windows.size(); |
| 4323 | for (int i=0; i<NW; i++) { |
| 4324 | WindowState win = token.windows.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4325 | 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] | 4326 | mWindows.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4327 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4328 | int j = win.mChildWindows.size(); |
| 4329 | while (j > 0) { |
| 4330 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4331 | WindowState cwin = win.mChildWindows.get(j); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4332 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4333 | "Tmp removing child window " + cwin); |
| 4334 | mWindows.remove(cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4335 | } |
| 4336 | } |
| 4337 | return NW > 0; |
| 4338 | } |
| 4339 | |
| 4340 | void dumpAppTokensLocked() { |
| 4341 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4342 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4343 | } |
| 4344 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4345 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4346 | void dumpWindowsLocked() { |
| 4347 | for (int i=mWindows.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4348 | Slog.v(TAG, " #" + i + ": " + mWindows.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4349 | } |
| 4350 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4351 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4352 | private int findWindowOffsetLocked(int tokenPos) { |
| 4353 | final int NW = mWindows.size(); |
| 4354 | |
| 4355 | if (tokenPos >= mAppTokens.size()) { |
| 4356 | int i = NW; |
| 4357 | while (i > 0) { |
| 4358 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4359 | WindowState win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4360 | if (win.getAppToken() != null) { |
| 4361 | return i+1; |
| 4362 | } |
| 4363 | } |
| 4364 | } |
| 4365 | |
| 4366 | while (tokenPos > 0) { |
| 4367 | // Find the first app token below the new position that has |
| 4368 | // a window displayed. |
| 4369 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4370 | 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] | 4371 | + tokenPos + " -- " + wtoken.token); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4372 | if (wtoken.sendingToBottom) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4373 | if (DEBUG_REORDER) Slog.v(TAG, |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4374 | "Skipping token -- currently sending to bottom"); |
| 4375 | tokenPos--; |
| 4376 | continue; |
| 4377 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4378 | int i = wtoken.windows.size(); |
| 4379 | while (i > 0) { |
| 4380 | i--; |
| 4381 | WindowState win = wtoken.windows.get(i); |
| 4382 | int j = win.mChildWindows.size(); |
| 4383 | while (j > 0) { |
| 4384 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4385 | WindowState cwin = win.mChildWindows.get(j); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4386 | if (cwin.mSubLayer >= 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4387 | for (int pos=NW-1; pos>=0; pos--) { |
| 4388 | if (mWindows.get(pos) == cwin) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4389 | if (DEBUG_REORDER) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4390 | "Found child win @" + (pos+1)); |
| 4391 | return pos+1; |
| 4392 | } |
| 4393 | } |
| 4394 | } |
| 4395 | } |
| 4396 | for (int pos=NW-1; pos>=0; pos--) { |
| 4397 | if (mWindows.get(pos) == win) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4398 | 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] | 4399 | return pos+1; |
| 4400 | } |
| 4401 | } |
| 4402 | } |
| 4403 | tokenPos--; |
| 4404 | } |
| 4405 | |
| 4406 | return 0; |
| 4407 | } |
| 4408 | |
| 4409 | private final int reAddWindowLocked(int index, WindowState win) { |
| 4410 | final int NCW = win.mChildWindows.size(); |
| 4411 | boolean added = false; |
| 4412 | for (int j=0; j<NCW; j++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4413 | WindowState cwin = win.mChildWindows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4414 | if (!added && cwin.mSubLayer >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4415 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4416 | + index + ": " + cwin); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4417 | win.mRebuilding = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4418 | mWindows.add(index, win); |
| 4419 | index++; |
| 4420 | added = true; |
| 4421 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4422 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4423 | + index + ": " + cwin); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4424 | cwin.mRebuilding = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4425 | mWindows.add(index, cwin); |
| 4426 | index++; |
| 4427 | } |
| 4428 | if (!added) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4429 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4430 | + index + ": " + win); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4431 | win.mRebuilding = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4432 | mWindows.add(index, win); |
| 4433 | index++; |
| 4434 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4435 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4436 | return index; |
| 4437 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4438 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4439 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 4440 | final int NW = token.windows.size(); |
| 4441 | for (int i=0; i<NW; i++) { |
| 4442 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 4443 | } |
| 4444 | return index; |
| 4445 | } |
| 4446 | |
| 4447 | public void moveAppToken(int index, IBinder token) { |
| 4448 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4449 | "moveAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4450 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4451 | } |
| 4452 | |
| 4453 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4454 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4455 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 4456 | final AppWindowToken wtoken = findAppWindowToken(token); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4457 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG, |
| 4458 | "Start moving token " + wtoken + " initially at " |
| 4459 | + mAppTokens.indexOf(wtoken)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4460 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4461 | 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] | 4462 | + token + " (" + wtoken + ")"); |
| 4463 | return; |
| 4464 | } |
| 4465 | mAppTokens.add(index, wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4466 | if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4467 | 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] | 4468 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
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 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4471 | 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] | 4472 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4473 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4474 | 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] | 4475 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4476 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4477 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4478 | if (DEBUG_REORDER) dumpWindowsLocked(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4479 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4480 | false /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4481 | mLayoutNeeded = true; |
| 4482 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4483 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4484 | } |
| 4485 | Binder.restoreCallingIdentity(origId); |
| 4486 | } |
| 4487 | } |
| 4488 | |
| 4489 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 4490 | // XXX This should be done more efficiently! |
| 4491 | // (take advantage of the fact that both lists should be |
| 4492 | // ordered in the same way.) |
| 4493 | int N = tokens.size(); |
| 4494 | for (int i=0; i<N; i++) { |
| 4495 | IBinder token = tokens.get(i); |
| 4496 | final AppWindowToken wtoken = findAppWindowToken(token); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4497 | if (DEBUG_REORDER || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4498 | "Temporarily removing " + wtoken + " from " + mAppTokens.indexOf(wtoken)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4499 | if (!mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4500 | 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] | 4501 | + token + " (" + wtoken + ")"); |
| 4502 | i--; |
| 4503 | N--; |
| 4504 | } |
| 4505 | } |
| 4506 | } |
| 4507 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4508 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 4509 | boolean updateFocusAndLayout) { |
| 4510 | // First remove all of the windows from the list. |
| 4511 | tmpRemoveAppWindowsLocked(wtoken); |
| 4512 | |
| 4513 | // Where to start adding? |
| 4514 | int pos = findWindowOffsetLocked(tokenPos); |
| 4515 | |
| 4516 | // And now add them back at the correct place. |
| 4517 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 4518 | |
| 4519 | if (updateFocusAndLayout) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4520 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4521 | false /*updateInputWindows*/)) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4522 | assignLayersLocked(); |
| 4523 | } |
| 4524 | mLayoutNeeded = true; |
| 4525 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4526 | mInputMonitor.updateInputWindowsLw(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4527 | } |
| 4528 | } |
| 4529 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4530 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 4531 | // First remove all of the windows from the list. |
| 4532 | final int N = tokens.size(); |
| 4533 | int i; |
| 4534 | for (i=0; i<N; i++) { |
| 4535 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4536 | if (token != null) { |
| 4537 | tmpRemoveAppWindowsLocked(token); |
| 4538 | } |
| 4539 | } |
| 4540 | |
| 4541 | // Where to start adding? |
| 4542 | int pos = findWindowOffsetLocked(tokenPos); |
| 4543 | |
| 4544 | // And now add them back at the correct place. |
| 4545 | for (i=0; i<N; i++) { |
| 4546 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4547 | if (token != null) { |
| 4548 | pos = reAddAppWindowsLocked(pos, token); |
| 4549 | } |
| 4550 | } |
| 4551 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4552 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4553 | false /*updateInputWindows*/)) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4554 | assignLayersLocked(); |
| 4555 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4556 | mLayoutNeeded = true; |
| 4557 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4558 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4559 | |
| 4560 | //dump(); |
| 4561 | } |
| 4562 | |
| 4563 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4564 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4565 | "moveAppTokensToTop()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4566 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4567 | } |
| 4568 | |
| 4569 | final long origId = Binder.clearCallingIdentity(); |
| 4570 | synchronized(mWindowMap) { |
| 4571 | removeAppTokensLocked(tokens); |
| 4572 | final int N = tokens.size(); |
| 4573 | for (int i=0; i<N; i++) { |
| 4574 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4575 | if (wt != null) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4576 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG, |
| 4577 | "Adding next to top: " + wt); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4578 | mAppTokens.add(wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4579 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4580 | mToTopApps.remove(wt); |
| 4581 | mToBottomApps.remove(wt); |
| 4582 | mToTopApps.add(wt); |
| 4583 | wt.sendingToBottom = false; |
| 4584 | wt.sendingToTop = true; |
| 4585 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4586 | } |
| 4587 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4588 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4589 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4590 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4591 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4592 | } |
| 4593 | Binder.restoreCallingIdentity(origId); |
| 4594 | } |
| 4595 | |
| 4596 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4597 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4598 | "moveAppTokensToBottom()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4599 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4600 | } |
| 4601 | |
| 4602 | final long origId = Binder.clearCallingIdentity(); |
| 4603 | synchronized(mWindowMap) { |
| 4604 | removeAppTokensLocked(tokens); |
| 4605 | final int N = tokens.size(); |
| 4606 | int pos = 0; |
| 4607 | for (int i=0; i<N; i++) { |
| 4608 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4609 | if (wt != null) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4610 | if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4611 | "Adding next to bottom: " + wt + " at " + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4612 | mAppTokens.add(pos, wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4613 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4614 | mToTopApps.remove(wt); |
| 4615 | mToBottomApps.remove(wt); |
| 4616 | mToBottomApps.add(i, wt); |
| 4617 | wt.sendingToTop = false; |
| 4618 | wt.sendingToBottom = true; |
| 4619 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4620 | pos++; |
| 4621 | } |
| 4622 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4623 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4624 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4625 | moveAppWindowsLocked(tokens, 0); |
| 4626 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4627 | } |
| 4628 | Binder.restoreCallingIdentity(origId); |
| 4629 | } |
| 4630 | |
| 4631 | // ------------------------------------------------------------- |
| 4632 | // Misc IWindowSession methods |
| 4633 | // ------------------------------------------------------------- |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4634 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4635 | private boolean shouldAllowDisableKeyguard() |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4636 | { |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4637 | // We fail safe and prevent disabling keyguard in the unlikely event this gets |
| 4638 | // called before DevicePolicyManagerService has started. |
| 4639 | if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { |
| 4640 | DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( |
| 4641 | Context.DEVICE_POLICY_SERVICE); |
| 4642 | if (dpm != null) { |
| 4643 | mAllowDisableKeyguard = dpm.getPasswordQuality(null) |
| 4644 | == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? |
| 4645 | ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; |
| 4646 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4647 | } |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4648 | return mAllowDisableKeyguard == ALLOW_DISABLE_YES; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4649 | } |
| 4650 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4651 | public void disableKeyguard(IBinder token, String tag) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4652 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4653 | != PackageManager.PERMISSION_GRANTED) { |
| 4654 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4655 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4656 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4657 | synchronized (mKeyguardTokenWatcher) { |
| 4658 | mKeyguardTokenWatcher.acquire(token, tag); |
Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4659 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4660 | } |
| 4661 | |
| 4662 | public void reenableKeyguard(IBinder token) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4663 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4664 | != PackageManager.PERMISSION_GRANTED) { |
| 4665 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4666 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4667 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4668 | synchronized (mKeyguardTokenWatcher) { |
| 4669 | mKeyguardTokenWatcher.release(token); |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4670 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4671 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4672 | // If we are the last one to reenable the keyguard wait until |
| 4673 | // we have actually finished reenabling until returning. |
| 4674 | // It is possible that reenableKeyguard() can be called before |
| 4675 | // the previous disableKeyguard() is handled, in which case |
| 4676 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4677 | // be called. In that case mKeyguardDisabled will be false here |
| 4678 | // and we have nothing to wait for. |
| 4679 | while (mKeyguardDisabled) { |
| 4680 | try { |
| 4681 | mKeyguardTokenWatcher.wait(); |
| 4682 | } catch (InterruptedException e) { |
| 4683 | Thread.currentThread().interrupt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4684 | } |
| 4685 | } |
| 4686 | } |
| 4687 | } |
| 4688 | } |
| 4689 | |
| 4690 | /** |
| 4691 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4692 | */ |
| 4693 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4694 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4695 | != PackageManager.PERMISSION_GRANTED) { |
| 4696 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4697 | } |
| 4698 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4699 | public void onKeyguardExitResult(boolean success) { |
| 4700 | try { |
| 4701 | callback.onKeyguardExitResult(success); |
| 4702 | } catch (RemoteException e) { |
| 4703 | // Client has died, we don't care. |
| 4704 | } |
| 4705 | } |
| 4706 | }); |
| 4707 | } |
| 4708 | |
| 4709 | public boolean inKeyguardRestrictedInputMode() { |
| 4710 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4711 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4712 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4713 | public void closeSystemDialogs(String reason) { |
| 4714 | synchronized(mWindowMap) { |
| 4715 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4716 | WindowState w = mWindows.get(i); |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4717 | if (w.mSurface != null) { |
| 4718 | try { |
| 4719 | w.mClient.closeSystemDialogs(reason); |
| 4720 | } catch (RemoteException e) { |
| 4721 | } |
| 4722 | } |
| 4723 | } |
| 4724 | } |
| 4725 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4726 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4727 | static float fixScale(float scale) { |
| 4728 | if (scale < 0) scale = 0; |
| 4729 | else if (scale > 20) scale = 20; |
| 4730 | return Math.abs(scale); |
| 4731 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4732 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4733 | public void setAnimationScale(int which, float scale) { |
| 4734 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4735 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4736 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4737 | } |
| 4738 | |
| 4739 | if (scale < 0) scale = 0; |
| 4740 | else if (scale > 20) scale = 20; |
| 4741 | scale = Math.abs(scale); |
| 4742 | switch (which) { |
| 4743 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4744 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4745 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4746 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4747 | // Persist setting |
| 4748 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4749 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4750 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4751 | public void setAnimationScales(float[] scales) { |
| 4752 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4753 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4754 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4755 | } |
| 4756 | |
| 4757 | if (scales != null) { |
| 4758 | if (scales.length >= 1) { |
| 4759 | mWindowAnimationScale = fixScale(scales[0]); |
| 4760 | } |
| 4761 | if (scales.length >= 2) { |
| 4762 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4763 | } |
| 4764 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4765 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4766 | // Persist setting |
| 4767 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4768 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4769 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4770 | public float getAnimationScale(int which) { |
| 4771 | switch (which) { |
| 4772 | case 0: return mWindowAnimationScale; |
| 4773 | case 1: return mTransitionAnimationScale; |
| 4774 | } |
| 4775 | return 0; |
| 4776 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4777 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4778 | public float[] getAnimationScales() { |
| 4779 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4780 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4781 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4782 | public int getSwitchState(int sw) { |
| 4783 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4784 | "getSwitchState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4785 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4786 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4787 | return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4788 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4789 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4790 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4791 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4792 | "getSwitchStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4793 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4794 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4795 | return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4796 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4797 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4798 | public int getScancodeState(int sw) { |
| 4799 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4800 | "getScancodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4801 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4802 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4803 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4804 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4805 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4806 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4807 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4808 | "getScancodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4809 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4810 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4811 | return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4812 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4813 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4814 | public int getTrackballScancodeState(int sw) { |
| 4815 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4816 | "getTrackballScancodeState()")) { |
| 4817 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4818 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4819 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4820 | } |
| 4821 | |
| 4822 | public int getDPadScancodeState(int sw) { |
| 4823 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4824 | "getDPadScancodeState()")) { |
| 4825 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4826 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4827 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4828 | } |
| 4829 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4830 | public int getKeycodeState(int sw) { |
| 4831 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4832 | "getKeycodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4833 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4834 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4835 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4836 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4837 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4838 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4839 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4840 | "getKeycodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4841 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4842 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4843 | return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4844 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4845 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4846 | public int getTrackballKeycodeState(int sw) { |
| 4847 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4848 | "getTrackballKeycodeState()")) { |
| 4849 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4850 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4851 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4852 | } |
| 4853 | |
| 4854 | public int getDPadKeycodeState(int sw) { |
| 4855 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4856 | "getDPadKeycodeState()")) { |
| 4857 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4858 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4859 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4860 | } |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4861 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4862 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4863 | return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4864 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4865 | |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4866 | public InputChannel monitorInput(String inputChannelName) { |
| 4867 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4868 | "monitorInput()")) { |
| 4869 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4870 | } |
| 4871 | return mInputManager.monitorInput(inputChannelName); |
| 4872 | } |
| 4873 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 4874 | public InputDevice getInputDevice(int deviceId) { |
| 4875 | return mInputManager.getInputDevice(deviceId); |
| 4876 | } |
| 4877 | |
| 4878 | public int[] getInputDeviceIds() { |
| 4879 | return mInputManager.getInputDeviceIds(); |
| 4880 | } |
| 4881 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4882 | public void enableScreenAfterBoot() { |
| 4883 | synchronized(mWindowMap) { |
| 4884 | if (mSystemBooted) { |
| 4885 | return; |
| 4886 | } |
| 4887 | mSystemBooted = true; |
| 4888 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4889 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4890 | performEnableScreen(); |
| 4891 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4892 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4893 | public void enableScreenIfNeededLocked() { |
| 4894 | if (mDisplayEnabled) { |
| 4895 | return; |
| 4896 | } |
| 4897 | if (!mSystemBooted) { |
| 4898 | return; |
| 4899 | } |
| 4900 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4901 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4902 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4903 | public void performEnableScreen() { |
| 4904 | synchronized(mWindowMap) { |
| 4905 | if (mDisplayEnabled) { |
| 4906 | return; |
| 4907 | } |
| 4908 | if (!mSystemBooted) { |
| 4909 | return; |
| 4910 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4911 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4912 | // Don't enable the screen until all existing windows |
| 4913 | // have been drawn. |
| 4914 | final int N = mWindows.size(); |
| 4915 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4916 | WindowState w = mWindows.get(i); |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 4917 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4918 | return; |
| 4919 | } |
| 4920 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4921 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4922 | mDisplayEnabled = true; |
| 4923 | if (false) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4924 | Slog.i(TAG, "ENABLING SCREEN!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4925 | StringWriter sw = new StringWriter(); |
| 4926 | PrintWriter pw = new PrintWriter(sw); |
| 4927 | this.dump(null, pw, null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4928 | Slog.i(TAG, sw.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4929 | } |
| 4930 | try { |
| 4931 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4932 | if (surfaceFlinger != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4933 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4934 | Parcel data = Parcel.obtain(); |
| 4935 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4936 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4937 | data, null, 0); |
| 4938 | data.recycle(); |
| 4939 | } |
| 4940 | } catch (RemoteException ex) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4941 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4942 | } |
| 4943 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4944 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4945 | mPolicy.enableScreenAfterBoot(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4946 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4947 | // Make sure the last requested orientation has been applied. |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4948 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4949 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4950 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4951 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4952 | public void setInTouchMode(boolean mode) { |
| 4953 | synchronized(mWindowMap) { |
| 4954 | mInTouchMode = mode; |
| 4955 | } |
| 4956 | } |
| 4957 | |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 4958 | // TODO: more accounting of which pid(s) turned it on, keep count, |
| 4959 | // only allow disables from pids which have count on, etc. |
| 4960 | public void showStrictModeViolation(boolean on) { |
| 4961 | int pid = Binder.getCallingPid(); |
| 4962 | synchronized(mWindowMap) { |
| 4963 | // Ignoring requests to enable the red border from clients |
| 4964 | // which aren't on screen. (e.g. Broadcast Receivers in |
| 4965 | // the background..) |
| 4966 | if (on) { |
| 4967 | boolean isVisible = false; |
| 4968 | for (WindowState ws : mWindows) { |
| 4969 | if (ws.mSession.mPid == pid && ws.isVisibleLw()) { |
| 4970 | isVisible = true; |
| 4971 | break; |
| 4972 | } |
| 4973 | } |
| 4974 | if (!isVisible) { |
| 4975 | return; |
| 4976 | } |
| 4977 | } |
| 4978 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4979 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION showStrictModeViolation"); |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 4980 | Surface.openTransaction(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4981 | try { |
| 4982 | if (mStrictModeFlash == null) { |
| 4983 | mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession); |
| 4984 | } |
| 4985 | mStrictModeFlash.setVisibility(on); |
| 4986 | } finally { |
| 4987 | Surface.closeTransaction(); |
| 4988 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION showStrictModeViolation"); |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 4989 | } |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 4990 | } |
| 4991 | } |
| 4992 | |
Brad Fitzpatrick | c1a968a | 2010-11-24 08:56:40 -0800 | [diff] [blame] | 4993 | public void setStrictModeVisualIndicatorPreference(String value) { |
| 4994 | SystemProperties.set(StrictMode.VISUAL_PROPERTY, value); |
| 4995 | } |
| 4996 | |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 4997 | public Bitmap screenshotApplications(IBinder appToken, int maxWidth, int maxHeight) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4998 | if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER, |
| 4999 | "screenshotApplications()")) { |
| 5000 | throw new SecurityException("Requires READ_FRAME_BUFFER permission"); |
| 5001 | } |
| 5002 | |
| 5003 | Bitmap rawss; |
| 5004 | |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5005 | int maxLayer = 0; |
| 5006 | boolean foundApp; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5007 | final Rect frame = new Rect(); |
| 5008 | |
| 5009 | float scale; |
| 5010 | int sw, sh, dw, dh; |
| 5011 | int rot; |
| 5012 | |
| 5013 | synchronized(mWindowMap) { |
| 5014 | long ident = Binder.clearCallingIdentity(); |
| 5015 | |
| 5016 | int aboveAppLayer = mPolicy.windowTypeToLayerLw( |
| 5017 | WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER |
| 5018 | + TYPE_LAYER_OFFSET; |
| 5019 | aboveAppLayer += TYPE_LAYER_MULTIPLIER; |
| 5020 | |
| 5021 | // Figure out the part of the screen that is actually the app. |
| 5022 | for (int i=0; i<mWindows.size(); i++) { |
| 5023 | WindowState ws = mWindows.get(i); |
| 5024 | if (ws.mSurface == null) { |
| 5025 | continue; |
| 5026 | } |
| 5027 | if (ws.mLayer >= aboveAppLayer) { |
| 5028 | break; |
| 5029 | } |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5030 | if (appToken != null && (ws.mAppToken == null |
| 5031 | || ws.mAppToken.token != appToken)) { |
| 5032 | continue; |
| 5033 | } |
| 5034 | if (maxLayer < ws.mAnimLayer) { |
| 5035 | maxLayer = ws.mAnimLayer; |
| 5036 | } |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5037 | final Rect wf = ws.mFrame; |
| 5038 | final Rect cr = ws.mContentInsets; |
| 5039 | int left = wf.left + cr.left; |
| 5040 | int top = wf.top + cr.top; |
| 5041 | int right = wf.right - cr.right; |
| 5042 | int bottom = wf.bottom - cr.bottom; |
| 5043 | frame.union(left, top, right, bottom); |
| 5044 | } |
| 5045 | Binder.restoreCallingIdentity(ident); |
| 5046 | |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5047 | if (frame.isEmpty() || maxLayer == 0) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5048 | return null; |
| 5049 | } |
| 5050 | |
| 5051 | // The screenshot API does not apply the current screen rotation. |
| 5052 | rot = mDisplay.getRotation(); |
| 5053 | int fw = frame.width(); |
| 5054 | int fh = frame.height(); |
| 5055 | |
| 5056 | // First try reducing to fit in x dimension. |
| 5057 | scale = maxWidth/(float)fw; |
| 5058 | sw = maxWidth; |
| 5059 | sh = (int)(fh*scale); |
| 5060 | if (sh > maxHeight) { |
| 5061 | // y dimension became too long; constrain by that. |
| 5062 | scale = maxHeight/(float)fh; |
| 5063 | sw = (int)(fw*scale); |
| 5064 | sh = maxHeight; |
| 5065 | } |
| 5066 | |
| 5067 | // The screen shot will contain the entire screen. |
| 5068 | dw = (int)(mDisplay.getWidth()*scale); |
| 5069 | dh = (int)(mDisplay.getHeight()*scale); |
| 5070 | if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) { |
| 5071 | int tmp = dw; |
| 5072 | dw = dh; |
| 5073 | dh = tmp; |
| 5074 | rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90; |
| 5075 | } |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5076 | rawss = Surface.screenshot(dw, dh, 0, maxLayer); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5077 | } |
| 5078 | |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5079 | if (rawss == null) { |
Dianne Hackborn | 88b03bd | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5080 | Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh |
| 5081 | + ") to layer " + maxLayer); |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5082 | return null; |
| 5083 | } |
| 5084 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5085 | Bitmap bm = Bitmap.createBitmap(sw, sh, rawss.getConfig()); |
| 5086 | Matrix matrix = new Matrix(); |
| 5087 | ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix); |
| 5088 | matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale)); |
| 5089 | Canvas canvas = new Canvas(bm); |
| 5090 | canvas.drawBitmap(rawss, matrix, null); |
| 5091 | |
| 5092 | rawss.recycle(); |
| 5093 | return bm; |
| 5094 | } |
| 5095 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5096 | public void freezeRotation() { |
| 5097 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| 5098 | "setRotation()")) { |
| 5099 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 5100 | } |
| 5101 | |
| 5102 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation); |
| 5103 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0); |
| 5104 | } |
| 5105 | |
| 5106 | public void thawRotation() { |
| 5107 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| 5108 | "setRotation()")) { |
| 5109 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 5110 | } |
| 5111 | |
| 5112 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0); |
| 5113 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0); |
| 5114 | } |
| 5115 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5116 | public void setRotation(int rotation, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 5117 | boolean alwaysSendConfiguration, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5118 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 5119 | "setRotation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5120 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5121 | } |
| 5122 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 5123 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5124 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5125 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 5126 | public void setRotationUnchecked(int rotation, |
| 5127 | boolean alwaysSendConfiguration, int animFlags) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5128 | if(DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5129 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5130 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5131 | long origId = Binder.clearCallingIdentity(); |
| 5132 | boolean changed; |
| 5133 | synchronized(mWindowMap) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5134 | changed = setRotationUncheckedLocked(rotation, animFlags, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5135 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5136 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5137 | if (changed || alwaysSendConfiguration) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5138 | sendNewConfiguration(); |
| 5139 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5141 | Binder.restoreCallingIdentity(origId); |
| 5142 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5143 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5144 | /** |
| 5145 | * Apply a new rotation to the screen, respecting the requests of |
| 5146 | * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply |
| 5147 | * re-evaluate the desired rotation. |
| 5148 | * |
| 5149 | * Returns null if the rotation has been changed. In this case YOU |
| 5150 | * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN. |
| 5151 | */ |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5152 | public boolean setRotationUncheckedLocked(int rotation, int animFlags, boolean inTransaction) { |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame^] | 5153 | if (mDragState != null || mScreenRotationAnimation != null) { |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 5154 | // Potential rotation during a drag. Don't do the rotation now, but make |
| 5155 | // a note to perform the rotation later. |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame^] | 5156 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation."); |
| 5157 | if (rotation != WindowManagerPolicy.USE_LAST_ROTATION) { |
| 5158 | mDeferredRotation = rotation; |
| 5159 | mDeferredRotationAnimFlags = animFlags; |
| 5160 | } |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 5161 | return false; |
| 5162 | } |
| 5163 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5164 | boolean changed; |
| 5165 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame^] | 5166 | if (mDeferredRotation != WindowManagerPolicy.USE_LAST_ROTATION) { |
| 5167 | rotation = mDeferredRotation; |
| 5168 | mRequestedRotation = rotation; |
| 5169 | mLastRotationFlags = mDeferredRotationAnimFlags; |
| 5170 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5171 | rotation = mRequestedRotation; |
| 5172 | } else { |
| 5173 | mRequestedRotation = rotation; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 5174 | mLastRotationFlags = animFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5175 | } |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame^] | 5176 | mDeferredRotation = WindowManagerPolicy.USE_LAST_ROTATION; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5177 | 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] | 5178 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5179 | mRotation, mDisplayEnabled); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5180 | if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5181 | changed = mDisplayEnabled && mRotation != rotation; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5182 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5183 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5184 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5185 | "Rotation changed to " + rotation |
| 5186 | + " from " + mRotation |
| 5187 | + " (forceApp=" + mForcedAppOrientation |
| 5188 | + ", req=" + mRequestedRotation + ")"); |
| 5189 | mRotation = rotation; |
| 5190 | mWindowsFreezingScreen = true; |
| 5191 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 5192 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 5193 | 2000); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5194 | mWaitingForConfig = true; |
| 5195 | mLayoutNeeded = true; |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5196 | startFreezingDisplayLocked(inTransaction); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5197 | Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5198 | mInputManager.setDisplayOrientation(0, rotation); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5199 | if (mDisplayEnabled) { |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 5200 | if (CUSTOM_SCREEN_ROTATION) { |
| 5201 | Surface.freezeDisplay(0); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5202 | if (!inTransaction) { |
| 5203 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 5204 | ">>> OPEN TRANSACTION setRotationUnchecked"); |
| 5205 | Surface.openTransaction(); |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 5206 | } |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5207 | try { |
| 5208 | if (mScreenRotationAnimation != null) { |
| 5209 | mScreenRotationAnimation.setRotation(rotation); |
| 5210 | } |
| 5211 | } finally { |
| 5212 | if (!inTransaction) { |
| 5213 | Surface.closeTransaction(); |
| 5214 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 5215 | "<<< CLOSE TRANSACTION setRotationUnchecked"); |
| 5216 | } |
| 5217 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 5218 | Surface.setOrientation(0, rotation, animFlags); |
| 5219 | Surface.unfreezeDisplay(0); |
| 5220 | } else { |
| 5221 | Surface.setOrientation(0, rotation, animFlags); |
| 5222 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5223 | } |
| 5224 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5225 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5226 | if (w.mSurface != null) { |
| 5227 | w.mOrientationChanging = true; |
| 5228 | } |
| 5229 | } |
| 5230 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 5231 | try { |
| 5232 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 5233 | } catch (RemoteException e) { |
| 5234 | } |
| 5235 | } |
| 5236 | } //end if changed |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5237 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5238 | return changed; |
| 5239 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5240 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5241 | public int getRotation() { |
| 5242 | return mRotation; |
| 5243 | } |
| 5244 | |
| 5245 | public int watchRotation(IRotationWatcher watcher) { |
| 5246 | final IBinder watcherBinder = watcher.asBinder(); |
| 5247 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 5248 | public void binderDied() { |
| 5249 | synchronized (mWindowMap) { |
| 5250 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 5251 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 5252 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 5253 | if (removed != null) { |
| 5254 | removed.asBinder().unlinkToDeath(this, 0); |
| 5255 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5256 | i--; |
| 5257 | } |
| 5258 | } |
| 5259 | } |
| 5260 | } |
| 5261 | }; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5262 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5263 | synchronized (mWindowMap) { |
| 5264 | try { |
| 5265 | watcher.asBinder().linkToDeath(dr, 0); |
| 5266 | mRotationWatchers.add(watcher); |
| 5267 | } catch (RemoteException e) { |
| 5268 | // Client died, no cleanup needed. |
| 5269 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5270 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5271 | return mRotation; |
| 5272 | } |
| 5273 | } |
| 5274 | |
| 5275 | /** |
| 5276 | * Starts the view server on the specified port. |
| 5277 | * |
| 5278 | * @param port The port to listener to. |
| 5279 | * |
| 5280 | * @return True if the server was successfully started, false otherwise. |
| 5281 | * |
| 5282 | * @see com.android.server.ViewServer |
| 5283 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 5284 | */ |
| 5285 | public boolean startViewServer(int port) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5286 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5287 | return false; |
| 5288 | } |
| 5289 | |
| 5290 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 5291 | return false; |
| 5292 | } |
| 5293 | |
| 5294 | if (port < 1024) { |
| 5295 | return false; |
| 5296 | } |
| 5297 | |
| 5298 | if (mViewServer != null) { |
| 5299 | if (!mViewServer.isRunning()) { |
| 5300 | try { |
| 5301 | return mViewServer.start(); |
| 5302 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5303 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5304 | } |
| 5305 | } |
| 5306 | return false; |
| 5307 | } |
| 5308 | |
| 5309 | try { |
| 5310 | mViewServer = new ViewServer(this, port); |
| 5311 | return mViewServer.start(); |
| 5312 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5313 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5314 | } |
| 5315 | return false; |
| 5316 | } |
| 5317 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5318 | private boolean isSystemSecure() { |
| 5319 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 5320 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 5321 | } |
| 5322 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5323 | /** |
| 5324 | * Stops the view server if it exists. |
| 5325 | * |
| 5326 | * @return True if the server stopped, false if it wasn't started or |
| 5327 | * couldn't be stopped. |
| 5328 | * |
| 5329 | * @see com.android.server.ViewServer |
| 5330 | */ |
| 5331 | public boolean stopViewServer() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5332 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5333 | return false; |
| 5334 | } |
| 5335 | |
| 5336 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 5337 | return false; |
| 5338 | } |
| 5339 | |
| 5340 | if (mViewServer != null) { |
| 5341 | return mViewServer.stop(); |
| 5342 | } |
| 5343 | return false; |
| 5344 | } |
| 5345 | |
| 5346 | /** |
| 5347 | * Indicates whether the view server is running. |
| 5348 | * |
| 5349 | * @return True if the server is running, false otherwise. |
| 5350 | * |
| 5351 | * @see com.android.server.ViewServer |
| 5352 | */ |
| 5353 | public boolean isViewServerRunning() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5354 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5355 | return false; |
| 5356 | } |
| 5357 | |
| 5358 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 5359 | return false; |
| 5360 | } |
| 5361 | |
| 5362 | return mViewServer != null && mViewServer.isRunning(); |
| 5363 | } |
| 5364 | |
| 5365 | /** |
| 5366 | * Lists all availble windows in the system. The listing is written in the |
| 5367 | * specified Socket's output stream with the following syntax: |
| 5368 | * windowHashCodeInHexadecimal windowName |
| 5369 | * Each line of the ouput represents a different window. |
| 5370 | * |
| 5371 | * @param client The remote client to send the listing to. |
| 5372 | * @return False if an error occured, true otherwise. |
| 5373 | */ |
| 5374 | boolean viewServerListWindows(Socket client) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5375 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5376 | return false; |
| 5377 | } |
| 5378 | |
| 5379 | boolean result = true; |
| 5380 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5381 | WindowState[] windows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5382 | synchronized (mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5383 | //noinspection unchecked |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5384 | windows = mWindows.toArray(new WindowState[mWindows.size()]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5385 | } |
| 5386 | |
| 5387 | BufferedWriter out = null; |
| 5388 | |
| 5389 | // Any uncaught exception will crash the system process |
| 5390 | try { |
| 5391 | OutputStream clientStream = client.getOutputStream(); |
| 5392 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5393 | |
| 5394 | final int count = windows.length; |
| 5395 | for (int i = 0; i < count; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5396 | final WindowState w = windows[i]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5397 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 5398 | out.write(' '); |
| 5399 | out.append(w.mAttrs.getTitle()); |
| 5400 | out.write('\n'); |
| 5401 | } |
| 5402 | |
| 5403 | out.write("DONE.\n"); |
| 5404 | out.flush(); |
| 5405 | } catch (Exception e) { |
| 5406 | result = false; |
| 5407 | } finally { |
| 5408 | if (out != null) { |
| 5409 | try { |
| 5410 | out.close(); |
| 5411 | } catch (IOException e) { |
| 5412 | result = false; |
| 5413 | } |
| 5414 | } |
| 5415 | } |
| 5416 | |
| 5417 | return result; |
| 5418 | } |
| 5419 | |
| 5420 | /** |
Konstantin Lopyrev | f962476 | 2010-07-14 17:02:37 -0700 | [diff] [blame] | 5421 | * Returns the focused window in the following format: |
| 5422 | * windowHashCodeInHexadecimal windowName |
| 5423 | * |
| 5424 | * @param client The remote client to send the listing to. |
| 5425 | * @return False if an error occurred, true otherwise. |
| 5426 | */ |
| 5427 | boolean viewServerGetFocusedWindow(Socket client) { |
| 5428 | if (isSystemSecure()) { |
| 5429 | return false; |
| 5430 | } |
| 5431 | |
| 5432 | boolean result = true; |
| 5433 | |
| 5434 | WindowState focusedWindow = getFocusedWindow(); |
| 5435 | |
| 5436 | BufferedWriter out = null; |
| 5437 | |
| 5438 | // Any uncaught exception will crash the system process |
| 5439 | try { |
| 5440 | OutputStream clientStream = client.getOutputStream(); |
| 5441 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5442 | |
| 5443 | if(focusedWindow != null) { |
| 5444 | out.write(Integer.toHexString(System.identityHashCode(focusedWindow))); |
| 5445 | out.write(' '); |
| 5446 | out.append(focusedWindow.mAttrs.getTitle()); |
| 5447 | } |
| 5448 | out.write('\n'); |
| 5449 | out.flush(); |
| 5450 | } catch (Exception e) { |
| 5451 | result = false; |
| 5452 | } finally { |
| 5453 | if (out != null) { |
| 5454 | try { |
| 5455 | out.close(); |
| 5456 | } catch (IOException e) { |
| 5457 | result = false; |
| 5458 | } |
| 5459 | } |
| 5460 | } |
| 5461 | |
| 5462 | return result; |
| 5463 | } |
| 5464 | |
| 5465 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5466 | * Sends a command to a target window. The result of the command, if any, will be |
| 5467 | * written in the output stream of the specified socket. |
| 5468 | * |
| 5469 | * The parameters must follow this syntax: |
| 5470 | * windowHashcode extra |
| 5471 | * |
| 5472 | * Where XX is the length in characeters of the windowTitle. |
| 5473 | * |
| 5474 | * The first parameter is the target window. The window with the specified hashcode |
| 5475 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 5476 | * will be delivered to the target window and as parameters to the command itself. |
| 5477 | * |
| 5478 | * @param client The remote client to sent the result, if any, to. |
| 5479 | * @param command The command to execute. |
| 5480 | * @param parameters The command parameters. |
| 5481 | * |
| 5482 | * @return True if the command was successfully delivered, false otherwise. This does |
| 5483 | * not indicate whether the command itself was successful. |
| 5484 | */ |
| 5485 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5486 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5487 | return false; |
| 5488 | } |
| 5489 | |
| 5490 | boolean success = true; |
| 5491 | Parcel data = null; |
| 5492 | Parcel reply = null; |
| 5493 | |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5494 | BufferedWriter out = null; |
| 5495 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5496 | // Any uncaught exception will crash the system process |
| 5497 | try { |
| 5498 | // Find the hashcode of the window |
| 5499 | int index = parameters.indexOf(' '); |
| 5500 | if (index == -1) { |
| 5501 | index = parameters.length(); |
| 5502 | } |
| 5503 | final String code = parameters.substring(0, index); |
Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 5504 | int hashCode = (int) Long.parseLong(code, 16); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5505 | |
| 5506 | // Extract the command's parameter after the window description |
| 5507 | if (index < parameters.length()) { |
| 5508 | parameters = parameters.substring(index + 1); |
| 5509 | } else { |
| 5510 | parameters = ""; |
| 5511 | } |
| 5512 | |
| 5513 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 5514 | if (window == null) { |
| 5515 | return false; |
| 5516 | } |
| 5517 | |
| 5518 | data = Parcel.obtain(); |
| 5519 | data.writeInterfaceToken("android.view.IWindow"); |
| 5520 | data.writeString(command); |
| 5521 | data.writeString(parameters); |
| 5522 | data.writeInt(1); |
| 5523 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 5524 | |
| 5525 | reply = Parcel.obtain(); |
| 5526 | |
| 5527 | final IBinder binder = window.mClient.asBinder(); |
| 5528 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 5529 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 5530 | |
| 5531 | reply.readException(); |
| 5532 | |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5533 | if (!client.isOutputShutdown()) { |
| 5534 | out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream())); |
| 5535 | out.write("DONE\n"); |
| 5536 | out.flush(); |
| 5537 | } |
| 5538 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5539 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5540 | 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] | 5541 | success = false; |
| 5542 | } finally { |
| 5543 | if (data != null) { |
| 5544 | data.recycle(); |
| 5545 | } |
| 5546 | if (reply != null) { |
| 5547 | reply.recycle(); |
| 5548 | } |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5549 | if (out != null) { |
| 5550 | try { |
| 5551 | out.close(); |
| 5552 | } catch (IOException e) { |
| 5553 | |
| 5554 | } |
| 5555 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5556 | } |
| 5557 | |
| 5558 | return success; |
| 5559 | } |
| 5560 | |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 5561 | public void addWindowChangeListener(WindowChangeListener listener) { |
| 5562 | synchronized(mWindowMap) { |
| 5563 | mWindowChangeListeners.add(listener); |
| 5564 | } |
| 5565 | } |
| 5566 | |
| 5567 | public void removeWindowChangeListener(WindowChangeListener listener) { |
| 5568 | synchronized(mWindowMap) { |
| 5569 | mWindowChangeListeners.remove(listener); |
| 5570 | } |
| 5571 | } |
| 5572 | |
| 5573 | private void notifyWindowsChanged() { |
| 5574 | WindowChangeListener[] windowChangeListeners; |
| 5575 | synchronized(mWindowMap) { |
| 5576 | if(mWindowChangeListeners.isEmpty()) { |
| 5577 | return; |
| 5578 | } |
| 5579 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5580 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5581 | } |
| 5582 | int N = windowChangeListeners.length; |
| 5583 | for(int i = 0; i < N; i++) { |
| 5584 | windowChangeListeners[i].windowsChanged(); |
| 5585 | } |
| 5586 | } |
| 5587 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 5588 | private void notifyFocusChanged() { |
| 5589 | WindowChangeListener[] windowChangeListeners; |
| 5590 | synchronized(mWindowMap) { |
| 5591 | if(mWindowChangeListeners.isEmpty()) { |
| 5592 | return; |
| 5593 | } |
| 5594 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5595 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5596 | } |
| 5597 | int N = windowChangeListeners.length; |
| 5598 | for(int i = 0; i < N; i++) { |
| 5599 | windowChangeListeners[i].focusChanged(); |
| 5600 | } |
| 5601 | } |
| 5602 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5603 | private WindowState findWindow(int hashCode) { |
| 5604 | if (hashCode == -1) { |
| 5605 | return getFocusedWindow(); |
| 5606 | } |
| 5607 | |
| 5608 | synchronized (mWindowMap) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5609 | final ArrayList<WindowState> windows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5610 | final int count = windows.size(); |
| 5611 | |
| 5612 | for (int i = 0; i < count; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5613 | WindowState w = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5614 | if (System.identityHashCode(w) == hashCode) { |
| 5615 | return w; |
| 5616 | } |
| 5617 | } |
| 5618 | } |
| 5619 | |
| 5620 | return null; |
| 5621 | } |
| 5622 | |
| 5623 | /* |
| 5624 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 5625 | * that to config-changed listeners if appropriate. |
| 5626 | */ |
| 5627 | void sendNewConfiguration() { |
| 5628 | try { |
| 5629 | mActivityManager.updateConfiguration(null); |
| 5630 | } catch (RemoteException e) { |
| 5631 | } |
| 5632 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5633 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5634 | public Configuration computeNewConfiguration() { |
| 5635 | synchronized (mWindowMap) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5636 | Configuration config = computeNewConfigurationLocked(); |
| 5637 | if (config == null && mWaitingForConfig) { |
| 5638 | // Nothing changed but we are waiting for something... stop that! |
| 5639 | mWaitingForConfig = false; |
| 5640 | performLayoutAndPlaceSurfacesLocked(); |
| 5641 | } |
| 5642 | return config; |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5643 | } |
| 5644 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5645 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5646 | Configuration computeNewConfigurationLocked() { |
| 5647 | Configuration config = new Configuration(); |
| 5648 | if (!computeNewConfigurationLocked(config)) { |
| 5649 | return null; |
| 5650 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5651 | return config; |
| 5652 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5653 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5654 | boolean computeNewConfigurationLocked(Configuration config) { |
| 5655 | if (mDisplay == null) { |
| 5656 | return false; |
| 5657 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5658 | |
| 5659 | mInputManager.getInputConfiguration(config); |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 5660 | |
| 5661 | // Use the effective "visual" dimensions based on current rotation |
| 5662 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 5663 | || mRotation == Surface.ROTATION_270); |
| 5664 | final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; |
| 5665 | final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; |
| 5666 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5667 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 5668 | if (dw < dh) { |
| 5669 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 5670 | } else if (dw > dh) { |
| 5671 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 5672 | } |
| 5673 | config.orientation = orientation; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5674 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5675 | DisplayMetrics dm = new DisplayMetrics(); |
| 5676 | mDisplay.getMetrics(dm); |
| 5677 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 5678 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5679 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5680 | // Note we only do this once because at this point we don't |
| 5681 | // expect the screen to change in this way at runtime, and want |
| 5682 | // to avoid all of this computation for every config change. |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5683 | int longSize = dw; |
| 5684 | int shortSize = dh; |
| 5685 | if (longSize < shortSize) { |
| 5686 | int tmp = longSize; |
| 5687 | longSize = shortSize; |
| 5688 | shortSize = tmp; |
| 5689 | } |
| 5690 | longSize = (int)(longSize/dm.density); |
| 5691 | shortSize = (int)(shortSize/dm.density); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5692 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5693 | // These semi-magic numbers define our compatibility modes for |
| 5694 | // applications with different screens. Don't change unless you |
| 5695 | // make sure to test lots and lots of apps! |
| 5696 | if (longSize < 470) { |
| 5697 | // This is shorter than an HVGA normal density screen (which |
| 5698 | // is 480 pixels on its long side). |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5699 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 5700 | | Configuration.SCREENLAYOUT_LONG_NO; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5701 | } else { |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 5702 | // What size is this screen screen? |
| 5703 | if (longSize >= 800 && shortSize >= 600) { |
| 5704 | // SVGA or larger screens at medium density are the point |
| 5705 | // at which we consider it to be an extra large screen. |
| 5706 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE; |
Dianne Hackborn | b51dc0f | 2010-10-21 15:34:47 -0700 | [diff] [blame] | 5707 | } else if (longSize >= 530 && shortSize >= 400) { |
| 5708 | // SVGA or larger screens at high density are the point |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5709 | // at which we consider it to be a large screen. |
| 5710 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 5711 | } else { |
| 5712 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5713 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5714 | // If this screen is wider than normal HVGA, or taller |
| 5715 | // than FWVGA, then for old apps we want to run in size |
| 5716 | // compatibility mode. |
| 5717 | if (shortSize > 321 || longSize > 570) { |
| 5718 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 5719 | } |
| 5720 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5721 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5722 | // Is this a long screen? |
| 5723 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 5724 | // Anything wider than WVGA (5:3) is considering to be long. |
| 5725 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 5726 | } else { |
| 5727 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 5728 | } |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5729 | } |
| 5730 | } |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5731 | config.screenLayout = mScreenLayout; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5732 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5733 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 5734 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 5735 | mPolicy.adjustConfigurationLw(config); |
| 5736 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5737 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5738 | |
| 5739 | // ------------------------------------------------------------- |
| 5740 | // Drag and drop |
| 5741 | // ------------------------------------------------------------- |
| 5742 | |
| 5743 | IBinder prepareDragSurface(IWindow window, SurfaceSession session, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 5744 | int flags, int width, int height, Surface outSurface) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5745 | if (DEBUG_DRAG) { |
| 5746 | Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 5747 | + " flags=" + Integer.toHexString(flags) + " win=" + window |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5748 | + " asbinder=" + window.asBinder()); |
| 5749 | } |
| 5750 | |
| 5751 | final int callerPid = Binder.getCallingPid(); |
| 5752 | final long origId = Binder.clearCallingIdentity(); |
| 5753 | IBinder token = null; |
| 5754 | |
| 5755 | try { |
| 5756 | synchronized (mWindowMap) { |
| 5757 | try { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5758 | if (mDragState == null) { |
| 5759 | Surface surface = new Surface(session, callerPid, "drag surface", 0, |
| 5760 | width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN); |
| 5761 | outSurface.copyFrom(surface); |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 5762 | final IBinder winBinder = window.asBinder(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5763 | token = new Binder(); |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 5764 | // TODO: preserve flags param in DragState |
| 5765 | mDragState = new DragState(token, surface, 0, winBinder); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5766 | mDragState.mSurface = surface; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5767 | token = mDragState.mToken = new Binder(); |
| 5768 | |
| 5769 | // 5 second timeout for this window to actually begin the drag |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 5770 | mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder); |
| 5771 | Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5772 | mH.sendMessageDelayed(msg, 5000); |
| 5773 | } else { |
| 5774 | Slog.w(TAG, "Drag already in progress"); |
| 5775 | } |
| 5776 | } catch (Surface.OutOfResourcesException e) { |
| 5777 | Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e); |
| 5778 | if (mDragState != null) { |
| 5779 | mDragState.reset(); |
| 5780 | mDragState = null; |
| 5781 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5782 | } |
| 5783 | } |
| 5784 | } finally { |
| 5785 | Binder.restoreCallingIdentity(origId); |
| 5786 | } |
| 5787 | |
| 5788 | return token; |
| 5789 | } |
| 5790 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5791 | // ------------------------------------------------------------- |
| 5792 | // Input Events and Focus Management |
| 5793 | // ------------------------------------------------------------- |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5794 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5795 | InputMonitor mInputMonitor = new InputMonitor(); |
| 5796 | |
| 5797 | /* Tracks the progress of input dispatch and ensures that input dispatch state |
| 5798 | * is kept in sync with changes in window focus, visibility, registration, and |
| 5799 | * other relevant Window Manager state transitions. */ |
| 5800 | final class InputMonitor { |
| 5801 | // Current window with input focus for keys and other non-touch events. May be null. |
| 5802 | private WindowState mInputFocus; |
| 5803 | |
| 5804 | // When true, prevents input dispatch from proceeding until set to false again. |
| 5805 | private boolean mInputDispatchFrozen; |
| 5806 | |
| 5807 | // When true, input dispatch proceeds normally. Otherwise all events are dropped. |
| 5808 | private boolean mInputDispatchEnabled = true; |
| 5809 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 5810 | // When true, need to call updateInputWindowsLw(). |
| 5811 | private boolean mUpdateInputWindowsNeeded = true; |
| 5812 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5813 | // Temporary list of windows information to provide to the input dispatcher. |
| 5814 | private InputWindowList mTempInputWindows = new InputWindowList(); |
| 5815 | |
| 5816 | // Temporary input application object to provide to the input dispatcher. |
| 5817 | private InputApplication mTempInputApplication = new InputApplication(); |
| 5818 | |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 5819 | // Set to true when the first input device configuration change notification |
| 5820 | // is received to indicate that the input devices are ready. |
| 5821 | private final Object mInputDevicesReadyMonitor = new Object(); |
| 5822 | private boolean mInputDevicesReady; |
| 5823 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5824 | /* Notifies the window manager about a broken input channel. |
| 5825 | * |
| 5826 | * Called by the InputManager. |
| 5827 | */ |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5828 | public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) { |
| 5829 | if (inputWindowHandle == null) { |
| 5830 | return; |
| 5831 | } |
| 5832 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5833 | synchronized (mWindowMap) { |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5834 | WindowState windowState = (WindowState) inputWindowHandle.windowState; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5835 | Slog.i(TAG, "WINDOW DIED " + windowState); |
| 5836 | removeWindowLocked(windowState.mSession, windowState); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5837 | } |
| 5838 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5839 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5840 | /* Notifies the window manager about an application that is not responding. |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5841 | * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch. |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5842 | * |
| 5843 | * Called by the InputManager. |
| 5844 | */ |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5845 | public long notifyANR(InputApplicationHandle inputApplicationHandle, |
| 5846 | InputWindowHandle inputWindowHandle) { |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5847 | AppWindowToken appWindowToken = null; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5848 | if (inputWindowHandle != null) { |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5849 | synchronized (mWindowMap) { |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5850 | WindowState windowState = (WindowState) inputWindowHandle.windowState; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5851 | if (windowState != null) { |
| 5852 | Slog.i(TAG, "Input event dispatching timed out sending to " |
| 5853 | + windowState.mAttrs.getTitle()); |
| 5854 | appWindowToken = windowState.mAppToken; |
| 5855 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5856 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5857 | } |
| 5858 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5859 | if (appWindowToken == null && inputApplicationHandle != null) { |
| 5860 | appWindowToken = inputApplicationHandle.appWindowToken; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5861 | Slog.i(TAG, "Input event dispatching timed out sending to application " |
| 5862 | + appWindowToken.stringName); |
| 5863 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5864 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5865 | if (appWindowToken != null && appWindowToken.appToken != null) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5866 | try { |
| 5867 | // Notify the activity manager about the timeout and let it decide whether |
| 5868 | // to abort dispatching or keep waiting. |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5869 | boolean abort = appWindowToken.appToken.keyDispatchingTimedOut(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5870 | if (! abort) { |
| 5871 | // The activity manager declined to abort dispatching. |
| 5872 | // Wait a bit longer and timeout again later. |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5873 | return appWindowToken.inputDispatchingTimeoutNanos; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5874 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5875 | } catch (RemoteException ex) { |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5876 | } |
| 5877 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5878 | return 0; // abort dispatching |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5879 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5880 | |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 5881 | private void addDragInputWindowLw(InputWindowList windowList) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5882 | final InputWindow inputWindow = windowList.add(); |
| 5883 | inputWindow.inputChannel = mDragState.mServerChannel; |
| 5884 | inputWindow.name = "drag"; |
Christopher Tate | a159579 | 2011-01-19 17:26:50 -0800 | [diff] [blame] | 5885 | inputWindow.layoutParamsFlags = 0; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5886 | inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG; |
| 5887 | inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 5888 | inputWindow.visible = true; |
| 5889 | inputWindow.canReceiveKeys = false; |
| 5890 | inputWindow.hasFocus = true; |
| 5891 | inputWindow.hasWallpaper = false; |
| 5892 | inputWindow.paused = false; |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 5893 | inputWindow.layer = mDragState.getDragLayerLw(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5894 | inputWindow.ownerPid = Process.myPid(); |
| 5895 | inputWindow.ownerUid = Process.myUid(); |
| 5896 | |
| 5897 | // The drag window covers the entire display |
| 5898 | inputWindow.frameLeft = 0; |
| 5899 | inputWindow.frameTop = 0; |
| 5900 | inputWindow.frameRight = mDisplay.getWidth(); |
| 5901 | inputWindow.frameBottom = mDisplay.getHeight(); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 5902 | |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 5903 | // The drag window cannot receive new touches. |
| 5904 | inputWindow.touchableRegion.setEmpty(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5905 | } |
| 5906 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 5907 | public void setUpdateInputWindowsNeededLw() { |
| 5908 | mUpdateInputWindowsNeeded = true; |
| 5909 | } |
| 5910 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5911 | /* Updates the cached window information provided to the input dispatcher. */ |
| 5912 | public void updateInputWindowsLw() { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 5913 | if (!mUpdateInputWindowsNeeded) { |
| 5914 | return; |
| 5915 | } |
| 5916 | mUpdateInputWindowsNeeded = false; |
| 5917 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5918 | // Populate the input window list with information about all of the windows that |
| 5919 | // could potentially receive input. |
| 5920 | // As an optimization, we could try to prune the list of windows but this turns |
| 5921 | // out to be difficult because only the native code knows for sure which window |
| 5922 | // currently has touch focus. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5923 | final ArrayList<WindowState> windows = mWindows; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5924 | |
| 5925 | // If there's a drag in flight, provide a pseudowindow to catch drag input |
| 5926 | final boolean inDrag = (mDragState != null); |
| 5927 | if (inDrag) { |
| 5928 | if (DEBUG_DRAG) { |
| 5929 | Log.d(TAG, "Inserting drag window"); |
| 5930 | } |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 5931 | addDragInputWindowLw(mTempInputWindows); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5932 | } |
| 5933 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5934 | final int N = windows.size(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5935 | for (int i = N - 1; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5936 | final WindowState child = windows.get(i); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5937 | if (child.mInputChannel == null || child.mRemoved) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5938 | // Skip this window because it cannot possibly receive input. |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5939 | continue; |
| 5940 | } |
| 5941 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5942 | final int flags = child.mAttrs.flags; |
| 5943 | final int type = child.mAttrs.type; |
| 5944 | |
| 5945 | final boolean hasFocus = (child == mInputFocus); |
| 5946 | final boolean isVisible = child.isVisibleLw(); |
| 5947 | final boolean hasWallpaper = (child == mWallpaperTarget) |
| 5948 | && (type != WindowManager.LayoutParams.TYPE_KEYGUARD); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5949 | |
| 5950 | // If there's a drag in progress and 'child' is a potential drop target, |
| 5951 | // make sure it's been told about the drag |
| 5952 | if (inDrag && isVisible) { |
| 5953 | mDragState.sendDragStartedIfNeededLw(child); |
| 5954 | } |
| 5955 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5956 | // Add a window to our list of input windows. |
| 5957 | final InputWindow inputWindow = mTempInputWindows.add(); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5958 | inputWindow.inputWindowHandle = child.mInputWindowHandle; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5959 | inputWindow.inputChannel = child.mInputChannel; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5960 | inputWindow.name = child.toString(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5961 | inputWindow.layoutParamsFlags = flags; |
| 5962 | inputWindow.layoutParamsType = type; |
| 5963 | inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos(); |
| 5964 | inputWindow.visible = isVisible; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5965 | inputWindow.canReceiveKeys = child.canReceiveKeys(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5966 | inputWindow.hasFocus = hasFocus; |
| 5967 | inputWindow.hasWallpaper = hasWallpaper; |
| 5968 | inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5969 | inputWindow.layer = child.mLayer; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5970 | inputWindow.ownerPid = child.mSession.mPid; |
| 5971 | inputWindow.ownerUid = child.mSession.mUid; |
| 5972 | |
| 5973 | final Rect frame = child.mFrame; |
| 5974 | inputWindow.frameLeft = frame.left; |
| 5975 | inputWindow.frameTop = frame.top; |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5976 | inputWindow.frameRight = frame.right; |
| 5977 | inputWindow.frameBottom = frame.bottom; |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 5978 | |
| 5979 | child.getTouchableRegion(inputWindow.touchableRegion); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5980 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5981 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5982 | // Send windows to native code. |
| 5983 | mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray()); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5984 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5985 | // Clear the list in preparation for the next round. |
| 5986 | // Also avoids keeping InputChannel objects referenced unnecessarily. |
| 5987 | mTempInputWindows.clear(); |
| 5988 | } |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 5989 | |
| 5990 | /* Notifies that the input device configuration has changed. */ |
| 5991 | public void notifyConfigurationChanged() { |
| 5992 | sendNewConfiguration(); |
| 5993 | |
| 5994 | synchronized (mInputDevicesReadyMonitor) { |
| 5995 | if (!mInputDevicesReady) { |
| 5996 | mInputDevicesReady = true; |
| 5997 | mInputDevicesReadyMonitor.notifyAll(); |
| 5998 | } |
| 5999 | } |
| 6000 | } |
| 6001 | |
| 6002 | /* Waits until the built-in input devices have been configured. */ |
| 6003 | public boolean waitForInputDevicesReady(long timeoutMillis) { |
| 6004 | synchronized (mInputDevicesReadyMonitor) { |
| 6005 | if (!mInputDevicesReady) { |
| 6006 | try { |
| 6007 | mInputDevicesReadyMonitor.wait(timeoutMillis); |
| 6008 | } catch (InterruptedException ex) { |
| 6009 | } |
| 6010 | } |
| 6011 | return mInputDevicesReady; |
| 6012 | } |
| 6013 | } |
| 6014 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6015 | /* Notifies that the lid switch changed state. */ |
| 6016 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 6017 | mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen); |
| 6018 | } |
| 6019 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6020 | /* Provides an opportunity for the window manager policy to intercept early key |
| 6021 | * processing as soon as the key has been read from the device. */ |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 6022 | public int interceptKeyBeforeQueueing( |
| 6023 | KeyEvent event, int policyFlags, boolean isScreenOn) { |
| 6024 | return mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6025 | } |
| 6026 | |
| 6027 | /* Provides an opportunity for the window manager policy to process a key before |
| 6028 | * ordinary dispatch. */ |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 6029 | public boolean interceptKeyBeforeDispatching( |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6030 | InputWindowHandle focus, KeyEvent event, int policyFlags) { |
Jeff Brown | 00ae87d | 2011-01-13 19:58:24 -0800 | [diff] [blame] | 6031 | WindowState windowState = focus != null ? (WindowState) focus.windowState : null; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 6032 | return mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6033 | } |
| 6034 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 6035 | /* Provides an opportunity for the window manager policy to process a key that |
| 6036 | * the application did not handle. */ |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 6037 | public KeyEvent dispatchUnhandledKey( |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6038 | InputWindowHandle focus, KeyEvent event, int policyFlags) { |
Jeff Brown | 00ae87d | 2011-01-13 19:58:24 -0800 | [diff] [blame] | 6039 | WindowState windowState = focus != null ? (WindowState) focus.windowState : null; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 6040 | return mPolicy.dispatchUnhandledKey(windowState, event, policyFlags); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 6041 | } |
| 6042 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6043 | /* Called when the current input focus changes. |
| 6044 | * Layer assignment is assumed to be complete by the time this is called. |
| 6045 | */ |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6046 | public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6047 | if (DEBUG_INPUT) { |
| 6048 | Slog.d(TAG, "Input focus has changed to " + newWindow); |
| 6049 | } |
| 6050 | |
| 6051 | if (newWindow != mInputFocus) { |
| 6052 | if (newWindow != null && newWindow.canReceiveKeys()) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6053 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 6054 | // This is to protect against bugs if someone pauses dispatching but |
| 6055 | // forgets to resume. |
| 6056 | newWindow.mToken.paused = false; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6057 | } |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6058 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6059 | mInputFocus = newWindow; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6060 | setUpdateInputWindowsNeededLw(); |
| 6061 | |
| 6062 | if (updateInputWindows) { |
| 6063 | updateInputWindowsLw(); |
| 6064 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6065 | } |
| 6066 | } |
| 6067 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6068 | public void setFocusedAppLw(AppWindowToken newApp) { |
| 6069 | // Focused app has changed. |
| 6070 | if (newApp == null) { |
| 6071 | mInputManager.setFocusedApplication(null); |
| 6072 | } else { |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6073 | mTempInputApplication.inputApplicationHandle = newApp.mInputApplicationHandle; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6074 | mTempInputApplication.name = newApp.toString(); |
| 6075 | mTempInputApplication.dispatchingTimeoutNanos = |
| 6076 | newApp.inputDispatchingTimeoutNanos; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6077 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6078 | mInputManager.setFocusedApplication(mTempInputApplication); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6079 | |
| 6080 | mTempInputApplication.recycle(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6081 | } |
| 6082 | } |
| 6083 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6084 | public void pauseDispatchingLw(WindowToken window) { |
| 6085 | if (! window.paused) { |
| 6086 | if (DEBUG_INPUT) { |
| 6087 | Slog.v(TAG, "Pausing WindowToken " + window); |
| 6088 | } |
| 6089 | |
| 6090 | window.paused = true; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6091 | setUpdateInputWindowsNeededLw(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6092 | updateInputWindowsLw(); |
| 6093 | } |
| 6094 | } |
| 6095 | |
| 6096 | public void resumeDispatchingLw(WindowToken window) { |
| 6097 | if (window.paused) { |
| 6098 | if (DEBUG_INPUT) { |
| 6099 | Slog.v(TAG, "Resuming WindowToken " + window); |
| 6100 | } |
| 6101 | |
| 6102 | window.paused = false; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6103 | setUpdateInputWindowsNeededLw(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6104 | updateInputWindowsLw(); |
| 6105 | } |
| 6106 | } |
| 6107 | |
| 6108 | public void freezeInputDispatchingLw() { |
| 6109 | if (! mInputDispatchFrozen) { |
| 6110 | if (DEBUG_INPUT) { |
| 6111 | Slog.v(TAG, "Freezing input dispatching"); |
| 6112 | } |
| 6113 | |
| 6114 | mInputDispatchFrozen = true; |
| 6115 | updateInputDispatchModeLw(); |
| 6116 | } |
| 6117 | } |
| 6118 | |
| 6119 | public void thawInputDispatchingLw() { |
| 6120 | if (mInputDispatchFrozen) { |
| 6121 | if (DEBUG_INPUT) { |
| 6122 | Slog.v(TAG, "Thawing input dispatching"); |
| 6123 | } |
| 6124 | |
| 6125 | mInputDispatchFrozen = false; |
| 6126 | updateInputDispatchModeLw(); |
| 6127 | } |
| 6128 | } |
| 6129 | |
| 6130 | public void setEventDispatchingLw(boolean enabled) { |
| 6131 | if (mInputDispatchEnabled != enabled) { |
| 6132 | if (DEBUG_INPUT) { |
| 6133 | Slog.v(TAG, "Setting event dispatching to " + enabled); |
| 6134 | } |
| 6135 | |
| 6136 | mInputDispatchEnabled = enabled; |
| 6137 | updateInputDispatchModeLw(); |
| 6138 | } |
| 6139 | } |
| 6140 | |
| 6141 | private void updateInputDispatchModeLw() { |
| 6142 | mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen); |
| 6143 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6144 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6145 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6146 | public void pauseKeyDispatching(IBinder _token) { |
| 6147 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 6148 | "pauseKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6149 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6150 | } |
| 6151 | |
| 6152 | synchronized (mWindowMap) { |
| 6153 | WindowToken token = mTokenMap.get(_token); |
| 6154 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6155 | mInputMonitor.pauseDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6156 | } |
| 6157 | } |
| 6158 | } |
| 6159 | |
| 6160 | public void resumeKeyDispatching(IBinder _token) { |
| 6161 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 6162 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6163 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6164 | } |
| 6165 | |
| 6166 | synchronized (mWindowMap) { |
| 6167 | WindowToken token = mTokenMap.get(_token); |
| 6168 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6169 | mInputMonitor.resumeDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6170 | } |
| 6171 | } |
| 6172 | } |
| 6173 | |
| 6174 | public void setEventDispatching(boolean enabled) { |
| 6175 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 6176 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6177 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6178 | } |
| 6179 | |
| 6180 | synchronized (mWindowMap) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6181 | mInputMonitor.setEventDispatchingLw(enabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6182 | } |
| 6183 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6184 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6185 | /** |
| 6186 | * Injects a keystroke event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6187 | * Even when sync is false, this method may block while waiting for current |
| 6188 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6189 | * |
| 6190 | * @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] | 6191 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 6192 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 6193 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6194 | */ |
| 6195 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 6196 | long downTime = ev.getDownTime(); |
| 6197 | long eventTime = ev.getEventTime(); |
| 6198 | |
| 6199 | int action = ev.getAction(); |
| 6200 | int code = ev.getKeyCode(); |
| 6201 | int repeatCount = ev.getRepeatCount(); |
| 6202 | int metaState = ev.getMetaState(); |
| 6203 | int deviceId = ev.getDeviceId(); |
| 6204 | int scancode = ev.getScanCode(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6205 | int source = ev.getSource(); |
Mike Playle | c6ded10 | 2010-11-29 16:01:03 +0000 | [diff] [blame] | 6206 | int flags = ev.getFlags(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6207 | |
| 6208 | if (source == InputDevice.SOURCE_UNKNOWN) { |
| 6209 | source = InputDevice.SOURCE_KEYBOARD; |
| 6210 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6211 | |
| 6212 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 6213 | if (downTime == 0) downTime = eventTime; |
| 6214 | |
| 6215 | KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, |
Jean-Baptiste Queru | 4a88013 | 2010-12-02 15:16:53 -0800 | [diff] [blame] | 6216 | deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6217 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6218 | final int pid = Binder.getCallingPid(); |
| 6219 | final int uid = Binder.getCallingUid(); |
| 6220 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6221 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6222 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 6223 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 6224 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 6225 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6226 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6227 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6228 | return reportInjectionResult(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6229 | } |
| 6230 | |
| 6231 | /** |
| 6232 | * Inject a pointer (touch) event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6233 | * Even when sync is false, this method may block while waiting for current |
| 6234 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6235 | * |
| 6236 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 6237 | * {@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] | 6238 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 6239 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 6240 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6241 | */ |
| 6242 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6243 | final int pid = Binder.getCallingPid(); |
| 6244 | final int uid = Binder.getCallingUid(); |
| 6245 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6246 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6247 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 6248 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) { |
| 6249 | newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 6250 | } |
| 6251 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6252 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 6253 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 6254 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 6255 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6256 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6257 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6258 | return reportInjectionResult(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6259 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6260 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6261 | /** |
| 6262 | * Inject a trackball (navigation device) event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6263 | * Even when sync is false, this method may block while waiting for current |
| 6264 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6265 | * |
| 6266 | * @param ev A motion event describing the trackball action. (As noted in |
| 6267 | * {@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] | 6268 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 6269 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 6270 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6271 | */ |
| 6272 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6273 | final int pid = Binder.getCallingPid(); |
| 6274 | final int uid = Binder.getCallingUid(); |
| 6275 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6276 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6277 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 6278 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) { |
| 6279 | newEvent.setSource(InputDevice.SOURCE_TRACKBALL); |
| 6280 | } |
| 6281 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6282 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 6283 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 6284 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 6285 | INJECTION_TIMEOUT_MILLIS); |
| 6286 | |
| 6287 | Binder.restoreCallingIdentity(ident); |
| 6288 | return reportInjectionResult(result); |
| 6289 | } |
| 6290 | |
| 6291 | /** |
| 6292 | * Inject an input event into the UI without waiting for dispatch to commence. |
| 6293 | * This variant is useful for fire-and-forget input event injection. It does not |
| 6294 | * block any longer than it takes to enqueue the input event. |
| 6295 | * |
| 6296 | * @param ev An input event. (Be sure to set the input source correctly.) |
| 6297 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6298 | */ |
| 6299 | public boolean injectInputEventNoWait(InputEvent ev) { |
| 6300 | final int pid = Binder.getCallingPid(); |
| 6301 | final int uid = Binder.getCallingUid(); |
| 6302 | final long ident = Binder.clearCallingIdentity(); |
| 6303 | |
| 6304 | final int result = mInputManager.injectInputEvent(ev, pid, uid, |
| 6305 | InputManager.INPUT_EVENT_INJECTION_SYNC_NONE, |
| 6306 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6307 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6308 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6309 | return reportInjectionResult(result); |
| 6310 | } |
| 6311 | |
| 6312 | private boolean reportInjectionResult(int result) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6313 | switch (result) { |
| 6314 | case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED: |
| 6315 | Slog.w(TAG, "Input event injection permission denied."); |
| 6316 | throw new SecurityException( |
| 6317 | "Injecting to another application requires INJECT_EVENTS permission"); |
| 6318 | case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED: |
Christopher Tate | 09e85dc | 2010-08-02 11:54:41 -0700 | [diff] [blame] | 6319 | //Slog.v(TAG, "Input event injection succeeded."); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6320 | return true; |
| 6321 | case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT: |
| 6322 | Slog.w(TAG, "Input event injection timed out."); |
| 6323 | return false; |
| 6324 | case InputManager.INPUT_EVENT_INJECTION_FAILED: |
| 6325 | default: |
| 6326 | Slog.w(TAG, "Input event injection failed."); |
| 6327 | return false; |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6328 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6329 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6330 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6331 | private WindowState getFocusedWindow() { |
| 6332 | synchronized (mWindowMap) { |
| 6333 | return getFocusedWindowLocked(); |
| 6334 | } |
| 6335 | } |
| 6336 | |
| 6337 | private WindowState getFocusedWindowLocked() { |
| 6338 | return mCurrentFocus; |
| 6339 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6340 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6341 | public boolean detectSafeMode() { |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 6342 | if (!mInputMonitor.waitForInputDevicesReady( |
| 6343 | INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) { |
| 6344 | Slog.w(TAG, "Devices still not ready after waiting " |
| 6345 | + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS |
| 6346 | + " milliseconds before attempting to detect safe mode."); |
| 6347 | } |
| 6348 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6349 | mSafeMode = mPolicy.detectSafeMode(); |
| 6350 | return mSafeMode; |
| 6351 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6352 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6353 | public void systemReady() { |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6354 | synchronized(mWindowMap) { |
| 6355 | if (mDisplay != null) { |
| 6356 | throw new IllegalStateException("Display already initialized"); |
| 6357 | } |
| 6358 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 6359 | mDisplay = wm.getDefaultDisplay(); |
| 6360 | mInitialDisplayWidth = mDisplay.getWidth(); |
| 6361 | mInitialDisplayHeight = mDisplay.getHeight(); |
Dianne Hackborn | 4c7cc34 | 2010-12-16 16:37:39 -0800 | [diff] [blame] | 6362 | mInputManager.setDisplaySize(0, Display.unmapDisplaySize(mInitialDisplayWidth), |
| 6363 | Display.unmapDisplaySize(mInitialDisplayHeight)); |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6364 | } |
| 6365 | |
| 6366 | try { |
| 6367 | mActivityManager.updateConfiguration(null); |
| 6368 | } catch (RemoteException e) { |
| 6369 | } |
Dianne Hackborn | 154db5f | 2010-07-29 19:15:19 -0700 | [diff] [blame] | 6370 | |
| 6371 | mPolicy.systemReady(); |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6372 | } |
| 6373 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6374 | // ------------------------------------------------------------- |
| 6375 | // Client Session State |
| 6376 | // ------------------------------------------------------------- |
| 6377 | |
| 6378 | private final class Session extends IWindowSession.Stub |
| 6379 | implements IBinder.DeathRecipient { |
| 6380 | final IInputMethodClient mClient; |
| 6381 | final IInputContext mInputContext; |
| 6382 | final int mUid; |
| 6383 | final int mPid; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6384 | final String mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6385 | SurfaceSession mSurfaceSession; |
| 6386 | int mNumWindow = 0; |
| 6387 | boolean mClientDead = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6388 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6389 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 6390 | mClient = client; |
| 6391 | mInputContext = inputContext; |
| 6392 | mUid = Binder.getCallingUid(); |
| 6393 | mPid = Binder.getCallingPid(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6394 | StringBuilder sb = new StringBuilder(); |
| 6395 | sb.append("Session{"); |
| 6396 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 6397 | sb.append(" uid "); |
| 6398 | sb.append(mUid); |
| 6399 | sb.append("}"); |
| 6400 | mStringName = sb.toString(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6401 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6402 | synchronized (mWindowMap) { |
| 6403 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 6404 | IBinder b = ServiceManager.getService( |
| 6405 | Context.INPUT_METHOD_SERVICE); |
| 6406 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 6407 | } |
| 6408 | } |
| 6409 | long ident = Binder.clearCallingIdentity(); |
| 6410 | try { |
| 6411 | // Note: it is safe to call in to the input method manager |
| 6412 | // here because we are not holding our lock. |
| 6413 | if (mInputMethodManager != null) { |
| 6414 | mInputMethodManager.addClient(client, inputContext, |
| 6415 | mUid, mPid); |
| 6416 | } else { |
| 6417 | client.setUsingInputMethod(false); |
| 6418 | } |
| 6419 | client.asBinder().linkToDeath(this, 0); |
| 6420 | } catch (RemoteException e) { |
| 6421 | // The caller has died, so we can just forget about this. |
| 6422 | try { |
| 6423 | if (mInputMethodManager != null) { |
| 6424 | mInputMethodManager.removeClient(client); |
| 6425 | } |
| 6426 | } catch (RemoteException ee) { |
| 6427 | } |
| 6428 | } finally { |
| 6429 | Binder.restoreCallingIdentity(ident); |
| 6430 | } |
| 6431 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6432 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6433 | @Override |
| 6434 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 6435 | throws RemoteException { |
| 6436 | try { |
| 6437 | return super.onTransact(code, data, reply, flags); |
| 6438 | } catch (RuntimeException e) { |
| 6439 | // Log all 'real' exceptions thrown to the caller |
| 6440 | if (!(e instanceof SecurityException)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6441 | Slog.e(TAG, "Window Session Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6442 | } |
| 6443 | throw e; |
| 6444 | } |
| 6445 | } |
| 6446 | |
| 6447 | public void binderDied() { |
| 6448 | // Note: it is safe to call in to the input method manager |
| 6449 | // here because we are not holding our lock. |
| 6450 | try { |
| 6451 | if (mInputMethodManager != null) { |
| 6452 | mInputMethodManager.removeClient(mClient); |
| 6453 | } |
| 6454 | } catch (RemoteException e) { |
| 6455 | } |
| 6456 | synchronized(mWindowMap) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 6457 | mClient.asBinder().unlinkToDeath(this, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6458 | mClientDead = true; |
| 6459 | killSessionLocked(); |
| 6460 | } |
| 6461 | } |
| 6462 | |
| 6463 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6464 | int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) { |
| 6465 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, |
| 6466 | outInputChannel); |
| 6467 | } |
| 6468 | |
| 6469 | public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6470 | int viewVisibility, Rect outContentInsets) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6471 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6472 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6473 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6474 | public void remove(IWindow window) { |
| 6475 | removeWindow(this, window); |
| 6476 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6477 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6478 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 6479 | int requestedWidth, int requestedHeight, int viewFlags, |
| 6480 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6481 | Rect outVisibleInsets, Configuration outConfig, Surface outSurface) { |
Dianne Hackborn | f123e49 | 2010-09-24 11:16:23 -0700 | [diff] [blame] | 6482 | //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid()); |
| 6483 | int res = relayoutWindow(this, window, attrs, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6484 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6485 | outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface); |
Dianne Hackborn | f123e49 | 2010-09-24 11:16:23 -0700 | [diff] [blame] | 6486 | //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid()); |
| 6487 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6488 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6489 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6490 | public void setTransparentRegion(IWindow window, Region region) { |
| 6491 | setTransparentRegionWindow(this, window, region); |
| 6492 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6493 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6494 | public void setInsets(IWindow window, int touchableInsets, |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 6495 | Rect contentInsets, Rect visibleInsets, Region touchableArea) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6496 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 6497 | visibleInsets, touchableArea); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6498 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6499 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6500 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 6501 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 6502 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6503 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6504 | public void finishDrawing(IWindow window) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6505 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6506 | TAG, "IWindow finishDrawing called for " + window); |
| 6507 | finishDrawingWindow(this, window); |
| 6508 | } |
| 6509 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6510 | public void setInTouchMode(boolean mode) { |
| 6511 | synchronized(mWindowMap) { |
| 6512 | mInTouchMode = mode; |
| 6513 | } |
| 6514 | } |
| 6515 | |
| 6516 | public boolean getInTouchMode() { |
| 6517 | synchronized(mWindowMap) { |
| 6518 | return mInTouchMode; |
| 6519 | } |
| 6520 | } |
| 6521 | |
| 6522 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 6523 | boolean always) { |
| 6524 | synchronized(mWindowMap) { |
| 6525 | long ident = Binder.clearCallingIdentity(); |
| 6526 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6527 | return mPolicy.performHapticFeedbackLw( |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6528 | windowForClientLocked(this, window, true), |
| 6529 | effectId, always); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6530 | } finally { |
| 6531 | Binder.restoreCallingIdentity(ident); |
| 6532 | } |
| 6533 | } |
| 6534 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6535 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6536 | /* Drag/drop */ |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 6537 | public IBinder prepareDrag(IWindow window, int flags, |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6538 | int width, int height, Surface outSurface) { |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 6539 | return prepareDragSurface(window, mSurfaceSession, flags, |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6540 | width, height, outSurface); |
| 6541 | } |
| 6542 | |
| 6543 | public boolean performDrag(IWindow window, IBinder dragToken, |
| 6544 | float touchX, float touchY, float thumbCenterX, float thumbCenterY, |
| 6545 | ClipData data) { |
| 6546 | if (DEBUG_DRAG) { |
| 6547 | Slog.d(TAG, "perform drag: win=" + window + " data=" + data); |
| 6548 | } |
| 6549 | |
| 6550 | synchronized (mWindowMap) { |
| 6551 | if (mDragState == null) { |
| 6552 | Slog.w(TAG, "No drag prepared"); |
| 6553 | throw new IllegalStateException("performDrag() without prepareDrag()"); |
| 6554 | } |
| 6555 | |
| 6556 | if (dragToken != mDragState.mToken) { |
| 6557 | Slog.w(TAG, "Performing mismatched drag"); |
| 6558 | throw new IllegalStateException("performDrag() does not match prepareDrag()"); |
| 6559 | } |
| 6560 | |
| 6561 | WindowState callingWin = windowForClientLocked(null, window, false); |
| 6562 | if (callingWin == null) { |
| 6563 | Slog.w(TAG, "Bad requesting window " + window); |
| 6564 | return false; // !!! TODO: throw here? |
| 6565 | } |
| 6566 | |
| 6567 | // !!! TODO: if input is not still focused on the initiating window, fail |
| 6568 | // the drag initiation (e.g. an alarm window popped up just as the application |
| 6569 | // called performDrag() |
| 6570 | |
| 6571 | mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder()); |
| 6572 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 6573 | // !!! TODO: extract the current touch (x, y) in screen coordinates. That |
| 6574 | // will let us eliminate the (touchX,touchY) parameters from the API. |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6575 | |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6576 | // !!! FIXME: put all this heavy stuff onto the mH looper, as well as |
| 6577 | // the actual drag event dispatch stuff in the dragstate |
| 6578 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6579 | mDragState.register(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6580 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6581 | mInputMonitor.updateInputWindowsLw(); |
Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 6582 | if (!mInputManager.transferTouchFocus(callingWin.mInputChannel, |
| 6583 | mDragState.mServerChannel)) { |
| 6584 | Slog.e(TAG, "Unable to transfer touch focus"); |
| 6585 | mDragState.unregister(); |
| 6586 | mDragState = null; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6587 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 6588 | mInputMonitor.updateInputWindowsLw(); |
| 6589 | return false; |
| 6590 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6591 | |
| 6592 | mDragState.mData = data; |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6593 | mDragState.mCurrentX = touchX; |
| 6594 | mDragState.mCurrentY = touchY; |
Chris Tate | b8203e9 | 2010-10-12 14:23:21 -0700 | [diff] [blame] | 6595 | mDragState.broadcastDragStartedLw(touchX, touchY); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6596 | |
| 6597 | // remember the thumb offsets for later |
| 6598 | mDragState.mThumbOffsetX = thumbCenterX; |
| 6599 | mDragState.mThumbOffsetY = thumbCenterY; |
| 6600 | |
| 6601 | // Make the surface visible at the proper location |
| 6602 | final Surface surface = mDragState.mSurface; |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 6603 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performDrag"); |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6604 | Surface.openTransaction(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6605 | try { |
| 6606 | surface.setPosition((int)(touchX - thumbCenterX), |
| 6607 | (int)(touchY - thumbCenterY)); |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6608 | surface.setAlpha(.7071f); |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 6609 | surface.setLayer(mDragState.getDragLayerLw()); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6610 | surface.show(); |
| 6611 | } finally { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6612 | Surface.closeTransaction(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 6613 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performDrag"); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6614 | } |
| 6615 | } |
| 6616 | |
| 6617 | return true; // success! |
| 6618 | } |
| 6619 | |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6620 | public void reportDropResult(IWindow window, boolean consumed) { |
| 6621 | IBinder token = window.asBinder(); |
| 6622 | if (DEBUG_DRAG) { |
| 6623 | Slog.d(TAG, "Drop result=" + consumed + " reported by " + token); |
| 6624 | } |
| 6625 | |
| 6626 | synchronized (mWindowMap) { |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 6627 | long ident = Binder.clearCallingIdentity(); |
| 6628 | try { |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 6629 | if (mDragState == null || mDragState.mToken != token) { |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 6630 | Slog.w(TAG, "Invalid drop-result claim by " + window); |
| 6631 | throw new IllegalStateException("reportDropResult() by non-recipient"); |
| 6632 | } |
| 6633 | |
| 6634 | // The right window has responded, even if it's no longer around, |
| 6635 | // so be sure to halt the timeout even if the later WindowState |
| 6636 | // lookup fails. |
| 6637 | mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder()); |
| 6638 | WindowState callingWin = windowForClientLocked(null, window, false); |
| 6639 | if (callingWin == null) { |
| 6640 | Slog.w(TAG, "Bad result-reporting window " + window); |
| 6641 | return; // !!! TODO: throw here? |
| 6642 | } |
| 6643 | |
| 6644 | mDragState.mDragResult = consumed; |
| 6645 | mDragState.endDragLw(); |
| 6646 | } finally { |
| 6647 | Binder.restoreCallingIdentity(ident); |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6648 | } |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6649 | } |
| 6650 | } |
| 6651 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6652 | public void dragRecipientEntered(IWindow window) { |
| 6653 | if (DEBUG_DRAG) { |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6654 | Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder()); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6655 | } |
| 6656 | } |
| 6657 | |
| 6658 | public void dragRecipientExited(IWindow window) { |
| 6659 | if (DEBUG_DRAG) { |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6660 | Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder()); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6661 | } |
| 6662 | } |
| 6663 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6664 | public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6665 | synchronized(mWindowMap) { |
| 6666 | long ident = Binder.clearCallingIdentity(); |
| 6667 | try { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6668 | setWindowWallpaperPositionLocked( |
| 6669 | windowForClientLocked(this, window, true), |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6670 | x, y, xStep, yStep); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6671 | } finally { |
| 6672 | Binder.restoreCallingIdentity(ident); |
| 6673 | } |
| 6674 | } |
| 6675 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6676 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6677 | public void wallpaperOffsetsComplete(IBinder window) { |
| 6678 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 6679 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6680 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6681 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 6682 | int z, Bundle extras, boolean sync) { |
| 6683 | synchronized(mWindowMap) { |
| 6684 | long ident = Binder.clearCallingIdentity(); |
| 6685 | try { |
| 6686 | return sendWindowWallpaperCommandLocked( |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6687 | windowForClientLocked(this, window, true), |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6688 | action, x, y, z, extras, sync); |
| 6689 | } finally { |
| 6690 | Binder.restoreCallingIdentity(ident); |
| 6691 | } |
| 6692 | } |
| 6693 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6694 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6695 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 6696 | WindowManagerService.this.wallpaperCommandComplete(window, result); |
| 6697 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6698 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6699 | void windowAddedLocked() { |
| 6700 | if (mSurfaceSession == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6701 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6702 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 6703 | mSurfaceSession = new SurfaceSession(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6704 | if (SHOW_TRANSACTIONS) Slog.i( |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6705 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6706 | mSessions.add(this); |
| 6707 | } |
| 6708 | mNumWindow++; |
| 6709 | } |
| 6710 | |
| 6711 | void windowRemovedLocked() { |
| 6712 | mNumWindow--; |
| 6713 | killSessionLocked(); |
| 6714 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6715 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6716 | void killSessionLocked() { |
| 6717 | if (mNumWindow <= 0 && mClientDead) { |
| 6718 | mSessions.remove(this); |
| 6719 | if (mSurfaceSession != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6720 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6721 | TAG, "Last window removed from " + this |
| 6722 | + ", destroying " + mSurfaceSession); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6723 | if (SHOW_TRANSACTIONS) Slog.i( |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6724 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6725 | try { |
| 6726 | mSurfaceSession.kill(); |
| 6727 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6728 | Slog.w(TAG, "Exception thrown when killing surface session " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6729 | + mSurfaceSession + " in session " + this |
| 6730 | + ": " + e.toString()); |
| 6731 | } |
| 6732 | mSurfaceSession = null; |
| 6733 | } |
| 6734 | } |
| 6735 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6736 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6737 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6738 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 6739 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 6740 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6741 | } |
| 6742 | |
| 6743 | @Override |
| 6744 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6745 | return mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6746 | } |
| 6747 | } |
| 6748 | |
| 6749 | // ------------------------------------------------------------- |
| 6750 | // Client Window State |
| 6751 | // ------------------------------------------------------------- |
| 6752 | |
| 6753 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 6754 | final Session mSession; |
| 6755 | final IWindow mClient; |
| 6756 | WindowToken mToken; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6757 | WindowToken mRootToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6758 | AppWindowToken mAppToken; |
| 6759 | AppWindowToken mTargetAppToken; |
| 6760 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 6761 | final DeathRecipient mDeathRecipient; |
| 6762 | final WindowState mAttachedWindow; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6763 | final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6764 | final int mBaseLayer; |
| 6765 | final int mSubLayer; |
| 6766 | final boolean mLayoutAttached; |
| 6767 | final boolean mIsImWindow; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6768 | final boolean mIsWallpaper; |
| 6769 | final boolean mIsFloatingLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6770 | int mViewVisibility; |
| 6771 | boolean mPolicyVisibility = true; |
| 6772 | boolean mPolicyVisibilityAfterAnim = true; |
| 6773 | boolean mAppFreezing; |
| 6774 | Surface mSurface; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6775 | boolean mReportDestroySurface; |
| 6776 | boolean mSurfacePendingDestroy; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6777 | boolean mAttachedHidden; // is our parent window hidden? |
| 6778 | boolean mLastHidden; // was this window last hidden? |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6779 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6780 | int mRequestedWidth; |
| 6781 | int mRequestedHeight; |
| 6782 | int mLastRequestedWidth; |
| 6783 | int mLastRequestedHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6784 | int mLayer; |
| 6785 | int mAnimLayer; |
| 6786 | int mLastLayer; |
| 6787 | boolean mHaveFrame; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6788 | boolean mObscured; |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 6789 | boolean mTurnOnScreen; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6790 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6791 | int mLayoutSeq = -1; |
| 6792 | |
| 6793 | Configuration mConfiguration = null; |
| 6794 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6795 | // Actual frame shown on-screen (may be modified by animation) |
| 6796 | final Rect mShownFrame = new Rect(); |
| 6797 | final Rect mLastShownFrame = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6798 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6799 | /** |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 6800 | * Set when we have changed the size of the surface, to know that |
| 6801 | * we must tell them application to resize (and thus redraw itself). |
| 6802 | */ |
| 6803 | boolean mSurfaceResized; |
| 6804 | |
| 6805 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6806 | * Insets that determine the actually visible area |
| 6807 | */ |
| 6808 | final Rect mVisibleInsets = new Rect(); |
| 6809 | final Rect mLastVisibleInsets = new Rect(); |
| 6810 | boolean mVisibleInsetsChanged; |
| 6811 | |
| 6812 | /** |
| 6813 | * Insets that are covered by system windows |
| 6814 | */ |
| 6815 | final Rect mContentInsets = new Rect(); |
| 6816 | final Rect mLastContentInsets = new Rect(); |
| 6817 | boolean mContentInsetsChanged; |
| 6818 | |
| 6819 | /** |
| 6820 | * Set to true if we are waiting for this window to receive its |
| 6821 | * given internal insets before laying out other windows based on it. |
| 6822 | */ |
| 6823 | boolean mGivenInsetsPending; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6824 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6825 | /** |
| 6826 | * These are the content insets that were given during layout for |
| 6827 | * this window, to be applied to windows behind it. |
| 6828 | */ |
| 6829 | final Rect mGivenContentInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6830 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6831 | /** |
| 6832 | * These are the visible insets that were given during layout for |
| 6833 | * this window, to be applied to windows behind it. |
| 6834 | */ |
| 6835 | final Rect mGivenVisibleInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6836 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6837 | /** |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 6838 | * This is the given touchable area relative to the window frame, or null if none. |
| 6839 | */ |
| 6840 | final Region mGivenTouchableRegion = new Region(); |
| 6841 | |
| 6842 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6843 | * Flag indicating whether the touchable region should be adjusted by |
| 6844 | * the visible insets; if false the area outside the visible insets is |
| 6845 | * NOT touchable, so we must use those to adjust the frame during hit |
| 6846 | * tests. |
| 6847 | */ |
| 6848 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6849 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6850 | // Current transformation being applied. |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 6851 | boolean mHaveMatrix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6852 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 6853 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 6854 | float mHScale=1, mVScale=1; |
| 6855 | float mLastHScale=1, mLastVScale=1; |
| 6856 | final Matrix mTmpMatrix = new Matrix(); |
| 6857 | |
| 6858 | // "Real" frame that the application sees. |
| 6859 | final Rect mFrame = new Rect(); |
| 6860 | final Rect mLastFrame = new Rect(); |
| 6861 | |
| 6862 | final Rect mContainingFrame = new Rect(); |
| 6863 | final Rect mDisplayFrame = new Rect(); |
| 6864 | final Rect mContentFrame = new Rect(); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 6865 | final Rect mParentFrame = new Rect(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6866 | final Rect mVisibleFrame = new Rect(); |
| 6867 | |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6868 | boolean mContentChanged; |
| 6869 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6870 | float mShownAlpha = 1; |
| 6871 | float mAlpha = 1; |
| 6872 | float mLastAlpha = 1; |
| 6873 | |
| 6874 | // Set to true if, when the window gets displayed, it should perform |
| 6875 | // an enter animation. |
| 6876 | boolean mEnterAnimationPending; |
| 6877 | |
| 6878 | // Currently running animation. |
| 6879 | boolean mAnimating; |
| 6880 | boolean mLocalAnimating; |
| 6881 | Animation mAnimation; |
| 6882 | boolean mAnimationIsEntrance; |
| 6883 | boolean mHasTransformation; |
| 6884 | boolean mHasLocalTransformation; |
| 6885 | final Transformation mTransformation = new Transformation(); |
| 6886 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6887 | // If a window showing a wallpaper: the requested offset for the |
| 6888 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 6889 | float mWallpaperX = -1; |
| 6890 | float mWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6891 | |
| 6892 | // If a window showing a wallpaper: what fraction of the offset |
| 6893 | // range corresponds to a full virtual screen. |
| 6894 | float mWallpaperXStep = -1; |
| 6895 | float mWallpaperYStep = -1; |
| 6896 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6897 | // Wallpaper windows: pixels offset based on above variables. |
| 6898 | int mXOffset; |
| 6899 | int mYOffset; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6900 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6901 | // This is set after IWindowSession.relayout() has been called at |
| 6902 | // least once for the window. It allows us to detect the situation |
| 6903 | // where we don't yet have a surface, but should have one soon, so |
| 6904 | // we can give the window focus before waiting for the relayout. |
| 6905 | boolean mRelayoutCalled; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6906 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6907 | // This is set after the Surface has been created but before the |
| 6908 | // window has been drawn. During this time the surface is hidden. |
| 6909 | boolean mDrawPending; |
| 6910 | |
| 6911 | // This is set after the window has finished drawing for the first |
| 6912 | // time but before its surface is shown. The surface will be |
| 6913 | // displayed when the next layout is run. |
| 6914 | boolean mCommitDrawPending; |
| 6915 | |
| 6916 | // This is set during the time after the window's drawing has been |
| 6917 | // committed, and before its surface is actually shown. It is used |
| 6918 | // to delay showing the surface until all windows in a token are ready |
| 6919 | // to be shown. |
| 6920 | boolean mReadyToShow; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6921 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6922 | // Set when the window has been shown in the screen the first time. |
| 6923 | boolean mHasDrawn; |
| 6924 | |
| 6925 | // Currently running an exit animation? |
| 6926 | boolean mExiting; |
| 6927 | |
| 6928 | // Currently on the mDestroySurface list? |
| 6929 | boolean mDestroying; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6930 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6931 | // Completely remove from window manager after exit animation? |
| 6932 | boolean mRemoveOnExit; |
| 6933 | |
| 6934 | // Set when the orientation is changing and this window has not yet |
| 6935 | // been updated for the new orientation. |
| 6936 | boolean mOrientationChanging; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6937 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6938 | // Is this window now (or just being) removed? |
| 6939 | boolean mRemoved; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6940 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6941 | // Temp for keeping track of windows that have been removed when |
| 6942 | // rebuilding window list. |
| 6943 | boolean mRebuilding; |
| 6944 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6945 | // For debugging, this is the last information given to the surface flinger. |
| 6946 | boolean mSurfaceShown; |
| 6947 | int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH; |
| 6948 | int mSurfaceLayer; |
| 6949 | float mSurfaceAlpha; |
| 6950 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6951 | // Input channel and input window handle used by the input dispatcher. |
| 6952 | InputWindowHandle mInputWindowHandle; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6953 | InputChannel mInputChannel; |
| 6954 | |
Mattias Petersson | 1622eee | 2010-12-21 10:15:11 +0100 | [diff] [blame] | 6955 | // Used to improve performance of toString() |
| 6956 | String mStringNameCache; |
| 6957 | CharSequence mLastTitle; |
| 6958 | boolean mWasPaused; |
| 6959 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6960 | WindowState(Session s, IWindow c, WindowToken token, |
| 6961 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 6962 | int viewVisibility) { |
| 6963 | mSession = s; |
| 6964 | mClient = c; |
| 6965 | mToken = token; |
| 6966 | mAttrs.copyFrom(a); |
| 6967 | mViewVisibility = viewVisibility; |
| 6968 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 6969 | mAlpha = a.alpha; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6970 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6971 | TAG, "Window " + this + " client=" + c.asBinder() |
| 6972 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 6973 | try { |
| 6974 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 6975 | } catch (RemoteException e) { |
| 6976 | mDeathRecipient = null; |
| 6977 | mAttachedWindow = null; |
| 6978 | mLayoutAttached = false; |
| 6979 | mIsImWindow = false; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6980 | mIsWallpaper = false; |
| 6981 | mIsFloatingLayer = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6982 | mBaseLayer = 0; |
| 6983 | mSubLayer = 0; |
| 6984 | return; |
| 6985 | } |
| 6986 | mDeathRecipient = deathRecipient; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6987 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6988 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 6989 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 6990 | // The multiplier here is to reserve space for multiple |
| 6991 | // windows in the same type layer. |
| 6992 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 6993 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 6994 | + TYPE_LAYER_OFFSET; |
| 6995 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 6996 | mAttachedWindow = attachedWindow; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6997 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6998 | mAttachedWindow.mChildWindows.add(this); |
| 6999 | mLayoutAttached = mAttrs.type != |
| 7000 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 7001 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 7002 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7003 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 7004 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7005 | } else { |
| 7006 | // The multiplier here is to reserve space for multiple |
| 7007 | // windows in the same type layer. |
| 7008 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 7009 | * TYPE_LAYER_MULTIPLIER |
| 7010 | + TYPE_LAYER_OFFSET; |
| 7011 | mSubLayer = 0; |
| 7012 | mAttachedWindow = null; |
| 7013 | mLayoutAttached = false; |
| 7014 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 7015 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7016 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 7017 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7018 | } |
| 7019 | |
| 7020 | WindowState appWin = this; |
| 7021 | while (appWin.mAttachedWindow != null) { |
| 7022 | appWin = mAttachedWindow; |
| 7023 | } |
| 7024 | WindowToken appToken = appWin.mToken; |
| 7025 | while (appToken.appWindowToken == null) { |
| 7026 | WindowToken parent = mTokenMap.get(appToken.token); |
| 7027 | if (parent == null || appToken == parent) { |
| 7028 | break; |
| 7029 | } |
| 7030 | appToken = parent; |
| 7031 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7032 | mRootToken = appToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7033 | mAppToken = appToken.appWindowToken; |
| 7034 | |
| 7035 | mSurface = null; |
| 7036 | mRequestedWidth = 0; |
| 7037 | mRequestedHeight = 0; |
| 7038 | mLastRequestedWidth = 0; |
| 7039 | mLastRequestedHeight = 0; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7040 | mXOffset = 0; |
| 7041 | mYOffset = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7042 | mLayer = 0; |
| 7043 | mAnimLayer = 0; |
| 7044 | mLastLayer = 0; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 7045 | mInputWindowHandle = new InputWindowHandle( |
| 7046 | mAppToken != null ? mAppToken.mInputApplicationHandle : null, this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7047 | } |
| 7048 | |
| 7049 | void attach() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7050 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7051 | TAG, "Attaching " + this + " token=" + mToken |
| 7052 | + ", list=" + mToken.windows); |
| 7053 | mSession.windowAddedLocked(); |
| 7054 | } |
| 7055 | |
| 7056 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 7057 | mHaveFrame = true; |
| 7058 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7059 | final Rect container = mContainingFrame; |
| 7060 | container.set(pf); |
| 7061 | |
| 7062 | final Rect display = mDisplayFrame; |
| 7063 | display.set(df); |
| 7064 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7065 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7066 | container.intersect(mCompatibleScreenFrame); |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7067 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 7068 | display.intersect(mCompatibleScreenFrame); |
| 7069 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7070 | } |
| 7071 | |
| 7072 | final int pw = container.right - container.left; |
| 7073 | final int ph = container.bottom - container.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7074 | |
| 7075 | int w,h; |
| 7076 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 7077 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 7078 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 7079 | } else { |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 7080 | w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth; |
| 7081 | h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7082 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7083 | |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 7084 | if (!mParentFrame.equals(pf)) { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 7085 | //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame |
| 7086 | // + " to " + pf); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 7087 | mParentFrame.set(pf); |
| 7088 | mContentChanged = true; |
| 7089 | } |
| 7090 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7091 | final Rect content = mContentFrame; |
| 7092 | content.set(cf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7093 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7094 | final Rect visible = mVisibleFrame; |
| 7095 | visible.set(vf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7096 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7097 | final Rect frame = mFrame; |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7098 | final int fw = frame.width(); |
| 7099 | final int fh = frame.height(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7100 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7101 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 7102 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 7103 | |
| 7104 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 7105 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 7106 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 7107 | |
| 7108 | //System.out.println("Out: " + mFrame); |
| 7109 | |
| 7110 | // Now make sure the window fits in the overall display. |
| 7111 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7112 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7113 | // Make sure the content and visible frames are inside of the |
| 7114 | // final window frame. |
| 7115 | if (content.left < frame.left) content.left = frame.left; |
| 7116 | if (content.top < frame.top) content.top = frame.top; |
| 7117 | if (content.right > frame.right) content.right = frame.right; |
| 7118 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 7119 | if (visible.left < frame.left) visible.left = frame.left; |
| 7120 | if (visible.top < frame.top) visible.top = frame.top; |
| 7121 | if (visible.right > frame.right) visible.right = frame.right; |
| 7122 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7123 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7124 | final Rect contentInsets = mContentInsets; |
| 7125 | contentInsets.left = content.left-frame.left; |
| 7126 | contentInsets.top = content.top-frame.top; |
| 7127 | contentInsets.right = frame.right-content.right; |
| 7128 | contentInsets.bottom = frame.bottom-content.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7129 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7130 | final Rect visibleInsets = mVisibleInsets; |
| 7131 | visibleInsets.left = visible.left-frame.left; |
| 7132 | visibleInsets.top = visible.top-frame.top; |
| 7133 | visibleInsets.right = frame.right-visible.right; |
| 7134 | visibleInsets.bottom = frame.bottom-visible.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7135 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 7136 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 7137 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 7138 | mDisplay.getHeight(), false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7139 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7141 | if (localLOGV) { |
| 7142 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 7143 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7144 | Slog.v(TAG, "Resolving (mRequestedWidth=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7145 | + mRequestedWidth + ", mRequestedheight=" |
| 7146 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 7147 | + "): frame=" + mFrame.toShortString() |
| 7148 | + " ci=" + contentInsets.toShortString() |
| 7149 | + " vi=" + visibleInsets.toShortString()); |
| 7150 | //} |
| 7151 | } |
| 7152 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7153 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7154 | public Rect getFrameLw() { |
| 7155 | return mFrame; |
| 7156 | } |
| 7157 | |
| 7158 | public Rect getShownFrameLw() { |
| 7159 | return mShownFrame; |
| 7160 | } |
| 7161 | |
| 7162 | public Rect getDisplayFrameLw() { |
| 7163 | return mDisplayFrame; |
| 7164 | } |
| 7165 | |
| 7166 | public Rect getContentFrameLw() { |
| 7167 | return mContentFrame; |
| 7168 | } |
| 7169 | |
| 7170 | public Rect getVisibleFrameLw() { |
| 7171 | return mVisibleFrame; |
| 7172 | } |
| 7173 | |
| 7174 | public boolean getGivenInsetsPendingLw() { |
| 7175 | return mGivenInsetsPending; |
| 7176 | } |
| 7177 | |
| 7178 | public Rect getGivenContentInsetsLw() { |
| 7179 | return mGivenContentInsets; |
| 7180 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7181 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7182 | public Rect getGivenVisibleInsetsLw() { |
| 7183 | return mGivenVisibleInsets; |
| 7184 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7185 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7186 | public WindowManager.LayoutParams getAttrs() { |
| 7187 | return mAttrs; |
| 7188 | } |
| 7189 | |
| 7190 | public int getSurfaceLayer() { |
| 7191 | return mLayer; |
| 7192 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7193 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7194 | public IApplicationToken getAppToken() { |
| 7195 | return mAppToken != null ? mAppToken.appToken : null; |
| 7196 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 7197 | |
| 7198 | public long getInputDispatchingTimeoutNanos() { |
| 7199 | return mAppToken != null |
| 7200 | ? mAppToken.inputDispatchingTimeoutNanos |
| 7201 | : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 7202 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7203 | |
| 7204 | public boolean hasAppShownWindows() { |
| 7205 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 7206 | } |
| 7207 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7208 | public void setAnimation(Animation anim) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7209 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7210 | TAG, "Setting animation in " + this + ": " + anim); |
| 7211 | mAnimating = false; |
| 7212 | mLocalAnimating = false; |
| 7213 | mAnimation = anim; |
| 7214 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 7215 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 7216 | } |
| 7217 | |
| 7218 | public void clearAnimation() { |
| 7219 | if (mAnimation != null) { |
| 7220 | mAnimating = true; |
| 7221 | mLocalAnimating = false; |
Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7222 | mAnimation.cancel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7223 | mAnimation = null; |
| 7224 | } |
| 7225 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7226 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7227 | Surface createSurfaceLocked() { |
| 7228 | if (mSurface == null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7229 | mReportDestroySurface = false; |
| 7230 | mSurfacePendingDestroy = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7231 | mDrawPending = true; |
| 7232 | mCommitDrawPending = false; |
| 7233 | mReadyToShow = false; |
| 7234 | if (mAppToken != null) { |
| 7235 | mAppToken.allDrawn = false; |
| 7236 | } |
| 7237 | |
| 7238 | int flags = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7239 | |
| 7240 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 7241 | flags |= Surface.SECURE; |
| 7242 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7243 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7244 | TAG, "Creating surface in session " |
| 7245 | + mSession.mSurfaceSession + " window " + this |
| 7246 | + " w=" + mFrame.width() |
| 7247 | + " h=" + mFrame.height() + " format=" |
| 7248 | + mAttrs.format + " flags=" + flags); |
| 7249 | |
| 7250 | int w = mFrame.width(); |
| 7251 | int h = mFrame.height(); |
| 7252 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 7253 | // for a scaled surface, we always want the requested |
| 7254 | // size. |
| 7255 | w = mRequestedWidth; |
| 7256 | h = mRequestedHeight; |
| 7257 | } |
| 7258 | |
Romain Guy | 9825ec6 | 2009-10-01 00:58:09 -0700 | [diff] [blame] | 7259 | // Something is wrong and SurfaceFlinger will not like this, |
| 7260 | // try to revert to sane values |
| 7261 | if (w <= 0) w = 1; |
| 7262 | if (h <= 0) h = 1; |
| 7263 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7264 | mSurfaceShown = false; |
| 7265 | mSurfaceLayer = 0; |
| 7266 | mSurfaceAlpha = 1; |
| 7267 | mSurfaceX = 0; |
| 7268 | mSurfaceY = 0; |
| 7269 | mSurfaceW = w; |
| 7270 | mSurfaceH = h; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7271 | try { |
Romain Guy | d10cd57 | 2010-10-10 13:33:22 -0700 | [diff] [blame] | 7272 | final boolean isHwAccelerated = (mAttrs.flags & |
| 7273 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0; |
| 7274 | final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format; |
| 7275 | if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) { |
| 7276 | flags |= Surface.OPAQUE; |
| 7277 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7278 | mSurface = new Surface( |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7279 | mSession.mSurfaceSession, mSession.mPid, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 7280 | mAttrs.getTitle().toString(), |
Romain Guy | d10cd57 | 2010-10-10 13:33:22 -0700 | [diff] [blame] | 7281 | 0, w, h, format, flags); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7282 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7283 | + mSurface + " IN SESSION " |
| 7284 | + mSession.mSurfaceSession |
| 7285 | + ": pid=" + mSession.mPid + " format=" |
| 7286 | + mAttrs.format + " flags=0x" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7287 | + Integer.toHexString(flags) |
| 7288 | + " / " + this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7289 | } catch (Surface.OutOfResourcesException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7290 | Slog.w(TAG, "OutOfResourcesException creating surface"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7291 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 7292 | return null; |
| 7293 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7294 | Slog.e(TAG, "Exception creating surface", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7295 | return null; |
| 7296 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7297 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7298 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7299 | TAG, "Got surface: " + mSurface |
| 7300 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 7301 | + ", animLayer=" + mAnimLayer); |
| 7302 | if (SHOW_TRANSACTIONS) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 7303 | Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked"); |
| 7304 | logSurface(this, "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" + |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7305 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 7306 | mAnimLayer + " HIDE", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7307 | } |
| 7308 | Surface.openTransaction(); |
| 7309 | try { |
| 7310 | try { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7311 | mSurfaceX = mFrame.left + mXOffset; |
Dianne Hackborn | 529bef6 | 2010-03-25 11:48:43 -0700 | [diff] [blame] | 7312 | mSurfaceY = mFrame.top + mYOffset; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7313 | mSurface.setPosition(mSurfaceX, mSurfaceY); |
| 7314 | mSurfaceLayer = mAnimLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7315 | mSurface.setLayer(mAnimLayer); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7316 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7317 | mSurface.hide(); |
| 7318 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7319 | if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7320 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 7321 | Surface.SURFACE_DITHER); |
| 7322 | } |
| 7323 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7324 | Slog.w(TAG, "Error creating surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7325 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 7326 | } |
| 7327 | mLastHidden = true; |
| 7328 | } finally { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7329 | Surface.closeTransaction(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 7330 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION createSurfaceLocked"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7331 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7332 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7333 | TAG, "Created surface " + this); |
| 7334 | } |
| 7335 | return mSurface; |
| 7336 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7337 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7338 | void destroySurfaceLocked() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7339 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 7340 | mAppToken.startingDisplayed = false; |
| 7341 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7342 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7343 | if (mSurface != null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7344 | mDrawPending = false; |
| 7345 | mCommitDrawPending = false; |
| 7346 | mReadyToShow = false; |
| 7347 | |
| 7348 | int i = mChildWindows.size(); |
| 7349 | while (i > 0) { |
| 7350 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7351 | WindowState c = mChildWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7352 | c.mAttachedHidden = true; |
| 7353 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7354 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7355 | if (mReportDestroySurface) { |
| 7356 | mReportDestroySurface = false; |
| 7357 | mSurfacePendingDestroy = true; |
| 7358 | try { |
| 7359 | mClient.dispatchGetNewSurface(); |
| 7360 | // We'll really destroy on the next time around. |
| 7361 | return; |
| 7362 | } catch (RemoteException e) { |
| 7363 | } |
| 7364 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7365 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7366 | try { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7367 | if (DEBUG_VISIBILITY) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7368 | RuntimeException e = null; |
| 7369 | if (!HIDE_STACK_CRAWLS) { |
| 7370 | e = new RuntimeException(); |
| 7371 | e.fillInStackTrace(); |
| 7372 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7373 | Slog.w(TAG, "Window " + this + " destroying surface " |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7374 | + mSurface + ", session " + mSession, e); |
| 7375 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7376 | if (SHOW_TRANSACTIONS) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7377 | RuntimeException e = null; |
| 7378 | if (!HIDE_STACK_CRAWLS) { |
| 7379 | e = new RuntimeException(); |
| 7380 | e.fillInStackTrace(); |
| 7381 | } |
| 7382 | if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7383 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7384 | mSurface.destroy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7385 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7386 | Slog.w(TAG, "Exception thrown when destroying Window " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7387 | + " surface " + mSurface + " session " + mSession |
| 7388 | + ": " + e.toString()); |
| 7389 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7390 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7391 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7392 | mSurface = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7393 | } |
| 7394 | } |
| 7395 | |
| 7396 | boolean finishDrawingLocked() { |
| 7397 | if (mDrawPending) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7398 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7399 | TAG, "finishDrawingLocked: " + mSurface); |
| 7400 | mCommitDrawPending = true; |
| 7401 | mDrawPending = false; |
| 7402 | return true; |
| 7403 | } |
| 7404 | return false; |
| 7405 | } |
| 7406 | |
| 7407 | // This must be called while inside a transaction. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7408 | boolean commitFinishDrawingLocked(long currentTime) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7409 | //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7410 | if (!mCommitDrawPending) { |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7411 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7412 | } |
| 7413 | mCommitDrawPending = false; |
| 7414 | mReadyToShow = true; |
| 7415 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 7416 | final AppWindowToken atoken = mAppToken; |
| 7417 | if (atoken == null || atoken.allDrawn || starting) { |
| 7418 | performShowLocked(); |
| 7419 | } |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7420 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7421 | } |
| 7422 | |
| 7423 | // This must be called while inside a transaction. |
| 7424 | boolean performShowLocked() { |
| 7425 | if (DEBUG_VISIBILITY) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7426 | RuntimeException e = null; |
| 7427 | if (!HIDE_STACK_CRAWLS) { |
| 7428 | e = new RuntimeException(); |
| 7429 | e.fillInStackTrace(); |
| 7430 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7431 | Slog.v(TAG, "performShow on " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7432 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 7433 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 7434 | } |
| 7435 | if (mReadyToShow && isReadyForDisplay()) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7436 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this, |
| 7437 | "SHOW (performShowLocked)", null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7438 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7439 | + " during animation: policyVis=" + mPolicyVisibility |
| 7440 | + " attHidden=" + mAttachedHidden |
| 7441 | + " tok.hiddenRequested=" |
| 7442 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7443 | + " tok.hidden=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7444 | + (mAppToken != null ? mAppToken.hidden : false) |
| 7445 | + " animating=" + mAnimating |
| 7446 | + " tok animating=" |
| 7447 | + (mAppToken != null ? mAppToken.animating : false)); |
| 7448 | if (!showSurfaceRobustlyLocked(this)) { |
| 7449 | return false; |
| 7450 | } |
| 7451 | mLastAlpha = -1; |
| 7452 | mHasDrawn = true; |
| 7453 | mLastHidden = false; |
| 7454 | mReadyToShow = false; |
| 7455 | enableScreenIfNeededLocked(); |
| 7456 | |
| 7457 | applyEnterAnimationLocked(this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7458 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7459 | int i = mChildWindows.size(); |
| 7460 | while (i > 0) { |
| 7461 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7462 | WindowState c = mChildWindows.get(i); |
Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7463 | if (c.mAttachedHidden) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7464 | c.mAttachedHidden = false; |
Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7465 | if (c.mSurface != null) { |
| 7466 | c.performShowLocked(); |
| 7467 | // It hadn't been shown, which means layout not |
| 7468 | // performed on it, so now we want to make sure to |
| 7469 | // do a layout. If called from within the transaction |
| 7470 | // loop, this will cause it to restart with a new |
| 7471 | // layout. |
| 7472 | mLayoutNeeded = true; |
| 7473 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7474 | } |
| 7475 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7476 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7477 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 7478 | && mAppToken != null) { |
| 7479 | mAppToken.firstWindowDrawn = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7480 | |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7481 | if (mAppToken.startingData != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7482 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7483 | "Finish starting " + mToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7484 | + ": first real window is shown, no animation"); |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7485 | // If this initial window is animating, stop it -- we |
| 7486 | // will do an animation to reveal it from behind the |
| 7487 | // starting window, so there is no need for it to also |
| 7488 | // be doing its own stuff. |
| 7489 | if (mAnimation != null) { |
Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7490 | mAnimation.cancel(); |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7491 | mAnimation = null; |
| 7492 | // Make sure we clean up the animation. |
| 7493 | mAnimating = true; |
| 7494 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7495 | mFinishedStarting.add(mAppToken); |
| 7496 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7497 | } |
| 7498 | mAppToken.updateReportedVisibilityLocked(); |
| 7499 | } |
| 7500 | } |
| 7501 | return true; |
| 7502 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7503 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7504 | // This must be called while inside a transaction. Returns true if |
| 7505 | // there is more animation to run. |
| 7506 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7507 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7508 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7509 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7510 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 7511 | mHasTransformation = true; |
| 7512 | mHasLocalTransformation = true; |
| 7513 | if (!mLocalAnimating) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7514 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7515 | TAG, "Starting animation in " + this + |
| 7516 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 7517 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 7518 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 7519 | mAnimation.setStartTime(currentTime); |
| 7520 | mLocalAnimating = true; |
| 7521 | mAnimating = true; |
| 7522 | } |
| 7523 | mTransformation.clear(); |
| 7524 | final boolean more = mAnimation.getTransformation( |
| 7525 | currentTime, mTransformation); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7526 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7527 | TAG, "Stepped animation in " + this + |
| 7528 | ": more=" + more + ", xform=" + mTransformation); |
| 7529 | if (more) { |
| 7530 | // we're not done! |
| 7531 | return true; |
| 7532 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7533 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7534 | TAG, "Finished animation in " + this + |
| 7535 | " @ " + currentTime); |
Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7536 | |
| 7537 | if (mAnimation != null) { |
| 7538 | mAnimation.cancel(); |
| 7539 | mAnimation = null; |
| 7540 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7541 | //WindowManagerService.this.dump(); |
| 7542 | } |
| 7543 | mHasLocalTransformation = false; |
| 7544 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7545 | && mAppToken.animation != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7546 | // When our app token is animating, we kind-of pretend like |
| 7547 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 7548 | // part of this check means that we will only do this if |
| 7549 | // our window is not currently exiting, or it is not |
| 7550 | // locally animating itself. The idea being that one that |
| 7551 | // is exiting and doing a local animation should be removed |
| 7552 | // once that animation is done. |
| 7553 | mAnimating = true; |
| 7554 | mHasTransformation = true; |
| 7555 | mTransformation.clear(); |
| 7556 | return false; |
| 7557 | } else if (mHasTransformation) { |
| 7558 | // Little trick to get through the path below to act like |
| 7559 | // we have finished an animation. |
| 7560 | mAnimating = true; |
| 7561 | } else if (isAnimating()) { |
| 7562 | mAnimating = true; |
| 7563 | } |
| 7564 | } else if (mAnimation != null) { |
| 7565 | // If the display is frozen, and there is a pending animation, |
| 7566 | // clear it and make sure we run the cleanup code. |
| 7567 | mAnimating = true; |
| 7568 | mLocalAnimating = true; |
Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7569 | mAnimation.cancel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7570 | mAnimation = null; |
| 7571 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7572 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7573 | if (!mAnimating && !mLocalAnimating) { |
| 7574 | return false; |
| 7575 | } |
| 7576 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7577 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7578 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 7579 | + ", reportedVisible=" |
| 7580 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7581 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7582 | mAnimating = false; |
| 7583 | mLocalAnimating = false; |
Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7584 | if (mAnimation != null) { |
| 7585 | mAnimation.cancel(); |
| 7586 | mAnimation = null; |
| 7587 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7588 | mAnimLayer = mLayer; |
| 7589 | if (mIsImWindow) { |
| 7590 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7591 | } else if (mIsWallpaper) { |
| 7592 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7593 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7594 | if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7595 | + " anim layer: " + mAnimLayer); |
| 7596 | mHasTransformation = false; |
| 7597 | mHasLocalTransformation = false; |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7598 | if (mPolicyVisibility != mPolicyVisibilityAfterAnim) { |
| 7599 | if (DEBUG_VISIBILITY) { |
| 7600 | Slog.v(TAG, "Policy visibility changing after anim in " + this + ": " |
| 7601 | + mPolicyVisibilityAfterAnim); |
| 7602 | } |
| 7603 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 7604 | if (!mPolicyVisibility) { |
| 7605 | if (mCurrentFocus == this) { |
| 7606 | mFocusMayChange = true; |
| 7607 | } |
| 7608 | // Window is no longer visible -- make sure if we were waiting |
| 7609 | // for it to be displayed before enabling the display, that |
| 7610 | // we allow the display to be enabled now. |
| 7611 | enableScreenIfNeededLocked(); |
| 7612 | } |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7613 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7614 | mTransformation.clear(); |
| 7615 | if (mHasDrawn |
| 7616 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 7617 | && mAppToken != null |
| 7618 | && mAppToken.firstWindowDrawn |
| 7619 | && mAppToken.startingData != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7620 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7621 | + mToken + ": first real window done animating"); |
| 7622 | mFinishedStarting.add(mAppToken); |
| 7623 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7624 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7625 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7626 | finishExit(); |
| 7627 | |
| 7628 | if (mAppToken != null) { |
| 7629 | mAppToken.updateReportedVisibilityLocked(); |
| 7630 | } |
| 7631 | |
| 7632 | return false; |
| 7633 | } |
| 7634 | |
| 7635 | void finishExit() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7636 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7637 | TAG, "finishExit in " + this |
| 7638 | + ": exiting=" + mExiting |
| 7639 | + " remove=" + mRemoveOnExit |
| 7640 | + " windowAnimating=" + isWindowAnimating()); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7641 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7642 | final int N = mChildWindows.size(); |
| 7643 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7644 | mChildWindows.get(i).finishExit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7645 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7646 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7647 | if (!mExiting) { |
| 7648 | return; |
| 7649 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7650 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7651 | if (isWindowAnimating()) { |
| 7652 | return; |
| 7653 | } |
| 7654 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7655 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7656 | TAG, "Exit animation finished in " + this |
| 7657 | + ": remove=" + mRemoveOnExit); |
| 7658 | if (mSurface != null) { |
| 7659 | mDestroySurface.add(this); |
| 7660 | mDestroying = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7661 | if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7662 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7663 | try { |
| 7664 | mSurface.hide(); |
| 7665 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7666 | Slog.w(TAG, "Error hiding surface in " + this, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7667 | } |
| 7668 | mLastHidden = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7669 | } |
| 7670 | mExiting = false; |
| 7671 | if (mRemoveOnExit) { |
| 7672 | mPendingRemove.add(this); |
| 7673 | mRemoveOnExit = false; |
| 7674 | } |
| 7675 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7676 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7677 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 7678 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 7679 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 7680 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 7681 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 7682 | return true; |
| 7683 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7684 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7685 | void computeShownFrameLocked() { |
| 7686 | final boolean selfTransformation = mHasLocalTransformation; |
| 7687 | Transformation attachedTransformation = |
| 7688 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 7689 | ? mAttachedWindow.mTransformation : null; |
| 7690 | Transformation appTransformation = |
| 7691 | (mAppToken != null && mAppToken.hasTransformation) |
| 7692 | ? mAppToken.transformation : null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7693 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7694 | // Wallpapers are animated based on the "real" window they |
| 7695 | // are currently targeting. |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7696 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7697 | && mWallpaperTarget != null) { |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7698 | if (mWallpaperTarget.mHasLocalTransformation && |
| 7699 | mWallpaperTarget.mAnimation != null && |
| 7700 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7701 | attachedTransformation = mWallpaperTarget.mTransformation; |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7702 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7703 | Slog.v(TAG, "WP target attached xform: " + attachedTransformation); |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7704 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7705 | } |
| 7706 | if (mWallpaperTarget.mAppToken != null && |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7707 | mWallpaperTarget.mAppToken.hasTransformation && |
| 7708 | mWallpaperTarget.mAppToken.animation != null && |
| 7709 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7710 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7711 | if (DEBUG_WALLPAPER && appTransformation != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7712 | Slog.v(TAG, "WP target app xform: " + appTransformation); |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7713 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7714 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7715 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7716 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7717 | final boolean screenAnimation = mScreenRotationAnimation != null |
| 7718 | && mScreenRotationAnimation.isAnimating(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7719 | if (selfTransformation || attachedTransformation != null |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7720 | || appTransformation != null || screenAnimation) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7721 | // cache often used attributes locally |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7722 | final Rect frame = mFrame; |
| 7723 | final float tmpFloats[] = mTmpFloats; |
| 7724 | final Matrix tmpMatrix = mTmpMatrix; |
| 7725 | |
| 7726 | // Compute the desired transformation. |
Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7727 | tmpMatrix.setTranslate(0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7728 | if (selfTransformation) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7729 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7730 | } |
Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7731 | tmpMatrix.postTranslate(frame.left, frame.top); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7732 | if (attachedTransformation != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7733 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7734 | } |
| 7735 | if (appTransformation != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7736 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7737 | } |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7738 | if (screenAnimation) { |
| 7739 | tmpMatrix.postConcat( |
| 7740 | mScreenRotationAnimation.getEnterTransformation().getMatrix()); |
| 7741 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7742 | |
| 7743 | // "convert" it into SurfaceFlinger's format |
| 7744 | // (a 2x2 matrix + an offset) |
| 7745 | // Here we must not transform the position of the surface |
| 7746 | // since it is already included in the transformation. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7747 | //Slog.i(TAG, "Transform: " + matrix); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7748 | |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 7749 | mHaveMatrix = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7750 | tmpMatrix.getValues(tmpFloats); |
| 7751 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7752 | mDtDx = tmpFloats[Matrix.MSKEW_Y]; |
| 7753 | mDsDy = tmpFloats[Matrix.MSKEW_X]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7754 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7755 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 7756 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7757 | int w = frame.width(); |
| 7758 | int h = frame.height(); |
| 7759 | mShownFrame.set(x, y, x+w, y+h); |
| 7760 | |
| 7761 | // Now set the alpha... but because our current hardware |
| 7762 | // can't do alpha transformation on a non-opaque surface, |
| 7763 | // turn it off if we are running an animation that is also |
| 7764 | // transforming since it is more important to have that |
| 7765 | // animation be smooth. |
| 7766 | mShownAlpha = mAlpha; |
| 7767 | if (!mLimitedAlphaCompositing |
| 7768 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 7769 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 7770 | && x == frame.left && y == frame.top))) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7771 | //Slog.i(TAG, "Applying alpha transform"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7772 | if (selfTransformation) { |
| 7773 | mShownAlpha *= mTransformation.getAlpha(); |
| 7774 | } |
| 7775 | if (attachedTransformation != null) { |
| 7776 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 7777 | } |
| 7778 | if (appTransformation != null) { |
| 7779 | mShownAlpha *= appTransformation.getAlpha(); |
| 7780 | } |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7781 | if (screenAnimation) { |
| 7782 | mShownAlpha *= |
| 7783 | mScreenRotationAnimation.getEnterTransformation().getAlpha(); |
| 7784 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7785 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7786 | //Slog.i(TAG, "Not applying alpha transform"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7787 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7788 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7789 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7790 | TAG, "Continuing animation in " + this + |
| 7791 | ": " + mShownFrame + |
| 7792 | ", alpha=" + mTransformation.getAlpha()); |
| 7793 | return; |
| 7794 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7795 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7796 | mShownFrame.set(mFrame); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7797 | if (mXOffset != 0 || mYOffset != 0) { |
| 7798 | mShownFrame.offset(mXOffset, mYOffset); |
| 7799 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7800 | mShownAlpha = mAlpha; |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 7801 | mHaveMatrix = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7802 | mDsDx = 1; |
| 7803 | mDtDx = 0; |
| 7804 | mDsDy = 0; |
| 7805 | mDtDy = 1; |
| 7806 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7807 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7808 | /** |
| 7809 | * Is this window visible? It is not visible if there is no |
| 7810 | * surface, or we are in the process of running an exit animation |
| 7811 | * that will remove the surface, or its app token has been hidden. |
| 7812 | */ |
| 7813 | public boolean isVisibleLw() { |
| 7814 | final AppWindowToken atoken = mAppToken; |
| 7815 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7816 | && (atoken == null || !atoken.hiddenRequested) |
| 7817 | && !mExiting && !mDestroying; |
| 7818 | } |
| 7819 | |
| 7820 | /** |
Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7821 | * Like {@link #isVisibleLw}, but also counts a window that is currently |
| 7822 | * "hidden" behind the keyguard as visible. This allows us to apply |
| 7823 | * things like window flags that impact the keyguard. |
| 7824 | * XXX I am starting to think we need to have ANOTHER visibility flag |
| 7825 | * for this "hidden behind keyguard" state rather than overloading |
| 7826 | * mPolicyVisibility. Ungh. |
| 7827 | */ |
| 7828 | public boolean isVisibleOrBehindKeyguardLw() { |
| 7829 | final AppWindowToken atoken = mAppToken; |
| 7830 | return mSurface != null && !mAttachedHidden |
| 7831 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7832 | && !mDrawPending && !mCommitDrawPending |
Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7833 | && !mExiting && !mDestroying; |
| 7834 | } |
| 7835 | |
| 7836 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7837 | * Is this window visible, ignoring its app token? It is not visible |
| 7838 | * if there is no surface, or we are in the process of running an exit animation |
| 7839 | * that will remove the surface. |
| 7840 | */ |
| 7841 | public boolean isWinVisibleLw() { |
| 7842 | final AppWindowToken atoken = mAppToken; |
| 7843 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7844 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 7845 | && !mExiting && !mDestroying; |
| 7846 | } |
| 7847 | |
| 7848 | /** |
| 7849 | * The same as isVisible(), but follows the current hidden state of |
| 7850 | * the associated app token, not the pending requested hidden state. |
| 7851 | */ |
| 7852 | boolean isVisibleNow() { |
| 7853 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7854 | && !mRootToken.hidden && !mExiting && !mDestroying; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7855 | } |
| 7856 | |
| 7857 | /** |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7858 | * Can this window possibly be a drag/drop target? The test here is |
| 7859 | * a combination of the above "visible now" with the check that the |
| 7860 | * Input Manager uses when discarding windows from input consideration. |
| 7861 | */ |
| 7862 | boolean isPotentialDragTarget() { |
| 7863 | return isVisibleNow() && (mInputChannel != null) && !mRemoved; |
| 7864 | } |
| 7865 | |
| 7866 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7867 | * Same as isVisible(), but we also count it as visible between the |
| 7868 | * call to IWindowSession.add() and the first relayout(). |
| 7869 | */ |
| 7870 | boolean isVisibleOrAdding() { |
| 7871 | final AppWindowToken atoken = mAppToken; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7872 | return ((mSurface != null && !mReportDestroySurface) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7873 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 7874 | && mPolicyVisibility && !mAttachedHidden |
| 7875 | && (atoken == null || !atoken.hiddenRequested) |
| 7876 | && !mExiting && !mDestroying; |
| 7877 | } |
| 7878 | |
| 7879 | /** |
| 7880 | * Is this window currently on-screen? It is on-screen either if it |
| 7881 | * is visible or it is currently running an animation before no longer |
| 7882 | * being visible. |
| 7883 | */ |
| 7884 | boolean isOnScreen() { |
| 7885 | final AppWindowToken atoken = mAppToken; |
| 7886 | if (atoken != null) { |
| 7887 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7888 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7889 | || mAnimation != null || atoken.animation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7890 | } else { |
| 7891 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7892 | && (!mAttachedHidden || mAnimation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7893 | } |
| 7894 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7895 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7896 | /** |
| 7897 | * Like isOnScreen(), but we don't return true if the window is part |
| 7898 | * of a transition that has not yet been started. |
| 7899 | */ |
| 7900 | boolean isReadyForDisplay() { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7901 | if (mRootToken.waitingToShow && |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 7902 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7903 | return false; |
| 7904 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7905 | final AppWindowToken atoken = mAppToken; |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7906 | final boolean animating = atoken != null |
| 7907 | ? (atoken.animation != null) : false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7908 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7909 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 7910 | && !mRootToken.hidden) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7911 | || mAnimation != null || animating); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7912 | } |
| 7913 | |
| 7914 | /** Is the window or its container currently animating? */ |
| 7915 | boolean isAnimating() { |
| 7916 | final WindowState attached = mAttachedWindow; |
| 7917 | final AppWindowToken atoken = mAppToken; |
| 7918 | return mAnimation != null |
| 7919 | || (attached != null && attached.mAnimation != null) |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7920 | || (atoken != null && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7921 | (atoken.animation != null |
| 7922 | || atoken.inPendingTransaction)); |
| 7923 | } |
| 7924 | |
| 7925 | /** Is this window currently animating? */ |
| 7926 | boolean isWindowAnimating() { |
| 7927 | return mAnimation != null; |
| 7928 | } |
| 7929 | |
| 7930 | /** |
| 7931 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 7932 | * been drawn. |
| 7933 | */ |
| 7934 | public boolean isDisplayedLw() { |
| 7935 | final AppWindowToken atoken = mAppToken; |
| 7936 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7937 | && !mDrawPending && !mCommitDrawPending |
| 7938 | && ((!mAttachedHidden && |
| 7939 | (atoken == null || !atoken.hiddenRequested)) |
| 7940 | || mAnimating); |
| 7941 | } |
| 7942 | |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7943 | /** |
| 7944 | * Returns true if the window has a surface that it has drawn a |
| 7945 | * complete UI in to. |
| 7946 | */ |
| 7947 | public boolean isDrawnLw() { |
| 7948 | final AppWindowToken atoken = mAppToken; |
| 7949 | return mSurface != null && !mDestroying |
| 7950 | && !mDrawPending && !mCommitDrawPending; |
| 7951 | } |
| 7952 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7953 | /** |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7954 | * Return true if the window is opaque and fully drawn. This indicates |
| 7955 | * it may obscure windows behind it. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7956 | */ |
| 7957 | boolean isOpaqueDrawn() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7958 | return (mAttrs.format == PixelFormat.OPAQUE |
| 7959 | || mAttrs.type == TYPE_WALLPAPER) |
| 7960 | && mSurface != null && mAnimation == null |
| 7961 | && (mAppToken == null || mAppToken.animation == null) |
| 7962 | && !mDrawPending && !mCommitDrawPending; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7963 | } |
| 7964 | |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 7965 | /** |
| 7966 | * Return whether this window is wanting to have a translation |
| 7967 | * animation applied to it for an in-progress move. (Only makes |
| 7968 | * sense to call from performLayoutAndPlaceSurfacesLockedInner().) |
| 7969 | */ |
| 7970 | boolean shouldAnimateMove() { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 7971 | return mContentChanged && !mExiting && !mLastHidden && !mDisplayFrozen |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 7972 | && (mFrame.top != mLastFrame.top |
| 7973 | || mFrame.left != mLastFrame.left) |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 7974 | && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove()) |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 7975 | && mPolicy.isScreenOn(); |
| 7976 | } |
| 7977 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7978 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 7979 | return |
| 7980 | // only if the application is requesting compatible window |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7981 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 7982 | // only if it's visible |
| 7983 | mHasDrawn && mViewVisibility == View.VISIBLE && |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7984 | // and only if the application fills the compatible screen |
| 7985 | mFrame.left <= mCompatibleScreenFrame.left && |
| 7986 | mFrame.top <= mCompatibleScreenFrame.top && |
| 7987 | mFrame.right >= mCompatibleScreenFrame.right && |
| 7988 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7989 | // and starting window do not need background filler |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7990 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7991 | } |
| 7992 | |
| 7993 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 7994 | return mFrame.left <= 0 && mFrame.top <= 0 && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7995 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7996 | } |
| 7997 | |
| 7998 | void removeLocked() { |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 7999 | disposeInputChannel(); |
| 8000 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8001 | if (mAttachedWindow != null) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8002 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8003 | mAttachedWindow.mChildWindows.remove(this); |
| 8004 | } |
| 8005 | destroySurfaceLocked(); |
| 8006 | mSession.windowRemovedLocked(); |
| 8007 | try { |
| 8008 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 8009 | } catch (RuntimeException e) { |
| 8010 | // Ignore if it has already been removed (usually because |
| 8011 | // we are doing this as part of processing a death note.) |
| 8012 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 8013 | } |
| 8014 | |
| 8015 | void disposeInputChannel() { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 8016 | if (mInputChannel != null) { |
| 8017 | mInputManager.unregisterInputChannel(mInputChannel); |
| 8018 | |
| 8019 | mInputChannel.dispose(); |
| 8020 | mInputChannel = null; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8021 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8022 | } |
| 8023 | |
| 8024 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 8025 | public void binderDied() { |
| 8026 | try { |
| 8027 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8028 | WindowState win = windowForClientLocked(mSession, mClient, false); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8029 | Slog.i(TAG, "WIN DEATH: " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8030 | if (win != null) { |
| 8031 | removeWindowLocked(mSession, win); |
| 8032 | } |
| 8033 | } |
| 8034 | } catch (IllegalArgumentException ex) { |
| 8035 | // This will happen if the window has already been |
| 8036 | // removed. |
| 8037 | } |
| 8038 | } |
| 8039 | } |
| 8040 | |
| 8041 | /** Returns true if this window desires key events. */ |
| 8042 | public final boolean canReceiveKeys() { |
| 8043 | return isVisibleOrAdding() |
| 8044 | && (mViewVisibility == View.VISIBLE) |
| 8045 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 8046 | } |
| 8047 | |
| 8048 | public boolean hasDrawnLw() { |
| 8049 | return mHasDrawn; |
| 8050 | } |
| 8051 | |
| 8052 | public boolean showLw(boolean doAnimation) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8053 | return showLw(doAnimation, true); |
| 8054 | } |
| 8055 | |
| 8056 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 8057 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 8058 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8059 | } |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8060 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8061 | if (doAnimation) { |
| 8062 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
| 8063 | + mPolicyVisibility + " mAnimation=" + mAnimation); |
| 8064 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 8065 | doAnimation = false; |
| 8066 | } else if (mPolicyVisibility && mAnimation == null) { |
| 8067 | // Check for the case where we are currently visible and |
| 8068 | // not animating; we do not want to do animation at such a |
| 8069 | // point to become visible when we already are. |
| 8070 | doAnimation = false; |
| 8071 | } |
| 8072 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8073 | mPolicyVisibility = true; |
| 8074 | mPolicyVisibilityAfterAnim = true; |
| 8075 | if (doAnimation) { |
| 8076 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 8077 | } |
| 8078 | if (requestAnim) { |
| 8079 | requestAnimationLocked(0); |
| 8080 | } |
| 8081 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8082 | } |
| 8083 | |
| 8084 | public boolean hideLw(boolean doAnimation) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8085 | return hideLw(doAnimation, true); |
| 8086 | } |
| 8087 | |
| 8088 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8089 | if (doAnimation) { |
| 8090 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 8091 | doAnimation = false; |
| 8092 | } |
| 8093 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8094 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 8095 | : mPolicyVisibility; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8096 | if (!current) { |
| 8097 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8098 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8099 | if (doAnimation) { |
| 8100 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 8101 | if (mAnimation == null) { |
| 8102 | doAnimation = false; |
| 8103 | } |
| 8104 | } |
| 8105 | if (doAnimation) { |
| 8106 | mPolicyVisibilityAfterAnim = false; |
| 8107 | } else { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8108 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8109 | mPolicyVisibilityAfterAnim = false; |
| 8110 | mPolicyVisibility = false; |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 8111 | // Window is no longer visible -- make sure if we were waiting |
| 8112 | // for it to be displayed before enabling the display, that |
| 8113 | // we allow the display to be enabled now. |
| 8114 | enableScreenIfNeededLocked(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8115 | if (mCurrentFocus == this) { |
| 8116 | mFocusMayChange = true; |
| 8117 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8118 | } |
| 8119 | if (requestAnim) { |
| 8120 | requestAnimationLocked(0); |
| 8121 | } |
| 8122 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8123 | } |
| 8124 | |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 8125 | public void getTouchableRegion(Region outRegion) { |
| 8126 | final Rect frame = mFrame; |
| 8127 | switch (mTouchableInsets) { |
| 8128 | default: |
| 8129 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME: |
| 8130 | outRegion.set(frame); |
| 8131 | break; |
| 8132 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: { |
| 8133 | final Rect inset = mGivenContentInsets; |
| 8134 | outRegion.set( |
| 8135 | frame.left + inset.left, frame.top + inset.top, |
| 8136 | frame.right - inset.right, frame.bottom - inset.bottom); |
| 8137 | break; |
| 8138 | } |
| 8139 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: { |
| 8140 | final Rect inset = mGivenVisibleInsets; |
| 8141 | outRegion.set( |
| 8142 | frame.left + inset.left, frame.top + inset.top, |
| 8143 | frame.right - inset.right, frame.bottom - inset.bottom); |
| 8144 | break; |
| 8145 | } |
| 8146 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: { |
| 8147 | final Region givenTouchableRegion = mGivenTouchableRegion; |
| 8148 | outRegion.set(givenTouchableRegion); |
| 8149 | outRegion.translate(frame.left, frame.top); |
| 8150 | break; |
| 8151 | } |
| 8152 | } |
| 8153 | } |
| 8154 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8155 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8156 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 8157 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 8158 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 8159 | if (mAttachedWindow != null || mLayoutAttached) { |
| 8160 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 8161 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 8162 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 8163 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 8164 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 8165 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8166 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 8167 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8168 | } |
| 8169 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 8170 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 8171 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 8172 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 8173 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 8174 | pw.print("="); pw.print(mAnimLayer); |
| 8175 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 8176 | if (mSurface != null) { |
| 8177 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8178 | pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown); |
| 8179 | pw.print(" layer="); pw.print(mSurfaceLayer); |
| 8180 | pw.print(" alpha="); pw.print(mSurfaceAlpha); |
| 8181 | pw.print(" rect=("); pw.print(mSurfaceX); |
| 8182 | pw.print(","); pw.print(mSurfaceY); |
| 8183 | pw.print(") "); pw.print(mSurfaceW); |
| 8184 | pw.print(" x "); pw.println(mSurfaceH); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8185 | } |
| 8186 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 8187 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 8188 | if (mAppToken != null) { |
| 8189 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 8190 | } |
| 8191 | if (mTargetAppToken != null) { |
| 8192 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 8193 | } |
| 8194 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 8195 | pw.print(Integer.toHexString(mViewVisibility)); |
| 8196 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8197 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 8198 | pw.print(" mObscured="); pw.println(mObscured); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8199 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 8200 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 8201 | pw.print(mPolicyVisibility); |
| 8202 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 8203 | pw.print(mPolicyVisibilityAfterAnim); |
| 8204 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 8205 | } |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 8206 | if (!mRelayoutCalled) { |
| 8207 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled); |
| 8208 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8209 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8210 | pw.print(" h="); pw.print(mRequestedHeight); |
| 8211 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8212 | if (mXOffset != 0 || mYOffset != 0) { |
| 8213 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 8214 | pw.print(" y="); pw.println(mYOffset); |
| 8215 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8216 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 8217 | mGivenContentInsets.printShortString(pw); |
| 8218 | pw.print(" mGivenVisibleInsets="); |
| 8219 | mGivenVisibleInsets.printShortString(pw); |
| 8220 | pw.println(); |
| 8221 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 8222 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 8223 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 8224 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8225 | pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8226 | pw.print(prefix); pw.print("mShownFrame="); |
| 8227 | mShownFrame.printShortString(pw); |
| 8228 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 8229 | pw.println(); |
| 8230 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 8231 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 8232 | pw.println(); |
| 8233 | pw.print(prefix); pw.print("mContainingFrame="); |
| 8234 | mContainingFrame.printShortString(pw); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 8235 | pw.print(" mParentFrame="); |
| 8236 | mParentFrame.printShortString(pw); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8237 | pw.print(" mDisplayFrame="); |
| 8238 | mDisplayFrame.printShortString(pw); |
| 8239 | pw.println(); |
| 8240 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 8241 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 8242 | pw.println(); |
| 8243 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 8244 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 8245 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 8246 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 8247 | pw.println(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8248 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 8249 | || mAnimation != null) { |
| 8250 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 8251 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 8252 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 8253 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 8254 | } |
| 8255 | if (mHasTransformation || mHasLocalTransformation) { |
| 8256 | pw.print(prefix); pw.print("XForm: has="); |
| 8257 | pw.print(mHasTransformation); |
| 8258 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 8259 | pw.print(" "); mTransformation.printShortString(pw); |
| 8260 | pw.println(); |
| 8261 | } |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 8262 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 8263 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 8264 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 8265 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 8266 | } |
| 8267 | if (mHaveMatrix) { |
| 8268 | pw.print(prefix); pw.print("mDsDx="); pw.print(mDsDx); |
| 8269 | pw.print(" mDtDx="); pw.print(mDtDx); |
| 8270 | pw.print(" mDsDy="); pw.print(mDsDy); |
| 8271 | pw.print(" mDtDy="); pw.println(mDtDy); |
| 8272 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8273 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 8274 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 8275 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 8276 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 8277 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 8278 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 8279 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 8280 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 8281 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 8282 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8283 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8284 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 8285 | pw.print(mOrientationChanging); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8286 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 8287 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8288 | } |
Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 8289 | if (mHScale != 1 || mVScale != 1) { |
| 8290 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 8291 | pw.print(" mVScale="); pw.println(mVScale); |
| 8292 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 8293 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8294 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 8295 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 8296 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 8297 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 8298 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 8299 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 8300 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8301 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8302 | |
| 8303 | String makeInputChannelName() { |
| 8304 | return Integer.toHexString(System.identityHashCode(this)) |
| 8305 | + " " + mAttrs.getTitle(); |
| 8306 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8307 | |
| 8308 | @Override |
| 8309 | public String toString() { |
Mattias Petersson | 1622eee | 2010-12-21 10:15:11 +0100 | [diff] [blame] | 8310 | if (mStringNameCache == null || mLastTitle != mAttrs.getTitle() |
| 8311 | || mWasPaused != mToken.paused) { |
| 8312 | mLastTitle = mAttrs.getTitle(); |
| 8313 | mWasPaused = mToken.paused; |
| 8314 | mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this)) |
| 8315 | + " " + mLastTitle + " paused=" + mWasPaused + "}"; |
| 8316 | } |
| 8317 | return mStringNameCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8318 | } |
| 8319 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8320 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8321 | // ------------------------------------------------------------- |
| 8322 | // Window Token State |
| 8323 | // ------------------------------------------------------------- |
| 8324 | |
| 8325 | class WindowToken { |
| 8326 | // The actual token. |
| 8327 | final IBinder token; |
| 8328 | |
| 8329 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 8330 | final int windowType; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8331 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8332 | // Set if this token was explicitly added by a client, so should |
| 8333 | // not be removed when all windows are removed. |
| 8334 | final boolean explicit; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8335 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8336 | // For printing. |
| 8337 | String stringName; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8338 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8339 | // If this is an AppWindowToken, this is non-null. |
| 8340 | AppWindowToken appWindowToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8341 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8342 | // All of the windows associated with this token. |
| 8343 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 8344 | |
| 8345 | // Is key dispatching paused for this token? |
| 8346 | boolean paused = false; |
| 8347 | |
| 8348 | // Should this token's windows be hidden? |
| 8349 | boolean hidden; |
| 8350 | |
| 8351 | // Temporary for finding which tokens no longer have visible windows. |
| 8352 | boolean hasVisible; |
| 8353 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8354 | // Set to true when this token is in a pending transaction where it |
| 8355 | // will be shown. |
| 8356 | boolean waitingToShow; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8357 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8358 | // Set to true when this token is in a pending transaction where it |
| 8359 | // will be hidden. |
| 8360 | boolean waitingToHide; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8361 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8362 | // Set to true when this token is in a pending transaction where its |
| 8363 | // windows will be put to the bottom of the list. |
| 8364 | boolean sendingToBottom; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8365 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8366 | // Set to true when this token is in a pending transaction where its |
| 8367 | // windows will be put to the top of the list. |
| 8368 | boolean sendingToTop; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8369 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8370 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 8371 | token = _token; |
| 8372 | windowType = type; |
| 8373 | explicit = _explicit; |
| 8374 | } |
| 8375 | |
| 8376 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8377 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 8378 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 8379 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 8380 | pw.print(" hidden="); pw.print(hidden); |
| 8381 | pw.print(" hasVisible="); pw.println(hasVisible); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8382 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 8383 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 8384 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 8385 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 8386 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 8387 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8388 | } |
| 8389 | |
| 8390 | @Override |
| 8391 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8392 | if (stringName == null) { |
| 8393 | StringBuilder sb = new StringBuilder(); |
| 8394 | sb.append("WindowToken{"); |
| 8395 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8396 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8397 | stringName = sb.toString(); |
| 8398 | } |
| 8399 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8400 | } |
| 8401 | }; |
| 8402 | |
| 8403 | class AppWindowToken extends WindowToken { |
| 8404 | // Non-null only for application tokens. |
| 8405 | final IApplicationToken appToken; |
| 8406 | |
| 8407 | // All of the windows and child windows that are included in this |
| 8408 | // application token. Note this list is NOT sorted! |
| 8409 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 8410 | |
| 8411 | int groupId = -1; |
| 8412 | boolean appFullscreen; |
| 8413 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8414 | |
| 8415 | // The input dispatching timeout for this application token in nanoseconds. |
| 8416 | long inputDispatchingTimeoutNanos; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8417 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8418 | // These are used for determining when all windows associated with |
| 8419 | // an activity have been drawn, so they can be made visible together |
| 8420 | // at the same time. |
| 8421 | int lastTransactionSequence = mTransactionSequence-1; |
| 8422 | int numInterestingWindows; |
| 8423 | int numDrawnWindows; |
| 8424 | boolean inPendingTransaction; |
| 8425 | boolean allDrawn; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8426 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8427 | // Is this token going to be hidden in a little while? If so, it |
| 8428 | // won't be taken into account for setting the screen orientation. |
| 8429 | boolean willBeHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8430 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8431 | // Is this window's surface needed? This is almost like hidden, except |
| 8432 | // it will sometimes be true a little earlier: when the token has |
| 8433 | // been shown, but is still waiting for its app transition to execute |
| 8434 | // before making its windows shown. |
| 8435 | boolean hiddenRequested; |
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 | // Have we told the window clients to hide themselves? |
| 8438 | boolean clientHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8439 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8440 | // Last visibility state we reported to the app token. |
| 8441 | boolean reportedVisible; |
| 8442 | |
| 8443 | // Set to true when the token has been removed from the window mgr. |
| 8444 | boolean removed; |
| 8445 | |
| 8446 | // Have we been asked to have this token keep the screen frozen? |
| 8447 | boolean freezingScreen; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8448 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8449 | boolean animating; |
| 8450 | Animation animation; |
| 8451 | boolean hasTransformation; |
| 8452 | final Transformation transformation = new Transformation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8453 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8454 | // Offset to the window of all layers in the token, for use by |
| 8455 | // AppWindowToken animations. |
| 8456 | int animLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8457 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8458 | // Information about an application starting window if displayed. |
| 8459 | StartingData startingData; |
| 8460 | WindowState startingWindow; |
| 8461 | View startingView; |
| 8462 | boolean startingDisplayed; |
| 8463 | boolean startingMoved; |
| 8464 | boolean firstWindowDrawn; |
| 8465 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 8466 | // Input application handle used by the input dispatcher. |
| 8467 | InputApplicationHandle mInputApplicationHandle; |
| 8468 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8469 | AppWindowToken(IApplicationToken _token) { |
| 8470 | super(_token.asBinder(), |
| 8471 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 8472 | appWindowToken = this; |
| 8473 | appToken = _token; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 8474 | mInputApplicationHandle = new InputApplicationHandle(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8475 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8476 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8477 | public void setAnimation(Animation anim) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8478 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8479 | TAG, "Setting animation in " + this + ": " + anim); |
| 8480 | animation = anim; |
| 8481 | animating = false; |
| 8482 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 8483 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 8484 | int zorder = anim.getZAdjustment(); |
| 8485 | int adj = 0; |
| 8486 | if (zorder == Animation.ZORDER_TOP) { |
| 8487 | adj = TYPE_LAYER_OFFSET; |
| 8488 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 8489 | adj = -TYPE_LAYER_OFFSET; |
| 8490 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8491 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8492 | if (animLayerAdjustment != adj) { |
| 8493 | animLayerAdjustment = adj; |
| 8494 | updateLayers(); |
| 8495 | } |
| 8496 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8497 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8498 | public void setDummyAnimation() { |
| 8499 | if (animation == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8500 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8501 | TAG, "Setting dummy animation in " + this); |
| 8502 | animation = sDummyAnimation; |
| 8503 | } |
| 8504 | } |
| 8505 | |
| 8506 | public void clearAnimation() { |
| 8507 | if (animation != null) { |
| 8508 | animation = null; |
| 8509 | animating = true; |
| 8510 | } |
| 8511 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8512 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8513 | void updateLayers() { |
| 8514 | final int N = allAppWindows.size(); |
| 8515 | final int adj = animLayerAdjustment; |
| 8516 | for (int i=0; i<N; i++) { |
| 8517 | WindowState w = allAppWindows.get(i); |
| 8518 | w.mAnimLayer = w.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8519 | if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8520 | + w.mAnimLayer); |
| 8521 | if (w == mInputMethodTarget) { |
| 8522 | setInputMethodAnimLayerAdjustment(adj); |
| 8523 | } |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8524 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8525 | setWallpaperAnimLayerAdjustmentLocked(adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8526 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8527 | } |
| 8528 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8529 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8530 | void sendAppVisibilityToClients() { |
| 8531 | final int N = allAppWindows.size(); |
| 8532 | for (int i=0; i<N; i++) { |
| 8533 | WindowState win = allAppWindows.get(i); |
| 8534 | if (win == startingWindow && clientHidden) { |
| 8535 | // Don't hide the starting window. |
| 8536 | continue; |
| 8537 | } |
| 8538 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8539 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8540 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 8541 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 8542 | } catch (RemoteException e) { |
| 8543 | } |
| 8544 | } |
| 8545 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8546 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8547 | void showAllWindowsLocked() { |
| 8548 | final int NW = allAppWindows.size(); |
| 8549 | for (int i=0; i<NW; i++) { |
| 8550 | WindowState w = allAppWindows.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8551 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8552 | "performing show on: " + w); |
| 8553 | w.performShowLocked(); |
| 8554 | } |
| 8555 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8556 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8557 | // This must be called while inside a transaction. |
| 8558 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8559 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8560 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8561 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8562 | if (animation == sDummyAnimation) { |
| 8563 | // This guy is going to animate, but not yet. For now count |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8564 | // it as not animating for purposes of scheduling transactions; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8565 | // when it is really time to animate, this will be set to |
| 8566 | // a real animation and the next call will execute normally. |
| 8567 | return false; |
| 8568 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8569 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8570 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 8571 | if (!animating) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8572 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8573 | TAG, "Starting animation in " + this + |
| 8574 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 8575 | + " scale=" + mTransitionAnimationScale |
| 8576 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 8577 | animation.initialize(dw, dh, dw, dh); |
| 8578 | animation.setStartTime(currentTime); |
| 8579 | animating = true; |
| 8580 | } |
| 8581 | transformation.clear(); |
| 8582 | final boolean more = animation.getTransformation( |
| 8583 | currentTime, transformation); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8584 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8585 | TAG, "Stepped animation in " + this + |
| 8586 | ": more=" + more + ", xform=" + transformation); |
| 8587 | if (more) { |
| 8588 | // we're done! |
| 8589 | hasTransformation = true; |
| 8590 | return true; |
| 8591 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8592 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8593 | TAG, "Finished animation in " + this + |
| 8594 | " @ " + currentTime); |
| 8595 | animation = null; |
| 8596 | } |
| 8597 | } else if (animation != null) { |
| 8598 | // If the display is frozen, and there is a pending animation, |
| 8599 | // clear it and make sure we run the cleanup code. |
| 8600 | animating = true; |
| 8601 | animation = null; |
| 8602 | } |
| 8603 | |
| 8604 | hasTransformation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8605 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8606 | if (!animating) { |
| 8607 | return false; |
| 8608 | } |
| 8609 | |
| 8610 | clearAnimation(); |
| 8611 | animating = false; |
| 8612 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 8613 | moveInputMethodWindowsIfNeededLocked(true); |
| 8614 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8615 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8616 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8617 | TAG, "Animation done in " + this |
| 8618 | + ": reportedVisible=" + reportedVisible); |
| 8619 | |
| 8620 | transformation.clear(); |
| 8621 | if (animLayerAdjustment != 0) { |
| 8622 | animLayerAdjustment = 0; |
| 8623 | updateLayers(); |
| 8624 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8625 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8626 | final int N = windows.size(); |
| 8627 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8628 | windows.get(i).finishExit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8629 | } |
| 8630 | updateReportedVisibilityLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8631 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8632 | return false; |
| 8633 | } |
| 8634 | |
| 8635 | void updateReportedVisibilityLocked() { |
| 8636 | if (appToken == null) { |
| 8637 | return; |
| 8638 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8639 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8640 | int numInteresting = 0; |
| 8641 | int numVisible = 0; |
| 8642 | boolean nowGone = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8643 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8644 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8645 | final int N = allAppWindows.size(); |
| 8646 | for (int i=0; i<N; i++) { |
| 8647 | WindowState win = allAppWindows.get(i); |
Dianne Hackborn | 6cf67fa | 2009-12-21 16:46:34 -0800 | [diff] [blame] | 8648 | if (win == startingWindow || win.mAppFreezing |
The Android Open Source Project | 727cec0 | 2010-04-08 11:35:37 -0700 | [diff] [blame] | 8649 | || win.mViewVisibility != View.VISIBLE |
Ulf Rosdahl | 3935770 | 2010-09-29 12:34:38 +0200 | [diff] [blame] | 8650 | || win.mAttrs.type == TYPE_APPLICATION_STARTING |
| 8651 | || win.mDestroying) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8652 | continue; |
| 8653 | } |
| 8654 | if (DEBUG_VISIBILITY) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8655 | Slog.v(TAG, "Win " + win + ": isDrawn=" |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8656 | + win.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8657 | + ", isAnimating=" + win.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8658 | if (!win.isDrawnLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8659 | Slog.v(TAG, "Not displayed: s=" + win.mSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8660 | + " pv=" + win.mPolicyVisibility |
| 8661 | + " dp=" + win.mDrawPending |
| 8662 | + " cdp=" + win.mCommitDrawPending |
| 8663 | + " ah=" + win.mAttachedHidden |
| 8664 | + " th=" |
| 8665 | + (win.mAppToken != null |
| 8666 | ? win.mAppToken.hiddenRequested : false) |
| 8667 | + " a=" + win.mAnimating); |
| 8668 | } |
| 8669 | } |
| 8670 | numInteresting++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8671 | if (win.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8672 | if (!win.isAnimating()) { |
| 8673 | numVisible++; |
| 8674 | } |
| 8675 | nowGone = false; |
| 8676 | } else if (win.isAnimating()) { |
| 8677 | nowGone = false; |
| 8678 | } |
| 8679 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8680 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8681 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8682 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8683 | + numInteresting + " visible=" + numVisible); |
| 8684 | if (nowVisible != reportedVisible) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8685 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8686 | TAG, "Visibility changed in " + this |
| 8687 | + ": vis=" + nowVisible); |
| 8688 | reportedVisible = nowVisible; |
| 8689 | Message m = mH.obtainMessage( |
| 8690 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 8691 | nowVisible ? 1 : 0, |
| 8692 | nowGone ? 1 : 0, |
| 8693 | this); |
| 8694 | mH.sendMessage(m); |
| 8695 | } |
| 8696 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8697 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8698 | WindowState findMainWindow() { |
| 8699 | int j = windows.size(); |
| 8700 | while (j > 0) { |
| 8701 | j--; |
| 8702 | WindowState win = windows.get(j); |
| 8703 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 8704 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 8705 | return win; |
| 8706 | } |
| 8707 | } |
| 8708 | return null; |
| 8709 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8710 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8711 | void dump(PrintWriter pw, String prefix) { |
| 8712 | super.dump(pw, prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8713 | if (appToken != null) { |
| 8714 | pw.print(prefix); pw.println("app=true"); |
| 8715 | } |
| 8716 | if (allAppWindows.size() > 0) { |
| 8717 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 8718 | } |
| 8719 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8720 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8721 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 8722 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 8723 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 8724 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 8725 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 8726 | if (paused || freezingScreen) { |
| 8727 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 8728 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 8729 | } |
| 8730 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 8731 | || inPendingTransaction || allDrawn) { |
| 8732 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 8733 | pw.print(numInterestingWindows); |
| 8734 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 8735 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 8736 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 8737 | } |
| 8738 | if (animating || animation != null) { |
| 8739 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 8740 | pw.print(" animation="); pw.println(animation); |
| 8741 | } |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 8742 | if (hasTransformation) { |
| 8743 | pw.print(prefix); pw.print("XForm: "); |
| 8744 | transformation.printShortString(pw); |
| 8745 | pw.println(); |
| 8746 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8747 | if (animLayerAdjustment != 0) { |
| 8748 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 8749 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8750 | if (startingData != null || removed || firstWindowDrawn) { |
| 8751 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 8752 | pw.print(" removed="); pw.print(removed); |
| 8753 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 8754 | } |
| 8755 | if (startingWindow != null || startingView != null |
| 8756 | || startingDisplayed || startingMoved) { |
| 8757 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 8758 | pw.print(" startingView="); pw.print(startingView); |
| 8759 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 8760 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 8761 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8762 | } |
| 8763 | |
| 8764 | @Override |
| 8765 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8766 | if (stringName == null) { |
| 8767 | StringBuilder sb = new StringBuilder(); |
| 8768 | sb.append("AppWindowToken{"); |
| 8769 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8770 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8771 | stringName = sb.toString(); |
| 8772 | } |
| 8773 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8774 | } |
| 8775 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8776 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8777 | // ------------------------------------------------------------- |
| 8778 | // DummyAnimation |
| 8779 | // ------------------------------------------------------------- |
| 8780 | |
| 8781 | // This is an animation that does nothing: it just immediately finishes |
| 8782 | // itself every time it is called. It is used as a stub animation in cases |
| 8783 | // where we want to synchronize multiple things that may be animating. |
| 8784 | static final class DummyAnimation extends Animation { |
| 8785 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 8786 | return false; |
| 8787 | } |
| 8788 | } |
| 8789 | static final Animation sDummyAnimation = new DummyAnimation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8790 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8791 | // ------------------------------------------------------------- |
| 8792 | // Async Handler |
| 8793 | // ------------------------------------------------------------- |
| 8794 | |
| 8795 | static final class StartingData { |
| 8796 | final String pkg; |
| 8797 | final int theme; |
| 8798 | final CharSequence nonLocalizedLabel; |
| 8799 | final int labelRes; |
| 8800 | final int icon; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 8801 | final int windowFlags; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8802 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8803 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 8804 | int _labelRes, int _icon, int _windowFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8805 | pkg = _pkg; |
| 8806 | theme = _theme; |
| 8807 | nonLocalizedLabel = _nonLocalizedLabel; |
| 8808 | labelRes = _labelRes; |
| 8809 | icon = _icon; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 8810 | windowFlags = _windowFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8811 | } |
| 8812 | } |
| 8813 | |
| 8814 | private final class H extends Handler { |
| 8815 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 8816 | public static final int REPORT_LOSING_FOCUS = 3; |
| 8817 | public static final int ANIMATE = 4; |
| 8818 | public static final int ADD_STARTING = 5; |
| 8819 | public static final int REMOVE_STARTING = 6; |
| 8820 | public static final int FINISHED_STARTING = 7; |
| 8821 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8822 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 8823 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 8824 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 8825 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 8826 | public static final int FORCE_GC = 15; |
| 8827 | public static final int ENABLE_SCREEN = 16; |
| 8828 | public static final int APP_FREEZE_TIMEOUT = 17; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8829 | public static final int SEND_NEW_CONFIGURATION = 18; |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8830 | public static final int REPORT_WINDOWS_CHANGE = 19; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8831 | public static final int DRAG_START_TIMEOUT = 20; |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 8832 | public static final int DRAG_END_TIMEOUT = 21; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8833 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8834 | private Session mLastReportedHold; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8835 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8836 | public H() { |
| 8837 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8838 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8839 | @Override |
| 8840 | public void handleMessage(Message msg) { |
| 8841 | switch (msg.what) { |
| 8842 | case REPORT_FOCUS_CHANGE: { |
| 8843 | WindowState lastFocus; |
| 8844 | WindowState newFocus; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8845 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8846 | synchronized(mWindowMap) { |
| 8847 | lastFocus = mLastFocus; |
| 8848 | newFocus = mCurrentFocus; |
| 8849 | if (lastFocus == newFocus) { |
| 8850 | // Focus is not changing, so nothing to do. |
| 8851 | return; |
| 8852 | } |
| 8853 | mLastFocus = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8854 | //Slog.i(TAG, "Focus moving from " + lastFocus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8855 | // + " to " + newFocus); |
| 8856 | if (newFocus != null && lastFocus != null |
| 8857 | && !newFocus.isDisplayedLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8858 | //Slog.i(TAG, "Delaying loss of focus..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8859 | mLosingFocus.add(lastFocus); |
| 8860 | lastFocus = null; |
| 8861 | } |
| 8862 | } |
| 8863 | |
| 8864 | if (lastFocus != newFocus) { |
| 8865 | //System.out.println("Changing focus from " + lastFocus |
| 8866 | // + " to " + newFocus); |
| 8867 | if (newFocus != null) { |
| 8868 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8869 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8870 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 8871 | } catch (RemoteException e) { |
| 8872 | // Ignore if process has died. |
| 8873 | } |
Konstantin Lopyrev | 5e7833a | 2010-08-09 17:01:11 -0700 | [diff] [blame] | 8874 | notifyFocusChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8875 | } |
| 8876 | |
| 8877 | if (lastFocus != null) { |
| 8878 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8879 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8880 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 8881 | } catch (RemoteException e) { |
| 8882 | // Ignore if process has died. |
| 8883 | } |
| 8884 | } |
| 8885 | } |
| 8886 | } break; |
| 8887 | |
| 8888 | case REPORT_LOSING_FOCUS: { |
| 8889 | ArrayList<WindowState> losers; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8890 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8891 | synchronized(mWindowMap) { |
| 8892 | losers = mLosingFocus; |
| 8893 | mLosingFocus = new ArrayList<WindowState>(); |
| 8894 | } |
| 8895 | |
| 8896 | final int N = losers.size(); |
| 8897 | for (int i=0; i<N; i++) { |
| 8898 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8899 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8900 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 8901 | } catch (RemoteException e) { |
| 8902 | // Ignore if process has died. |
| 8903 | } |
| 8904 | } |
| 8905 | } break; |
| 8906 | |
| 8907 | case ANIMATE: { |
| 8908 | synchronized(mWindowMap) { |
| 8909 | mAnimationPending = false; |
| 8910 | performLayoutAndPlaceSurfacesLocked(); |
| 8911 | } |
| 8912 | } break; |
| 8913 | |
| 8914 | case ADD_STARTING: { |
| 8915 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8916 | final StartingData sd = wtoken.startingData; |
| 8917 | |
| 8918 | if (sd == null) { |
| 8919 | // Animation has been canceled... do nothing. |
| 8920 | return; |
| 8921 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8922 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8923 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8924 | + wtoken + ": pkg=" + sd.pkg); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8925 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8926 | View view = null; |
| 8927 | try { |
| 8928 | view = mPolicy.addStartingWindow( |
| 8929 | wtoken.token, sd.pkg, |
| 8930 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 8931 | sd.icon, sd.windowFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8932 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8933 | Slog.w(TAG, "Exception when adding starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8934 | } |
| 8935 | |
| 8936 | if (view != null) { |
| 8937 | boolean abort = false; |
| 8938 | |
| 8939 | synchronized(mWindowMap) { |
| 8940 | if (wtoken.removed || wtoken.startingData == null) { |
| 8941 | // If the window was successfully added, then |
| 8942 | // we need to remove it. |
| 8943 | if (wtoken.startingWindow != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8944 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8945 | "Aborted starting " + wtoken |
| 8946 | + ": removed=" + wtoken.removed |
| 8947 | + " startingData=" + wtoken.startingData); |
| 8948 | wtoken.startingWindow = null; |
| 8949 | wtoken.startingData = null; |
| 8950 | abort = true; |
| 8951 | } |
| 8952 | } else { |
| 8953 | wtoken.startingView = view; |
| 8954 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8955 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8956 | "Added starting " + wtoken |
| 8957 | + ": startingWindow=" |
| 8958 | + wtoken.startingWindow + " startingView=" |
| 8959 | + wtoken.startingView); |
| 8960 | } |
| 8961 | |
| 8962 | if (abort) { |
| 8963 | try { |
| 8964 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 8965 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8966 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8967 | } |
| 8968 | } |
| 8969 | } |
| 8970 | } break; |
| 8971 | |
| 8972 | case REMOVE_STARTING: { |
| 8973 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8974 | IBinder token = null; |
| 8975 | View view = null; |
| 8976 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8977 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8978 | + wtoken + ": startingWindow=" |
| 8979 | + wtoken.startingWindow + " startingView=" |
| 8980 | + wtoken.startingView); |
| 8981 | if (wtoken.startingWindow != null) { |
| 8982 | view = wtoken.startingView; |
| 8983 | token = wtoken.token; |
| 8984 | wtoken.startingData = null; |
| 8985 | wtoken.startingView = null; |
| 8986 | wtoken.startingWindow = null; |
| 8987 | } |
| 8988 | } |
| 8989 | if (view != null) { |
| 8990 | try { |
| 8991 | mPolicy.removeStartingWindow(token, view); |
| 8992 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8993 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8994 | } |
| 8995 | } |
| 8996 | } break; |
| 8997 | |
| 8998 | case FINISHED_STARTING: { |
| 8999 | IBinder token = null; |
| 9000 | View view = null; |
| 9001 | while (true) { |
| 9002 | synchronized (mWindowMap) { |
| 9003 | final int N = mFinishedStarting.size(); |
| 9004 | if (N <= 0) { |
| 9005 | break; |
| 9006 | } |
| 9007 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 9008 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9009 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9010 | "Finished starting " + wtoken |
| 9011 | + ": startingWindow=" + wtoken.startingWindow |
| 9012 | + " startingView=" + wtoken.startingView); |
| 9013 | |
| 9014 | if (wtoken.startingWindow == null) { |
| 9015 | continue; |
| 9016 | } |
| 9017 | |
| 9018 | view = wtoken.startingView; |
| 9019 | token = wtoken.token; |
| 9020 | wtoken.startingData = null; |
| 9021 | wtoken.startingView = null; |
| 9022 | wtoken.startingWindow = null; |
| 9023 | } |
| 9024 | |
| 9025 | try { |
| 9026 | mPolicy.removeStartingWindow(token, view); |
| 9027 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9028 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9029 | } |
| 9030 | } |
| 9031 | } break; |
| 9032 | |
| 9033 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 9034 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 9035 | |
| 9036 | boolean nowVisible = msg.arg1 != 0; |
| 9037 | boolean nowGone = msg.arg2 != 0; |
| 9038 | |
| 9039 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9040 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9041 | TAG, "Reporting visible in " + wtoken |
| 9042 | + " visible=" + nowVisible |
| 9043 | + " gone=" + nowGone); |
| 9044 | if (nowVisible) { |
| 9045 | wtoken.appToken.windowsVisible(); |
| 9046 | } else { |
| 9047 | wtoken.appToken.windowsGone(); |
| 9048 | } |
| 9049 | } catch (RemoteException ex) { |
| 9050 | } |
| 9051 | } break; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9052 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9053 | case WINDOW_FREEZE_TIMEOUT: { |
| 9054 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9055 | Slog.w(TAG, "Window freeze timeout expired."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9056 | int i = mWindows.size(); |
| 9057 | while (i > 0) { |
| 9058 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9059 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9060 | if (w.mOrientationChanging) { |
| 9061 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9062 | Slog.w(TAG, "Force clearing orientation change: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9063 | } |
| 9064 | } |
| 9065 | performLayoutAndPlaceSurfacesLocked(); |
| 9066 | } |
| 9067 | break; |
| 9068 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9069 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9070 | case HOLD_SCREEN_CHANGED: { |
| 9071 | Session oldHold; |
| 9072 | Session newHold; |
| 9073 | synchronized (mWindowMap) { |
| 9074 | oldHold = mLastReportedHold; |
| 9075 | newHold = (Session)msg.obj; |
| 9076 | mLastReportedHold = newHold; |
| 9077 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9078 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9079 | if (oldHold != newHold) { |
| 9080 | try { |
| 9081 | if (oldHold != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9082 | mBatteryStats.noteStopWakelock(oldHold.mUid, -1, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9083 | "window", |
| 9084 | BatteryStats.WAKE_TYPE_WINDOW); |
| 9085 | } |
| 9086 | if (newHold != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9087 | mBatteryStats.noteStartWakelock(newHold.mUid, -1, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9088 | "window", |
| 9089 | BatteryStats.WAKE_TYPE_WINDOW); |
| 9090 | } |
| 9091 | } catch (RemoteException e) { |
| 9092 | } |
| 9093 | } |
| 9094 | break; |
| 9095 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9096 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9097 | case APP_TRANSITION_TIMEOUT: { |
| 9098 | synchronized (mWindowMap) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9099 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9100 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9101 | "*** APP TRANSITION TIMEOUT"); |
| 9102 | mAppTransitionReady = true; |
| 9103 | mAppTransitionTimeout = true; |
| 9104 | performLayoutAndPlaceSurfacesLocked(); |
| 9105 | } |
| 9106 | } |
| 9107 | break; |
| 9108 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9109 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9110 | case PERSIST_ANIMATION_SCALE: { |
| 9111 | Settings.System.putFloat(mContext.getContentResolver(), |
| 9112 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 9113 | Settings.System.putFloat(mContext.getContentResolver(), |
| 9114 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 9115 | break; |
| 9116 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9117 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9118 | case FORCE_GC: { |
| 9119 | synchronized(mWindowMap) { |
| 9120 | if (mAnimationPending) { |
| 9121 | // If we are animating, don't do the gc now but |
| 9122 | // delay a bit so we don't interrupt the animation. |
| 9123 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 9124 | 2000); |
| 9125 | return; |
| 9126 | } |
| 9127 | // If we are currently rotating the display, it will |
| 9128 | // schedule a new message when done. |
| 9129 | if (mDisplayFrozen) { |
| 9130 | return; |
| 9131 | } |
| 9132 | mFreezeGcPending = 0; |
| 9133 | } |
| 9134 | Runtime.getRuntime().gc(); |
| 9135 | break; |
| 9136 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9137 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9138 | case ENABLE_SCREEN: { |
| 9139 | performEnableScreen(); |
| 9140 | break; |
| 9141 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9142 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9143 | case APP_FREEZE_TIMEOUT: { |
| 9144 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9145 | Slog.w(TAG, "App freeze timeout expired."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9146 | int i = mAppTokens.size(); |
| 9147 | while (i > 0) { |
| 9148 | i--; |
| 9149 | AppWindowToken tok = mAppTokens.get(i); |
| 9150 | if (tok.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9151 | Slog.w(TAG, "Force clearing freeze: " + tok); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9152 | unsetAppFreezingScreenLocked(tok, true, true); |
| 9153 | } |
| 9154 | } |
| 9155 | } |
| 9156 | break; |
| 9157 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9158 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9159 | case SEND_NEW_CONFIGURATION: { |
| 9160 | removeMessages(SEND_NEW_CONFIGURATION); |
| 9161 | sendNewConfiguration(); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 9162 | break; |
| 9163 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9164 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 9165 | case REPORT_WINDOWS_CHANGE: { |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 9166 | if (mWindowsChanged) { |
| 9167 | synchronized (mWindowMap) { |
| 9168 | mWindowsChanged = false; |
| 9169 | } |
| 9170 | notifyWindowsChanged(); |
| 9171 | } |
| 9172 | break; |
| 9173 | } |
| 9174 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 9175 | case DRAG_START_TIMEOUT: { |
| 9176 | IBinder win = (IBinder)msg.obj; |
| 9177 | if (DEBUG_DRAG) { |
| 9178 | Slog.w(TAG, "Timeout starting drag by win " + win); |
| 9179 | } |
| 9180 | synchronized (mWindowMap) { |
| 9181 | // !!! TODO: ANR the app that has failed to start the drag in time |
| 9182 | if (mDragState != null) { |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 9183 | mDragState.unregister(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9184 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 9185 | mInputMonitor.updateInputWindowsLw(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 9186 | mDragState.reset(); |
| 9187 | mDragState = null; |
| 9188 | } |
| 9189 | } |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 9190 | break; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 9191 | } |
| 9192 | |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 9193 | case DRAG_END_TIMEOUT: { |
| 9194 | IBinder win = (IBinder)msg.obj; |
| 9195 | if (DEBUG_DRAG) { |
| 9196 | Slog.w(TAG, "Timeout ending drag to win " + win); |
| 9197 | } |
| 9198 | synchronized (mWindowMap) { |
| 9199 | // !!! TODO: ANR the drag-receiving app |
| 9200 | mDragState.mDragResult = false; |
| 9201 | mDragState.endDragLw(); |
| 9202 | } |
| 9203 | break; |
| 9204 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9205 | } |
| 9206 | } |
| 9207 | } |
| 9208 | |
| 9209 | // ------------------------------------------------------------- |
| 9210 | // IWindowManager API |
| 9211 | // ------------------------------------------------------------- |
| 9212 | |
| 9213 | public IWindowSession openSession(IInputMethodClient client, |
| 9214 | IInputContext inputContext) { |
| 9215 | if (client == null) throw new IllegalArgumentException("null client"); |
| 9216 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 9217 | Session session = new Session(client, inputContext); |
| 9218 | return session; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9219 | } |
| 9220 | |
| 9221 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 9222 | synchronized (mWindowMap) { |
| 9223 | // The focus for the client is the window immediately below |
| 9224 | // where we would place the input method window. |
| 9225 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 9226 | WindowState imFocus; |
| 9227 | if (idx > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9228 | imFocus = mWindows.get(idx-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9229 | if (imFocus != null) { |
| 9230 | if (imFocus.mSession.mClient != null && |
| 9231 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 9232 | return true; |
| 9233 | } |
| 9234 | } |
| 9235 | } |
| 9236 | } |
| 9237 | return false; |
| 9238 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9239 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9240 | // ------------------------------------------------------------- |
| 9241 | // Internals |
| 9242 | // ------------------------------------------------------------- |
| 9243 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9244 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 9245 | boolean throwOnError) { |
| 9246 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9247 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9248 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9249 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 9250 | boolean throwOnError) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9251 | WindowState win = mWindowMap.get(client); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9252 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9253 | TAG, "Looking up client " + client + ": " + win); |
| 9254 | if (win == null) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9255 | RuntimeException ex = new IllegalArgumentException( |
| 9256 | "Requested window " + client + " does not exist"); |
| 9257 | if (throwOnError) { |
| 9258 | throw ex; |
| 9259 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9260 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9261 | return null; |
| 9262 | } |
| 9263 | if (session != null && win.mSession != session) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9264 | RuntimeException ex = new IllegalArgumentException( |
| 9265 | "Requested window " + client + " is in session " + |
| 9266 | win.mSession + ", not " + session); |
| 9267 | if (throwOnError) { |
| 9268 | throw ex; |
| 9269 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9270 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9271 | return null; |
| 9272 | } |
| 9273 | |
| 9274 | return win; |
| 9275 | } |
| 9276 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9277 | final void rebuildAppWindowListLocked() { |
| 9278 | int NW = mWindows.size(); |
| 9279 | int i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9280 | int lastWallpaper = -1; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9281 | int numRemoved = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9282 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9283 | if (mRebuildTmp.length < NW) { |
| 9284 | mRebuildTmp = new WindowState[NW+10]; |
| 9285 | } |
| 9286 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9287 | // First remove all existing app windows. |
| 9288 | i=0; |
| 9289 | while (i < NW) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9290 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9291 | if (w.mAppToken != null) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9292 | WindowState win = mWindows.remove(i); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9293 | win.mRebuilding = true; |
| 9294 | mRebuildTmp[numRemoved] = win; |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 9295 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9296 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9297 | "Rebuild removing window: " + win); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9298 | NW--; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9299 | numRemoved++; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9300 | continue; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9301 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 9302 | && lastWallpaper == i-1) { |
| 9303 | lastWallpaper = i; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9304 | } |
| 9305 | i++; |
| 9306 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9307 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9308 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 9309 | // so skip them before adding app tokens. |
| 9310 | lastWallpaper++; |
| 9311 | i = lastWallpaper; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9312 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9313 | // First add all of the exiting app tokens... these are no longer |
| 9314 | // in the main app list, but still have windows shown. We put them |
| 9315 | // in the back because now that the animation is over we no longer |
| 9316 | // will care about them. |
| 9317 | int NT = mExitingAppTokens.size(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9318 | for (int j=0; j<NT; j++) { |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9319 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 9320 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9321 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9322 | // And add in the still active app tokens in Z order. |
| 9323 | NT = mAppTokens.size(); |
| 9324 | for (int j=0; j<NT; j++) { |
| 9325 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9326 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9327 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9328 | i -= lastWallpaper; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9329 | if (i != numRemoved) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9330 | Slog.w(TAG, "Rebuild removed " + numRemoved |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9331 | + " windows but added " + i); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9332 | for (i=0; i<numRemoved; i++) { |
| 9333 | WindowState ws = mRebuildTmp[i]; |
| 9334 | if (ws.mRebuilding) { |
| 9335 | StringWriter sw = new StringWriter(); |
| 9336 | PrintWriter pw = new PrintWriter(sw); |
| 9337 | ws.dump(pw, ""); |
| 9338 | pw.flush(); |
| 9339 | Slog.w(TAG, "This window was lost: " + ws); |
| 9340 | Slog.w(TAG, sw.toString()); |
| 9341 | } |
| 9342 | } |
| 9343 | Slog.w(TAG, "Current app token list:"); |
| 9344 | dumpAppTokensLocked(); |
| 9345 | Slog.w(TAG, "Final window list:"); |
| 9346 | dumpWindowsLocked(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9347 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9348 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9349 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9350 | private final void assignLayersLocked() { |
| 9351 | int N = mWindows.size(); |
| 9352 | int curBaseLayer = 0; |
| 9353 | int curLayer = 0; |
| 9354 | int i; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9355 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9356 | if (DEBUG_LAYERS) { |
| 9357 | RuntimeException here = new RuntimeException("here"); |
| 9358 | here.fillInStackTrace(); |
| 9359 | Log.v(TAG, "Assigning layers", here); |
| 9360 | } |
| 9361 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9362 | for (i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9363 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9364 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 9365 | || (i > 0 && w.mIsWallpaper)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9366 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 9367 | w.mLayer = curLayer; |
| 9368 | } else { |
| 9369 | curBaseLayer = curLayer = w.mBaseLayer; |
| 9370 | w.mLayer = curLayer; |
| 9371 | } |
| 9372 | if (w.mTargetAppToken != null) { |
| 9373 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 9374 | } else if (w.mAppToken != null) { |
| 9375 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 9376 | } else { |
| 9377 | w.mAnimLayer = w.mLayer; |
| 9378 | } |
| 9379 | if (w.mIsImWindow) { |
| 9380 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 9381 | } else if (w.mIsWallpaper) { |
| 9382 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9383 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9384 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9385 | + w.mAnimLayer); |
| 9386 | //System.out.println( |
| 9387 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 9388 | } |
| 9389 | } |
| 9390 | |
| 9391 | private boolean mInLayout = false; |
| 9392 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 9393 | if (mInLayout) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 9394 | if (DEBUG) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9395 | throw new RuntimeException("Recursive call!"); |
| 9396 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9397 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9398 | return; |
| 9399 | } |
| 9400 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9401 | if (mWaitingForConfig) { |
| 9402 | // Our configuration has changed (most likely rotation), but we |
| 9403 | // don't yet have the complete configuration to report to |
| 9404 | // applications. Don't do any window layout until we have it. |
| 9405 | return; |
| 9406 | } |
| 9407 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9408 | if (mDisplay == null) { |
| 9409 | // Not yet initialized, nothing to do. |
| 9410 | return; |
| 9411 | } |
| 9412 | |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 9413 | mInLayout = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9414 | boolean recoveringMemory = false; |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 9415 | |
| 9416 | try { |
| 9417 | if (mForceRemoves != null) { |
| 9418 | recoveringMemory = true; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9419 | // 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] | 9420 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 9421 | WindowState ws = mForceRemoves.get(i); |
| 9422 | Slog.i(TAG, "Force removing: " + ws); |
| 9423 | removeWindowInnerLocked(ws.mSession, ws); |
| 9424 | } |
| 9425 | mForceRemoves = null; |
| 9426 | Slog.w(TAG, "Due to memory failure, waiting a bit for next layout"); |
| 9427 | Object tmp = new Object(); |
| 9428 | synchronized (tmp) { |
| 9429 | try { |
| 9430 | tmp.wait(250); |
| 9431 | } catch (InterruptedException e) { |
| 9432 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9433 | } |
| 9434 | } |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 9435 | } catch (RuntimeException e) { |
| 9436 | 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] | 9437 | } |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 9438 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9439 | try { |
| 9440 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9441 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9442 | int N = mPendingRemove.size(); |
| 9443 | if (N > 0) { |
| 9444 | if (mPendingRemoveTmp.length < N) { |
| 9445 | mPendingRemoveTmp = new WindowState[N+10]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9446 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9447 | mPendingRemove.toArray(mPendingRemoveTmp); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9448 | mPendingRemove.clear(); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9449 | for (int i=0; i<N; i++) { |
| 9450 | WindowState w = mPendingRemoveTmp[i]; |
| 9451 | removeWindowInnerLocked(w.mSession, w); |
| 9452 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9453 | |
| 9454 | mInLayout = false; |
| 9455 | assignLayersLocked(); |
| 9456 | mLayoutNeeded = true; |
| 9457 | performLayoutAndPlaceSurfacesLocked(); |
| 9458 | |
| 9459 | } else { |
| 9460 | mInLayout = false; |
| 9461 | if (mLayoutNeeded) { |
| 9462 | requestAnimationLocked(0); |
| 9463 | } |
| 9464 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 9465 | if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) { |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 9466 | mH.removeMessages(H.REPORT_WINDOWS_CHANGE); |
| 9467 | mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE)); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 9468 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9469 | } catch (RuntimeException e) { |
| 9470 | mInLayout = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9471 | 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] | 9472 | } |
| 9473 | } |
| 9474 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9475 | private final int performLayoutLockedInner(boolean initial, boolean updateInputWindows) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9476 | if (!mLayoutNeeded) { |
| 9477 | return 0; |
| 9478 | } |
| 9479 | |
| 9480 | mLayoutNeeded = false; |
| 9481 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9482 | final int dw = mDisplay.getWidth(); |
| 9483 | final int dh = mDisplay.getHeight(); |
| 9484 | |
| 9485 | final int N = mWindows.size(); |
| 9486 | int i; |
| 9487 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9488 | if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed=" |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 9489 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 9490 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9491 | mPolicy.beginLayoutLw(dw, dh); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9492 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9493 | int seq = mLayoutSeq+1; |
| 9494 | if (seq < 0) seq = 0; |
| 9495 | mLayoutSeq = seq; |
| 9496 | |
| 9497 | // First perform layout of any root windows (not attached |
| 9498 | // to another window). |
| 9499 | int topAttached = -1; |
| 9500 | for (i = N-1; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9501 | WindowState win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9502 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9503 | // Don't do layout of a window if it is not visible, or |
| 9504 | // soon won't be visible, to avoid wasting time and funky |
| 9505 | // changes while a window is animating away. |
| 9506 | final AppWindowToken atoken = win.mAppToken; |
| 9507 | final boolean gone = win.mViewVisibility == View.GONE |
| 9508 | || !win.mRelayoutCalled |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 9509 | || (atoken == null && win.mRootToken.hidden) |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9510 | || (atoken != null && atoken.hiddenRequested) |
| 9511 | || win.mAttachedHidden |
| 9512 | || win.mExiting || win.mDestroying; |
| 9513 | |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 9514 | if (DEBUG_LAYOUT && !win.mLayoutAttached) { |
| 9515 | Slog.v(TAG, "First pass " + win |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9516 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 9517 | + " mLayoutAttached=" + win.mLayoutAttached); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 9518 | if (gone) Slog.v(TAG, " (mViewVisibility=" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9519 | + win.mViewVisibility + " mRelayoutCalled=" |
| 9520 | + win.mRelayoutCalled + " hidden=" |
| 9521 | + win.mRootToken.hidden + " hiddenRequested=" |
| 9522 | + (atoken != null && atoken.hiddenRequested) |
| 9523 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 9524 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9525 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9526 | // If this view is GONE, then skip it -- keep the current |
| 9527 | // frame, and let the caller know so they can ignore it |
| 9528 | // if they want. (We do the normal layout for INVISIBLE |
| 9529 | // windows, since that means "perform layout as normal, |
| 9530 | // just don't display"). |
| 9531 | if (!gone || !win.mHaveFrame) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9532 | if (!win.mLayoutAttached) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9533 | if (initial) { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 9534 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9535 | win.mContentChanged = false; |
| 9536 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9537 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 9538 | win.mLayoutSeq = seq; |
| 9539 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 9540 | + win.mFrame + " mContainingFrame=" |
| 9541 | + win.mContainingFrame + " mDisplayFrame=" |
| 9542 | + win.mDisplayFrame); |
| 9543 | } else { |
| 9544 | if (topAttached < 0) topAttached = i; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9545 | } |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9546 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9547 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9548 | |
| 9549 | // Now perform layout of attached windows, which usually |
| 9550 | // depend on the position of the window they are attached to. |
| 9551 | // XXX does not deal with windows that are attached to windows |
| 9552 | // that are themselves attached. |
| 9553 | for (i = topAttached; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9554 | WindowState win = mWindows.get(i); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9555 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9556 | if (win.mLayoutAttached) { |
| 9557 | if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win |
| 9558 | + " mHaveFrame=" + win.mHaveFrame |
| 9559 | + " mViewVisibility=" + win.mViewVisibility |
| 9560 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 9561 | // If this view is GONE, then skip it -- keep the current |
| 9562 | // frame, and let the caller know so they can ignore it |
| 9563 | // if they want. (We do the normal layout for INVISIBLE |
| 9564 | // windows, since that means "perform layout as normal, |
| 9565 | // just don't display"). |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9566 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 9567 | || !win.mHaveFrame) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9568 | if (initial) { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 9569 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9570 | win.mContentChanged = false; |
| 9571 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9572 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 9573 | win.mLayoutSeq = seq; |
| 9574 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 9575 | + win.mFrame + " mContainingFrame=" |
| 9576 | + win.mContainingFrame + " mDisplayFrame=" |
| 9577 | + win.mDisplayFrame); |
| 9578 | } |
| 9579 | } |
| 9580 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9581 | |
| 9582 | // Window frames may have changed. Tell the input dispatcher about it. |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9583 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 9584 | if (updateInputWindows) { |
| 9585 | mInputMonitor.updateInputWindowsLw(); |
| 9586 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9587 | |
| 9588 | return mPolicy.finishLayoutLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9589 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9590 | |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 9591 | // "Something has changed! Let's make it correct now." |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9592 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 9593 | boolean recoveringMemory) { |
Joe Onorato | 34bcebc | 2010-07-07 18:05:01 -0400 | [diff] [blame] | 9594 | if (mDisplay == null) { |
| 9595 | Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay"); |
| 9596 | return; |
| 9597 | } |
| 9598 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9599 | final long currentTime = SystemClock.uptimeMillis(); |
| 9600 | final int dw = mDisplay.getWidth(); |
| 9601 | final int dh = mDisplay.getHeight(); |
| 9602 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9603 | int i; |
| 9604 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9605 | if (mFocusMayChange) { |
| 9606 | mFocusMayChange = false; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9607 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 9608 | false /*updateInputWindows*/); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9609 | } |
| 9610 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9611 | // Initialize state of exiting tokens. |
| 9612 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9613 | mExitingTokens.get(i).hasVisible = false; |
| 9614 | } |
| 9615 | |
| 9616 | // Initialize state of exiting applications. |
| 9617 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9618 | mExitingAppTokens.get(i).hasVisible = false; |
| 9619 | } |
| 9620 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9621 | boolean orientationChangeComplete = true; |
| 9622 | Session holdScreen = null; |
| 9623 | float screenBrightness = -1; |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9624 | float buttonBrightness = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9625 | boolean focusDisplayed = false; |
| 9626 | boolean animating = false; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9627 | boolean createWatermark = false; |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame^] | 9628 | boolean updateRotation = false; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9629 | |
| 9630 | if (mFxSession == null) { |
| 9631 | mFxSession = new SurfaceSession(); |
| 9632 | createWatermark = true; |
| 9633 | } |
| 9634 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 9635 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9636 | |
| 9637 | Surface.openTransaction(); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9638 | |
| 9639 | if (createWatermark) { |
| 9640 | createWatermark(); |
| 9641 | } |
| 9642 | if (mWatermark != null) { |
| 9643 | mWatermark.positionSurface(dw, dh); |
| 9644 | } |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 9645 | if (mStrictModeFlash != null) { |
| 9646 | mStrictModeFlash.positionSurface(dw, dh); |
| 9647 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9648 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9649 | try { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9650 | boolean wallpaperForceHidingChanged = false; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9651 | int repeats = 0; |
| 9652 | int changes = 0; |
| 9653 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9654 | do { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9655 | repeats++; |
| 9656 | if (repeats > 6) { |
| 9657 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 9658 | mLayoutNeeded = false; |
| 9659 | break; |
| 9660 | } |
| 9661 | |
| 9662 | if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER |
| 9663 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG |
| 9664 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) { |
| 9665 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 9666 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 9667 | assignLayersLocked(); |
| 9668 | mLayoutNeeded = true; |
| 9669 | } |
| 9670 | } |
| 9671 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 9672 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 9673 | if (updateOrientationFromAppTokensLocked(true)) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9674 | mLayoutNeeded = true; |
| 9675 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 9676 | } |
| 9677 | } |
| 9678 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 9679 | mLayoutNeeded = true; |
| 9680 | } |
| 9681 | } |
| 9682 | |
| 9683 | // FIRST LOOP: Perform a layout, if needed. |
| 9684 | if (repeats < 4) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9685 | changes = performLayoutLockedInner(repeats == 0, false /*updateInputWindows*/); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9686 | if (changes != 0) { |
| 9687 | continue; |
| 9688 | } |
| 9689 | } else { |
| 9690 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 9691 | changes = 0; |
| 9692 | } |
| 9693 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9694 | final int transactionSequence = ++mTransactionSequence; |
| 9695 | |
| 9696 | // Update animations of all applications, including those |
| 9697 | // associated with exiting/removed apps |
| 9698 | boolean tokensAnimating = false; |
| 9699 | final int NAT = mAppTokens.size(); |
| 9700 | for (i=0; i<NAT; i++) { |
| 9701 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9702 | tokensAnimating = true; |
| 9703 | } |
| 9704 | } |
| 9705 | final int NEAT = mExitingAppTokens.size(); |
| 9706 | for (i=0; i<NEAT; i++) { |
| 9707 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9708 | tokensAnimating = true; |
| 9709 | } |
| 9710 | } |
| 9711 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9712 | // SECOND LOOP: Execute animations and update visibility of windows. |
| 9713 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9714 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq=" |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9715 | + transactionSequence + " tokensAnimating=" |
| 9716 | + tokensAnimating); |
| 9717 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9718 | animating = tokensAnimating; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9719 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 9720 | if (mScreenRotationAnimation != null) { |
| 9721 | if (mScreenRotationAnimation.isAnimating()) { |
| 9722 | if (mScreenRotationAnimation.stepAnimation(currentTime)) { |
| 9723 | animating = true; |
| 9724 | } else { |
| 9725 | mScreenRotationAnimation = null; |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame^] | 9726 | updateRotation = true; |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 9727 | } |
| 9728 | } |
| 9729 | } |
| 9730 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9731 | boolean tokenMayBeDrawn = false; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9732 | boolean wallpaperMayChange = false; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9733 | boolean forceHiding = false; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9734 | WindowState windowDetachedWallpaper = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9735 | |
| 9736 | mPolicy.beginAnimationLw(dw, dh); |
| 9737 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9738 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9739 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9740 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9741 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9742 | |
| 9743 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9744 | |
| 9745 | if (w.mSurface != null) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9746 | // Take care of the window being ready to display. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9747 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 9748 | if ((w.mAttrs.flags |
| 9749 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9750 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9751 | "First draw done in potential wallpaper target " + w); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9752 | wallpaperMayChange = true; |
| 9753 | } |
| 9754 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9755 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9756 | final boolean wasAnimating = w.mAnimating; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9757 | |
| 9758 | int animDw = dw; |
| 9759 | int animDh = dh; |
| 9760 | |
| 9761 | // If the window has moved due to its containing |
| 9762 | // content frame changing, then we'd like to animate |
| 9763 | // it. The checks here are ordered by what is least |
Joe Onorato | 3fe7f2f | 2010-11-20 13:48:58 -0800 | [diff] [blame] | 9764 | // likely to be true first. |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 9765 | if (w.shouldAnimateMove()) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9766 | // Frame has moved, containing content frame |
| 9767 | // has also moved, and we're not currently animating... |
| 9768 | // let's do something. |
| 9769 | Animation a = AnimationUtils.loadAnimation(mContext, |
| 9770 | com.android.internal.R.anim.window_move_from_decor); |
| 9771 | w.setAnimation(a); |
| 9772 | animDw = w.mLastFrame.left - w.mFrame.left; |
| 9773 | animDh = w.mLastFrame.top - w.mFrame.top; |
| 9774 | } |
| 9775 | |
| 9776 | // Execute animation. |
| 9777 | final boolean nowAnimating = w.stepAnimationLocked(currentTime, |
| 9778 | animDw, animDh); |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9779 | |
| 9780 | // If this window is animating, make a note that we have |
| 9781 | // an animating window and take care of a request to run |
| 9782 | // a detached wallpaper animation. |
| 9783 | if (nowAnimating) { |
| 9784 | if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) { |
| 9785 | windowDetachedWallpaper = w; |
| 9786 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9787 | animating = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9788 | } |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9789 | |
| 9790 | // If this window's app token is running a detached wallpaper |
| 9791 | // animation, make a note so we can ensure the wallpaper is |
| 9792 | // displayed behind it. |
| 9793 | if (w.mAppToken != null && w.mAppToken.animation != null |
| 9794 | && w.mAppToken.animation.getDetachWallpaper()) { |
| 9795 | windowDetachedWallpaper = w; |
| 9796 | } |
| 9797 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9798 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 9799 | wallpaperMayChange = true; |
| 9800 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9801 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9802 | if (mPolicy.doesForceHide(w, attrs)) { |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9803 | if (!wasAnimating && nowAnimating) { |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9804 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9805 | "Animation started that could impact force hide: " |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9806 | + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9807 | wallpaperForceHidingChanged = true; |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9808 | mFocusMayChange = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9809 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 9810 | forceHiding = true; |
| 9811 | } |
| 9812 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9813 | boolean changed; |
| 9814 | if (forceHiding) { |
| 9815 | changed = w.hideLw(false, false); |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9816 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9817 | "Now policy hidden: " + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9818 | } else { |
| 9819 | changed = w.showLw(false, false); |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9820 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9821 | "Now policy shown: " + w); |
| 9822 | if (changed) { |
| 9823 | if (wallpaperForceHidingChanged |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9824 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9825 | // Assume we will need to animate. If |
| 9826 | // we don't (because the wallpaper will |
| 9827 | // stay with the lock screen), then we will |
| 9828 | // clean up later. |
| 9829 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 9830 | if (a != null) { |
| 9831 | w.setAnimation(a); |
| 9832 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9833 | } |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9834 | if (mCurrentFocus == null || |
| 9835 | mCurrentFocus.mLayer < w.mLayer) { |
| 9836 | // We are showing on to of the current |
| 9837 | // focus, so re-evaluate focus to make |
| 9838 | // sure it is correct. |
| 9839 | mFocusMayChange = true; |
| 9840 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9841 | } |
| 9842 | } |
| 9843 | if (changed && (attrs.flags |
| 9844 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 9845 | wallpaperMayChange = true; |
| 9846 | } |
| 9847 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9848 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9849 | mPolicy.animatingWindowLw(w, attrs); |
| 9850 | } |
| 9851 | |
| 9852 | final AppWindowToken atoken = w.mAppToken; |
| 9853 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 9854 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 9855 | atoken.lastTransactionSequence = transactionSequence; |
| 9856 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 9857 | atoken.startingDisplayed = false; |
| 9858 | } |
| 9859 | if ((w.isOnScreen() || w.mAttrs.type |
| 9860 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 9861 | && !w.mExiting && !w.mDestroying) { |
| 9862 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9863 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9864 | + w.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9865 | + ", isAnimating=" + w.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9866 | if (!w.isDrawnLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9867 | Slog.v(TAG, "Not displayed: s=" + w.mSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9868 | + " pv=" + w.mPolicyVisibility |
| 9869 | + " dp=" + w.mDrawPending |
| 9870 | + " cdp=" + w.mCommitDrawPending |
| 9871 | + " ah=" + w.mAttachedHidden |
| 9872 | + " th=" + atoken.hiddenRequested |
| 9873 | + " a=" + w.mAnimating); |
| 9874 | } |
| 9875 | } |
| 9876 | if (w != atoken.startingWindow) { |
| 9877 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 9878 | atoken.numInterestingWindows++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9879 | if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9880 | atoken.numDrawnWindows++; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9881 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9882 | "tokenMayBeDrawn: " + atoken |
| 9883 | + " freezingScreen=" + atoken.freezingScreen |
| 9884 | + " mAppFreezing=" + w.mAppFreezing); |
| 9885 | tokenMayBeDrawn = true; |
| 9886 | } |
| 9887 | } |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9888 | } else if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9889 | atoken.startingDisplayed = true; |
| 9890 | } |
| 9891 | } |
| 9892 | } else if (w.mReadyToShow) { |
| 9893 | w.performShowLocked(); |
| 9894 | } |
| 9895 | } |
| 9896 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9897 | changes |= mPolicy.finishAnimationLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9898 | |
| 9899 | if (tokenMayBeDrawn) { |
| 9900 | // See if any windows have been drawn, so they (and others |
| 9901 | // associated with them) can now be shown. |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9902 | final int NT = mAppTokens.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9903 | for (i=0; i<NT; i++) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9904 | AppWindowToken wtoken = mAppTokens.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9905 | if (wtoken.freezingScreen) { |
| 9906 | int numInteresting = wtoken.numInterestingWindows; |
| 9907 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9908 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9909 | "allDrawn: " + wtoken |
| 9910 | + " interesting=" + numInteresting |
| 9911 | + " drawn=" + wtoken.numDrawnWindows); |
| 9912 | wtoken.showAllWindowsLocked(); |
| 9913 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 9914 | orientationChangeComplete = true; |
| 9915 | } |
| 9916 | } else if (!wtoken.allDrawn) { |
| 9917 | int numInteresting = wtoken.numInterestingWindows; |
| 9918 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9919 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9920 | "allDrawn: " + wtoken |
| 9921 | + " interesting=" + numInteresting |
| 9922 | + " drawn=" + wtoken.numDrawnWindows); |
| 9923 | wtoken.allDrawn = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9924 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9925 | |
| 9926 | // We can now show all of the drawn windows! |
| 9927 | if (!mOpeningApps.contains(wtoken)) { |
| 9928 | wtoken.showAllWindowsLocked(); |
| 9929 | } |
| 9930 | } |
| 9931 | } |
| 9932 | } |
| 9933 | } |
| 9934 | |
| 9935 | // If we are ready to perform an app transition, check through |
| 9936 | // all of the app tokens to be shown and see if they are ready |
| 9937 | // to go. |
| 9938 | if (mAppTransitionReady) { |
| 9939 | int NN = mOpeningApps.size(); |
| 9940 | boolean goodToGo = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9941 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9942 | "Checking " + NN + " opening apps (frozen=" |
| 9943 | + mDisplayFrozen + " timeout=" |
| 9944 | + mAppTransitionTimeout + ")..."); |
| 9945 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 9946 | // If the display isn't frozen, wait to do anything until |
| 9947 | // all of the apps are ready. Otherwise just go because |
| 9948 | // we'll unfreeze the display when everyone is ready. |
| 9949 | for (i=0; i<NN && goodToGo; i++) { |
| 9950 | AppWindowToken wtoken = mOpeningApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9951 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9952 | "Check opening app" + wtoken + ": allDrawn=" |
| 9953 | + wtoken.allDrawn + " startingDisplayed=" |
| 9954 | + wtoken.startingDisplayed); |
| 9955 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 9956 | && !wtoken.startingMoved) { |
| 9957 | goodToGo = false; |
| 9958 | } |
| 9959 | } |
| 9960 | } |
| 9961 | if (goodToGo) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9962 | 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] | 9963 | int transit = mNextAppTransition; |
| 9964 | if (mSkipAppTransitionAnimation) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9965 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9966 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9967 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9968 | mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9969 | mAppTransitionRunning = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9970 | mAppTransitionTimeout = false; |
| 9971 | mStartingIconInTransition = false; |
| 9972 | mSkipAppTransitionAnimation = false; |
| 9973 | |
| 9974 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 9975 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9976 | // If there are applications waiting to come to the |
| 9977 | // top of the stack, now is the time to move their windows. |
| 9978 | // (Note that we don't do apps going to the bottom |
| 9979 | // here -- we want to keep their windows in the old |
| 9980 | // Z-order until the animation completes.) |
| 9981 | if (mToTopApps.size() > 0) { |
| 9982 | NN = mAppTokens.size(); |
| 9983 | for (i=0; i<NN; i++) { |
| 9984 | AppWindowToken wtoken = mAppTokens.get(i); |
| 9985 | if (wtoken.sendingToTop) { |
| 9986 | wtoken.sendingToTop = false; |
| 9987 | moveAppWindowsLocked(wtoken, NN, false); |
| 9988 | } |
| 9989 | } |
| 9990 | mToTopApps.clear(); |
| 9991 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9992 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9993 | WindowState oldWallpaper = mWallpaperTarget; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9994 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9995 | adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9996 | wallpaperMayChange = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9997 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9998 | // The top-most window will supply the layout params, |
| 9999 | // and we will determine it below. |
| 10000 | LayoutParams animLp = null; |
| 10001 | int bestAnimLayer = -1; |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 10002 | boolean fullscreenAnim = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10003 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10004 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 10005 | "New wallpaper target=" + mWallpaperTarget |
| 10006 | + ", lower target=" + mLowerWallpaperTarget |
| 10007 | + ", upper target=" + mUpperWallpaperTarget); |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10008 | int foundWallpapers = 0; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10009 | // Do a first pass through the tokens for two |
| 10010 | // things: |
| 10011 | // (1) Determine if both the closing and opening |
| 10012 | // app token sets are wallpaper targets, in which |
| 10013 | // case special animations are needed |
| 10014 | // (since the wallpaper needs to stay static |
| 10015 | // behind them). |
| 10016 | // (2) Find the layout params of the top-most |
| 10017 | // application window in the tokens, which is |
| 10018 | // what will control the animation theme. |
| 10019 | final int NC = mClosingApps.size(); |
| 10020 | NN = NC + mOpeningApps.size(); |
| 10021 | for (i=0; i<NN; i++) { |
| 10022 | AppWindowToken wtoken; |
| 10023 | int mode; |
| 10024 | if (i < NC) { |
| 10025 | wtoken = mClosingApps.get(i); |
| 10026 | mode = 1; |
| 10027 | } else { |
| 10028 | wtoken = mOpeningApps.get(i-NC); |
| 10029 | mode = 2; |
| 10030 | } |
| 10031 | if (mLowerWallpaperTarget != null) { |
| 10032 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 10033 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 10034 | foundWallpapers |= mode; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 10035 | } |
| 10036 | } |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10037 | if (wtoken.appFullscreen) { |
| 10038 | WindowState ws = wtoken.findMainWindow(); |
| 10039 | if (ws != null) { |
| 10040 | // If this is a compatibility mode |
| 10041 | // window, we will always use its anim. |
| 10042 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 10043 | animLp = ws.mAttrs; |
| 10044 | bestAnimLayer = Integer.MAX_VALUE; |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 10045 | } else if (!fullscreenAnim || ws.mLayer > bestAnimLayer) { |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10046 | animLp = ws.mAttrs; |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 10047 | bestAnimLayer = ws.mLayer; |
| 10048 | } |
| 10049 | fullscreenAnim = true; |
| 10050 | } |
| 10051 | } else if (!fullscreenAnim) { |
| 10052 | WindowState ws = wtoken.findMainWindow(); |
| 10053 | if (ws != null) { |
| 10054 | if (ws.mLayer > bestAnimLayer) { |
| 10055 | animLp = ws.mAttrs; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10056 | bestAnimLayer = ws.mLayer; |
| 10057 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10058 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 10059 | } |
| 10060 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10061 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10062 | if (foundWallpapers == 3) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10063 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10064 | "Wallpaper animation!"); |
| 10065 | switch (transit) { |
| 10066 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 10067 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 10068 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 10069 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 10070 | break; |
| 10071 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 10072 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 10073 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 10074 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 10075 | break; |
| 10076 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10077 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10078 | "New transit: " + transit); |
| 10079 | } else if (oldWallpaper != null) { |
| 10080 | // We are transitioning from an activity with |
| 10081 | // a wallpaper to one without. |
| 10082 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10083 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10084 | "New transit away from wallpaper: " + transit); |
| 10085 | } else if (mWallpaperTarget != null) { |
| 10086 | // We are transitioning from an activity without |
| 10087 | // a wallpaper to now showing the wallpaper |
| 10088 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10089 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10090 | "New transit into wallpaper: " + transit); |
| 10091 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10092 | |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10093 | // If all closing windows are obscured, then there is |
| 10094 | // no need to do an animation. This is the case, for |
| 10095 | // example, when this transition is being done behind |
| 10096 | // the lock screen. |
| 10097 | if (!mPolicy.allowAppAnimationsLw()) { |
| 10098 | animLp = null; |
| 10099 | } |
| 10100 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10101 | NN = mOpeningApps.size(); |
| 10102 | for (i=0; i<NN; i++) { |
| 10103 | AppWindowToken wtoken = mOpeningApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10104 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10105 | "Now opening app" + wtoken); |
| 10106 | wtoken.reportedVisible = false; |
| 10107 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 10108 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10109 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10110 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10111 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10112 | wtoken.showAllWindowsLocked(); |
| 10113 | } |
| 10114 | NN = mClosingApps.size(); |
| 10115 | for (i=0; i<NN; i++) { |
| 10116 | AppWindowToken wtoken = mClosingApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10117 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10118 | "Now closing app" + wtoken); |
| 10119 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 10120 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10121 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10122 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10123 | wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10124 | // Force the allDrawn flag, because we want to start |
| 10125 | // this guy's animations regardless of whether it's |
| 10126 | // gotten drawn. |
| 10127 | wtoken.allDrawn = true; |
| 10128 | } |
| 10129 | |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 10130 | mNextAppTransitionPackage = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10131 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10132 | mOpeningApps.clear(); |
| 10133 | mClosingApps.clear(); |
| 10134 | |
| 10135 | // This has changed the visibility of windows, so perform |
| 10136 | // a new layout to get them all up-to-date. |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 10137 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT |
| 10138 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10139 | mLayoutNeeded = true; |
Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 10140 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 10141 | assignLayersLocked(); |
| 10142 | } |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 10143 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, |
| 10144 | false /*updateInputWindows*/); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10145 | mFocusMayChange = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10146 | } |
| 10147 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10148 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10149 | int adjResult = 0; |
| 10150 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10151 | if (!animating && mAppTransitionRunning) { |
| 10152 | // We have finished the animation of an app transition. To do |
| 10153 | // this, we have delayed a lot of operations like showing and |
| 10154 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10155 | // reflects the correct Z-order, but the window list may now |
| 10156 | // be out of sync with it. So here we will just rebuild the |
| 10157 | // entire app window list. Fun! |
| 10158 | mAppTransitionRunning = false; |
| 10159 | // Clear information about apps that were moving. |
| 10160 | mToBottomApps.clear(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10161 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10162 | rebuildAppWindowListLocked(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10163 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10164 | adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10165 | moveInputMethodWindowsIfNeededLocked(false); |
| 10166 | wallpaperMayChange = true; |
Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 10167 | // Since the window list has been rebuilt, focus might |
| 10168 | // have to be recomputed since the actual order of windows |
| 10169 | // might have changed again. |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10170 | mFocusMayChange = true; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10171 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10172 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10173 | if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10174 | // At this point, there was a window with a wallpaper that |
| 10175 | // was force hiding other windows behind it, but now it |
| 10176 | // is going away. This may be simple -- just animate |
| 10177 | // away the wallpaper and its window -- or it may be |
| 10178 | // hard -- the wallpaper now needs to be shown behind |
| 10179 | // something that was hidden. |
| 10180 | WindowState oldWallpaper = mWallpaperTarget; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10181 | if (mLowerWallpaperTarget != null |
| 10182 | && mLowerWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10183 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10184 | "wallpaperForceHiding changed with lower=" |
| 10185 | + mLowerWallpaperTarget); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10186 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10187 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 10188 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 10189 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 10190 | // The lower target has become hidden before we |
| 10191 | // actually started the animation... let's completely |
| 10192 | // re-evaluate everything. |
| 10193 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10194 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10195 | } |
| 10196 | } |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10197 | adjResult |= adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10198 | wallpaperMayChange = false; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10199 | wallpaperForceHidingChanged = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10200 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10201 | + " NEW: " + mWallpaperTarget |
| 10202 | + " LOWER: " + mLowerWallpaperTarget); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10203 | if (mLowerWallpaperTarget == null) { |
| 10204 | // Whoops, we don't need a special wallpaper animation. |
| 10205 | // Clear them out. |
| 10206 | forceHiding = false; |
| 10207 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10208 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10209 | if (w.mSurface != null) { |
| 10210 | final WindowManager.LayoutParams attrs = w.mAttrs; |
Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 10211 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10212 | if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10213 | forceHiding = true; |
| 10214 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 10215 | if (!w.mAnimating) { |
| 10216 | // We set the animation above so it |
| 10217 | // is not yet running. |
| 10218 | w.clearAnimation(); |
| 10219 | } |
| 10220 | } |
| 10221 | } |
| 10222 | } |
| 10223 | } |
| 10224 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10225 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 10226 | if (mWindowDetachedWallpaper != windowDetachedWallpaper) { |
| 10227 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 10228 | "Detached wallpaper changed from " + mWindowDetachedWallpaper |
| 10229 | + windowDetachedWallpaper); |
| 10230 | mWindowDetachedWallpaper = windowDetachedWallpaper; |
| 10231 | wallpaperMayChange = true; |
| 10232 | } |
| 10233 | |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10234 | if (wallpaperMayChange) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10235 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10236 | "Wallpaper may change! Adjusting"); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10237 | adjResult |= adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10238 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10239 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10240 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10241 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10242 | "Wallpaper layer changed: assigning layers + relayout"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10243 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10244 | assignLayersLocked(); |
| 10245 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10246 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10247 | "Wallpaper visibility changed: relayout"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10248 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10249 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10250 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10251 | if (mFocusMayChange) { |
| 10252 | mFocusMayChange = false; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 10253 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, |
| 10254 | false /*updateInputWindows*/)) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10255 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10256 | adjResult = 0; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10257 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10258 | } |
| 10259 | |
| 10260 | if (mLayoutNeeded) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10261 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10262 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10263 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10264 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x" |
| 10265 | + Integer.toHexString(changes)); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10266 | } while (changes != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10267 | |
| 10268 | // THIRD LOOP: Update the surfaces of all windows. |
| 10269 | |
| 10270 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 10271 | |
| 10272 | boolean obscured = false; |
| 10273 | boolean blurring = false; |
| 10274 | boolean dimming = false; |
| 10275 | boolean covered = false; |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10276 | boolean syswin = false; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10277 | boolean backgroundFillerShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10278 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 10279 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10280 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10281 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10282 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10283 | |
| 10284 | boolean displayed = false; |
| 10285 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 10286 | final int attrFlags = attrs.flags; |
| 10287 | |
| 10288 | if (w.mSurface != null) { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10289 | // XXX NOTE: The logic here could be improved. We have |
| 10290 | // the decision about whether to resize a window separated |
| 10291 | // from whether to hide the surface. This can cause us to |
| 10292 | // resize a surface even if we are going to hide it. You |
| 10293 | // can see this by (1) holding device in landscape mode on |
| 10294 | // home screen; (2) tapping browser icon (device will rotate |
| 10295 | // to landscape; (3) tap home. The wallpaper will be resized |
| 10296 | // in step 2 but then immediately hidden, causing us to |
| 10297 | // have to resize and then redraw it again in step 3. It |
| 10298 | // would be nice to figure out how to avoid this, but it is |
| 10299 | // difficult because we do need to resize surfaces in some |
| 10300 | // cases while they are hidden such as when first showing a |
| 10301 | // window. |
| 10302 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10303 | w.computeShownFrameLocked(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10304 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10305 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 10306 | + ": new=" + w.mShownFrame + ", old=" |
| 10307 | + w.mLastShownFrame); |
| 10308 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10309 | int width, height; |
| 10310 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10311 | // for a scaled surface, we just want to use |
| 10312 | // the requested size. |
| 10313 | width = w.mRequestedWidth; |
| 10314 | height = w.mRequestedHeight; |
| 10315 | w.mLastRequestedWidth = width; |
| 10316 | w.mLastRequestedHeight = height; |
| 10317 | w.mLastShownFrame.set(w.mShownFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10318 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10319 | width = w.mShownFrame.width(); |
| 10320 | height = w.mShownFrame.height(); |
| 10321 | w.mLastShownFrame.set(w.mShownFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10322 | } |
| 10323 | |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 10324 | if (w.mSurface != null) { |
| 10325 | if (w.mSurfaceX != w.mShownFrame.left |
| 10326 | || w.mSurfaceY != w.mShownFrame.top) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10327 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10328 | if (SHOW_TRANSACTIONS) logSurface(w, |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 10329 | "POS " + w.mShownFrame.left |
| 10330 | + ", " + w.mShownFrame.top, null); |
| 10331 | w.mSurfaceX = w.mShownFrame.left; |
| 10332 | w.mSurfaceY = w.mShownFrame.top; |
| 10333 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 10334 | } catch (RuntimeException e) { |
| 10335 | Slog.w(TAG, "Error positioning surface of " + w |
| 10336 | + " pos=(" + w.mShownFrame.left |
| 10337 | + "," + w.mShownFrame.top + ")", e); |
| 10338 | if (!recoveringMemory) { |
| 10339 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 10340 | } |
| 10341 | } |
| 10342 | } |
| 10343 | |
| 10344 | if (width < 1) { |
| 10345 | width = 1; |
| 10346 | } |
| 10347 | if (height < 1) { |
| 10348 | height = 1; |
| 10349 | } |
| 10350 | |
| 10351 | if (w.mSurfaceW != width || w.mSurfaceH != height) { |
| 10352 | try { |
| 10353 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10354 | "SIZE " + w.mShownFrame.width() + "x" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10355 | + w.mShownFrame.height(), null); |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10356 | w.mSurfaceResized = true; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10357 | w.mSurfaceW = width; |
| 10358 | w.mSurfaceH = height; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10359 | w.mSurface.setSize(width, height); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10360 | } catch (RuntimeException e) { |
| 10361 | // If something goes wrong with the surface (such |
| 10362 | // as running out of memory), don't take down the |
| 10363 | // entire system. |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 10364 | Slog.e(TAG, "Error resizing surface of " + w |
| 10365 | + " size=(" + width + "x" + height + ")", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10366 | if (!recoveringMemory) { |
| 10367 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 10368 | } |
| 10369 | } |
| 10370 | } |
| 10371 | } |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 10372 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10373 | if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10374 | w.mContentInsetsChanged = |
| 10375 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 10376 | w.mVisibleInsetsChanged = |
| 10377 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10378 | boolean configChanged = |
| 10379 | w.mConfiguration != mCurConfiguration |
| 10380 | && (w.mConfiguration == null |
| 10381 | || mCurConfiguration.diff(w.mConfiguration) != 0); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10382 | if (DEBUG_CONFIGURATION && configChanged) { |
| 10383 | Slog.v(TAG, "Win " + w + " config changed: " |
| 10384 | + mCurConfiguration); |
| 10385 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10386 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10387 | + ": configChanged=" + configChanged |
| 10388 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 10389 | boolean frameChanged = !w.mLastFrame.equals(w.mFrame); |
| 10390 | if (frameChanged |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10391 | || w.mContentInsetsChanged |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10392 | || w.mVisibleInsetsChanged |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10393 | || w.mSurfaceResized |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10394 | || configChanged) { |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 10395 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) { |
| 10396 | Slog.v(TAG, "Resize reasons: " |
| 10397 | + "frameChanged=" + frameChanged |
| 10398 | + " contentInsetsChanged=" + w.mContentInsetsChanged |
| 10399 | + " visibleInsetsChanged=" + w.mVisibleInsetsChanged |
| 10400 | + " surfaceResized=" + w.mSurfaceResized |
| 10401 | + " configChanged=" + configChanged); |
| 10402 | } |
| 10403 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10404 | w.mLastFrame.set(w.mFrame); |
| 10405 | w.mLastContentInsets.set(w.mContentInsets); |
| 10406 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10407 | // If the screen is currently frozen, then keep |
| 10408 | // it frozen until this window draws at its new |
| 10409 | // orientation. |
| 10410 | if (mDisplayFrozen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10411 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10412 | "Resizing while display frozen: " + w); |
| 10413 | w.mOrientationChanging = true; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10414 | if (!mWindowsFreezingScreen) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10415 | mWindowsFreezingScreen = true; |
| 10416 | // XXX should probably keep timeout from |
| 10417 | // when we first froze the display. |
| 10418 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10419 | mH.sendMessageDelayed(mH.obtainMessage( |
| 10420 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 10421 | } |
| 10422 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10423 | // If the orientation is changing, then we need to |
| 10424 | // hold off on unfreezing the display until this |
| 10425 | // window has been redrawn; to do that, we need |
| 10426 | // to go through the process of getting informed |
| 10427 | // by the application when it has finished drawing. |
| 10428 | if (w.mOrientationChanging) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10429 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10430 | "Orientation start waiting for draw in " |
| 10431 | + w + ", surface " + w.mSurface); |
| 10432 | w.mDrawPending = true; |
| 10433 | w.mCommitDrawPending = false; |
| 10434 | w.mReadyToShow = false; |
| 10435 | if (w.mAppToken != null) { |
| 10436 | w.mAppToken.allDrawn = false; |
| 10437 | } |
| 10438 | } |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10439 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10440 | "Resizing window " + w + " to " + w.mFrame); |
| 10441 | mResizingWindows.add(w); |
| 10442 | } else if (w.mOrientationChanging) { |
| 10443 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10444 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10445 | "Orientation not waiting for draw in " |
| 10446 | + w + ", surface " + w.mSurface); |
| 10447 | w.mOrientationChanging = false; |
| 10448 | } |
| 10449 | } |
| 10450 | } |
| 10451 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10452 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10453 | if (!w.mLastHidden) { |
| 10454 | //dump(); |
| 10455 | w.mLastHidden = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10456 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10457 | "HIDE (performLayout)", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10458 | if (w.mSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10459 | w.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10460 | try { |
| 10461 | w.mSurface.hide(); |
| 10462 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10463 | Slog.w(TAG, "Exception hiding surface in " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10464 | } |
| 10465 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10466 | } |
| 10467 | // If we are waiting for this window to handle an |
| 10468 | // orientation change, well, it is hidden, so |
| 10469 | // doesn't really matter. Note that this does |
| 10470 | // introduce a potential glitch if the window |
| 10471 | // becomes unhidden before it has drawn for the |
| 10472 | // new orientation. |
| 10473 | if (w.mOrientationChanging) { |
| 10474 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10475 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10476 | "Orientation change skips hidden " + w); |
| 10477 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10478 | } else if (w.mLastLayer != w.mAnimLayer |
| 10479 | || w.mLastAlpha != w.mShownAlpha |
| 10480 | || w.mLastDsDx != w.mDsDx |
| 10481 | || w.mLastDtDx != w.mDtDx |
| 10482 | || w.mLastDsDy != w.mDsDy |
| 10483 | || w.mLastDtDy != w.mDtDy |
| 10484 | || w.mLastHScale != w.mHScale |
| 10485 | || w.mLastVScale != w.mVScale |
| 10486 | || w.mLastHidden) { |
| 10487 | displayed = true; |
| 10488 | w.mLastAlpha = w.mShownAlpha; |
| 10489 | w.mLastLayer = w.mAnimLayer; |
| 10490 | w.mLastDsDx = w.mDsDx; |
| 10491 | w.mLastDtDx = w.mDtDx; |
| 10492 | w.mLastDsDy = w.mDsDy; |
| 10493 | w.mLastDtDy = w.mDtDy; |
| 10494 | w.mLastHScale = w.mHScale; |
| 10495 | w.mLastVScale = w.mVScale; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10496 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10497 | "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10498 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 10499 | + "," + (w.mDtDx*w.mVScale) |
| 10500 | + "][" + (w.mDsDy*w.mHScale) |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10501 | + "," + (w.mDtDy*w.mVScale) + "]", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10502 | if (w.mSurface != null) { |
| 10503 | try { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10504 | w.mSurfaceAlpha = w.mShownAlpha; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10505 | w.mSurface.setAlpha(w.mShownAlpha); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10506 | w.mSurfaceLayer = w.mAnimLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10507 | w.mSurface.setLayer(w.mAnimLayer); |
| 10508 | w.mSurface.setMatrix( |
| 10509 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 10510 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 10511 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10512 | Slog.w(TAG, "Error updating surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10513 | if (!recoveringMemory) { |
| 10514 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 10515 | } |
| 10516 | } |
| 10517 | } |
| 10518 | |
| 10519 | if (w.mLastHidden && !w.mDrawPending |
| 10520 | && !w.mCommitDrawPending |
| 10521 | && !w.mReadyToShow) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10522 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10523 | "SHOW (performLayout)", null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10524 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10525 | + " during relayout"); |
| 10526 | if (showSurfaceRobustlyLocked(w)) { |
| 10527 | w.mHasDrawn = true; |
| 10528 | w.mLastHidden = false; |
| 10529 | } else { |
| 10530 | w.mOrientationChanging = false; |
| 10531 | } |
| 10532 | } |
| 10533 | if (w.mSurface != null) { |
| 10534 | w.mToken.hasVisible = true; |
| 10535 | } |
| 10536 | } else { |
| 10537 | displayed = true; |
| 10538 | } |
| 10539 | |
| 10540 | if (displayed) { |
| 10541 | if (!covered) { |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 10542 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 10543 | && attrs.height == LayoutParams.MATCH_PARENT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10544 | covered = true; |
| 10545 | } |
| 10546 | } |
| 10547 | if (w.mOrientationChanging) { |
| 10548 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 10549 | orientationChangeComplete = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10550 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10551 | "Orientation continue waiting for draw in " + w); |
| 10552 | } else { |
| 10553 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10554 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10555 | "Orientation change complete in " + w); |
| 10556 | } |
| 10557 | } |
| 10558 | w.mToken.hasVisible = true; |
| 10559 | } |
| 10560 | } else if (w.mOrientationChanging) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10561 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10562 | "Orientation change skips hidden " + w); |
| 10563 | w.mOrientationChanging = false; |
| 10564 | } |
| 10565 | |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 10566 | if (w.mContentChanged) { |
| 10567 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing"); |
| 10568 | w.mContentChanged = false; |
| 10569 | } |
| 10570 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10571 | final boolean canBeSeen = w.isDisplayedLw(); |
| 10572 | |
| 10573 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 10574 | focusDisplayed = true; |
| 10575 | } |
| 10576 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10577 | final boolean obscuredChanged = w.mObscured != obscured; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10578 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10579 | // Update effect. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10580 | if (!(w.mObscured=obscured)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10581 | if (w.mSurface != null) { |
| 10582 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 10583 | holdScreen = w.mSession; |
| 10584 | } |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10585 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 10586 | && screenBrightness < 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10587 | screenBrightness = w.mAttrs.screenBrightness; |
| 10588 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10589 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 10590 | && buttonBrightness < 0) { |
| 10591 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 10592 | } |
Mike Lockwood | 46af6a8 | 2010-03-09 08:28:22 -0500 | [diff] [blame] | 10593 | if (canBeSeen |
| 10594 | && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 10595 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 10596 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) { |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10597 | syswin = true; |
| 10598 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10599 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10600 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10601 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 10602 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10603 | // This window completely covers everything behind it, |
| 10604 | // so we want to leave all of them as unblurred (for |
| 10605 | // performance reasons). |
| 10606 | obscured = true; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10607 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10608 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler"); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10609 | // This window is in compatibility mode, and needs background filler. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10610 | obscured = true; |
| 10611 | if (mBackgroundFillerSurface == null) { |
| 10612 | try { |
| 10613 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10614 | "BackGroundFiller", |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10615 | 0, dw, dh, |
| 10616 | PixelFormat.OPAQUE, |
| 10617 | Surface.FX_SURFACE_NORMAL); |
| 10618 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10619 | Slog.e(TAG, "Exception creating filler surface", e); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10620 | } |
| 10621 | } |
| 10622 | try { |
| 10623 | mBackgroundFillerSurface.setPosition(0, 0); |
| 10624 | mBackgroundFillerSurface.setSize(dw, dh); |
| 10625 | // Using the same layer as Dim because they will never be shown at the |
| 10626 | // same time. |
| 10627 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 10628 | mBackgroundFillerSurface.show(); |
| 10629 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10630 | Slog.e(TAG, "Exception showing filler surface"); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10631 | } |
| 10632 | backgroundFillerShown = true; |
| 10633 | mBackgroundFillerShown = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10634 | } else if (canBeSeen && !obscured && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10635 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10636 | if (localLOGV) Slog.v(TAG, "Win " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10637 | + ": blurring=" + blurring |
| 10638 | + " obscured=" + obscured |
| 10639 | + " displayed=" + displayed); |
| 10640 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 10641 | if (!dimming) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10642 | //Slog.i(TAG, "DIM BEHIND: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10643 | dimming = true; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10644 | if (mDimAnimator == null) { |
| 10645 | mDimAnimator = new DimAnimator(mFxSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10646 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10647 | mDimAnimator.show(dw, dh); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 10648 | mDimAnimator.updateParameters(mContext.getResources(), |
| 10649 | w, currentTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10650 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10651 | } |
| 10652 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 10653 | if (!blurring) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10654 | //Slog.i(TAG, "BLUR BEHIND: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10655 | blurring = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10656 | if (mBlurSurface == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10657 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10658 | + mBlurSurface + ": CREATE"); |
| 10659 | try { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10660 | mBlurSurface = new Surface(mFxSession, 0, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10661 | "BlurSurface", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10662 | -1, 16, 16, |
| 10663 | PixelFormat.OPAQUE, |
| 10664 | Surface.FX_SURFACE_BLUR); |
| 10665 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10666 | Slog.e(TAG, "Exception creating Blur surface", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10667 | } |
| 10668 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10669 | if (mBlurSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10670 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10671 | + mBlurSurface + ": pos=(0,0) (" + |
| 10672 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10673 | mBlurSurface.setPosition(0, 0); |
| 10674 | mBlurSurface.setSize(dw, dh); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10675 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 10676 | if (!mBlurShown) { |
| 10677 | try { |
| 10678 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10679 | + mBlurSurface + ": SHOW"); |
| 10680 | mBlurSurface.show(); |
| 10681 | } catch (RuntimeException e) { |
| 10682 | Slog.w(TAG, "Failure showing blur surface", e); |
| 10683 | } |
| 10684 | mBlurShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10685 | } |
| 10686 | } |
| 10687 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10688 | } |
| 10689 | } |
| 10690 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10691 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10692 | if (obscuredChanged && mWallpaperTarget == w) { |
| 10693 | // This is the wallpaper target and its obscured state |
| 10694 | // changed... make sure the current wallaper's visibility |
| 10695 | // has been updated accordingly. |
| 10696 | updateWallpaperVisibilityLocked(); |
| 10697 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10698 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10699 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10700 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 10701 | mBackgroundFillerShown = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10702 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler"); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10703 | try { |
| 10704 | mBackgroundFillerSurface.hide(); |
| 10705 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10706 | Slog.e(TAG, "Exception hiding filler surface", e); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10707 | } |
| 10708 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10709 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10710 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10711 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 10712 | mDisplayFrozen || !mPolicy.isScreenOn()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10713 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10714 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10715 | if (!blurring && mBlurShown) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10716 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10717 | + ": HIDE"); |
| 10718 | try { |
| 10719 | mBlurSurface.hide(); |
| 10720 | } catch (IllegalArgumentException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10721 | Slog.w(TAG, "Illegal argument exception hiding blur surface"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10722 | } |
| 10723 | mBlurShown = false; |
| 10724 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10725 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10726 | Slog.e(TAG, "Unhandled exception in Window Manager", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10727 | } |
| 10728 | |
| 10729 | Surface.closeTransaction(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10730 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 10731 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces"); |
| 10732 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10733 | if (mWatermark != null) { |
| 10734 | mWatermark.drawIfNeeded(); |
| 10735 | } |
| 10736 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10737 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10738 | "With display frozen, orientationChangeComplete=" |
| 10739 | + orientationChangeComplete); |
| 10740 | if (orientationChangeComplete) { |
| 10741 | if (mWindowsFreezingScreen) { |
| 10742 | mWindowsFreezingScreen = false; |
| 10743 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10744 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10745 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10746 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10747 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10748 | i = mResizingWindows.size(); |
| 10749 | if (i > 0) { |
| 10750 | do { |
| 10751 | i--; |
| 10752 | WindowState win = mResizingWindows.get(i); |
| 10753 | try { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10754 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| 10755 | "Reporting new frame to " + win + ": " + win.mFrame); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10756 | int diff = 0; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10757 | boolean configChanged = |
| 10758 | win.mConfiguration != mCurConfiguration |
| 10759 | && (win.mConfiguration == null |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10760 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); |
| 10761 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) |
| 10762 | && configChanged) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10763 | Slog.i(TAG, "Sending new config to window " + win + ": " |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10764 | + win.mFrame.width() + "x" + win.mFrame.height() |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10765 | + " / " + mCurConfiguration + " / 0x" |
| 10766 | + Integer.toHexString(diff)); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10767 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10768 | win.mConfiguration = mCurConfiguration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10769 | win.mClient.resized(win.mFrame.width(), |
| 10770 | win.mFrame.height(), win.mLastContentInsets, |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10771 | win.mLastVisibleInsets, win.mDrawPending, |
| 10772 | configChanged ? win.mConfiguration : null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10773 | win.mContentInsetsChanged = false; |
| 10774 | win.mVisibleInsetsChanged = false; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10775 | win.mSurfaceResized = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10776 | } catch (RemoteException e) { |
| 10777 | win.mOrientationChanging = false; |
| 10778 | } |
| 10779 | } while (i > 0); |
| 10780 | mResizingWindows.clear(); |
| 10781 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10782 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10783 | // Destroy the surface of any windows that are no longer visible. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10784 | boolean wallpaperDestroyed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10785 | i = mDestroySurface.size(); |
| 10786 | if (i > 0) { |
| 10787 | do { |
| 10788 | i--; |
| 10789 | WindowState win = mDestroySurface.get(i); |
| 10790 | win.mDestroying = false; |
| 10791 | if (mInputMethodWindow == win) { |
| 10792 | mInputMethodWindow = null; |
| 10793 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10794 | if (win == mWallpaperTarget) { |
| 10795 | wallpaperDestroyed = true; |
| 10796 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10797 | win.destroySurfaceLocked(); |
| 10798 | } while (i > 0); |
| 10799 | mDestroySurface.clear(); |
| 10800 | } |
| 10801 | |
| 10802 | // Time to remove any exiting tokens? |
| 10803 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 10804 | WindowToken token = mExitingTokens.get(i); |
| 10805 | if (!token.hasVisible) { |
| 10806 | mExitingTokens.remove(i); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10807 | if (token.windowType == TYPE_WALLPAPER) { |
| 10808 | mWallpaperTokens.remove(token); |
| 10809 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10810 | } |
| 10811 | } |
| 10812 | |
| 10813 | // Time to remove any exiting applications? |
| 10814 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10815 | AppWindowToken token = mExitingAppTokens.get(i); |
| 10816 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 10817 | // Make sure there is no animation running on this token, |
| 10818 | // so any windows associated with it will be removed as |
| 10819 | // soon as their animations are complete |
| 10820 | token.animation = null; |
| 10821 | token.animating = false; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 10822 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 10823 | "performLayout: App token exiting now removed" + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10824 | mAppTokens.remove(token); |
| 10825 | mExitingAppTokens.remove(i); |
| 10826 | } |
| 10827 | } |
| 10828 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10829 | boolean needRelayout = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10830 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10831 | if (!animating && mAppTransitionRunning) { |
| 10832 | // We have finished the animation of an app transition. To do |
| 10833 | // this, we have delayed a lot of operations like showing and |
| 10834 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10835 | // reflects the correct Z-order, but the window list may now |
| 10836 | // be out of sync with it. So here we will just rebuild the |
| 10837 | // entire app window list. Fun! |
| 10838 | mAppTransitionRunning = false; |
| 10839 | needRelayout = true; |
| 10840 | rebuildAppWindowListLocked(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10841 | assignLayersLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10842 | // Clear information about apps that were moving. |
| 10843 | mToBottomApps.clear(); |
| 10844 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10845 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10846 | if (focusDisplayed) { |
| 10847 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 10848 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10849 | if (wallpaperDestroyed) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10850 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10851 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10852 | if (needRelayout) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10853 | requestAnimationLocked(0); |
| 10854 | } else if (animating) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10855 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 10856 | } |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 10857 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 10858 | // Finally update all input windows now that the window changes have stabilized. |
| 10859 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10860 | mInputMonitor.updateInputWindowsLw(); |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 10861 | |
Jeff Brown | 8e03b75 | 2010-06-13 19:16:55 -0700 | [diff] [blame] | 10862 | setHoldScreenLocked(holdScreen != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10863 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 10864 | mPowerManager.setScreenBrightnessOverride(-1); |
| 10865 | } else { |
| 10866 | mPowerManager.setScreenBrightnessOverride((int) |
| 10867 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 10868 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10869 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 10870 | mPowerManager.setButtonBrightnessOverride(-1); |
| 10871 | } else { |
| 10872 | mPowerManager.setButtonBrightnessOverride((int) |
| 10873 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 10874 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10875 | if (holdScreen != mHoldingScreenOn) { |
| 10876 | mHoldingScreenOn = holdScreen; |
| 10877 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 10878 | mH.sendMessage(m); |
| 10879 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10880 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10881 | if (mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10882 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10883 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 10884 | LocalPowerManager.BUTTON_EVENT, true); |
| 10885 | mTurnOnScreen = false; |
| 10886 | } |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 10887 | |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame^] | 10888 | if (updateRotation) { |
| 10889 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation"); |
| 10890 | boolean changed = setRotationUncheckedLocked( |
| 10891 | WindowManagerPolicy.USE_LAST_ROTATION, 0, false); |
| 10892 | if (changed) { |
| 10893 | sendNewConfiguration(); |
| 10894 | } |
| 10895 | } |
| 10896 | |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 10897 | // Check to see if we are now in a state where the screen should |
| 10898 | // be enabled, because the window obscured flags have changed. |
| 10899 | enableScreenIfNeededLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10900 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 10901 | |
| 10902 | /** |
| 10903 | * Must be called with the main window manager lock held. |
| 10904 | */ |
| 10905 | void setHoldScreenLocked(boolean holding) { |
| 10906 | boolean state = mHoldingScreenWakeLock.isHeld(); |
| 10907 | if (holding != state) { |
| 10908 | if (holding) { |
| 10909 | mHoldingScreenWakeLock.acquire(); |
| 10910 | } else { |
| 10911 | mPolicy.screenOnStoppedLw(); |
| 10912 | mHoldingScreenWakeLock.release(); |
| 10913 | } |
| 10914 | } |
| 10915 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10916 | |
| 10917 | void requestAnimationLocked(long delay) { |
| 10918 | if (!mAnimationPending) { |
| 10919 | mAnimationPending = true; |
| 10920 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 10921 | } |
| 10922 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10923 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10924 | /** |
| 10925 | * Have the surface flinger show a surface, robustly dealing with |
| 10926 | * error conditions. In particular, if there is not enough memory |
| 10927 | * to show the surface, then we will try to get rid of other surfaces |
| 10928 | * in order to succeed. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10929 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10930 | * @return Returns true if the surface was successfully shown. |
| 10931 | */ |
| 10932 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 10933 | try { |
| 10934 | if (win.mSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10935 | win.mSurfaceShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10936 | win.mSurface.show(); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10937 | if (win.mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10938 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 10939 | "Show surface turning screen on: " + win); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10940 | win.mTurnOnScreen = false; |
| 10941 | mTurnOnScreen = true; |
| 10942 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10943 | } |
| 10944 | return true; |
| 10945 | } catch (RuntimeException e) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 10946 | 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] | 10947 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10948 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10949 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10950 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10951 | return false; |
| 10952 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10953 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10954 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 10955 | final Surface surface = win.mSurface; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10956 | |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10957 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10958 | win.mSession.mPid, operation); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10959 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10960 | if (mForceRemoves == null) { |
| 10961 | mForceRemoves = new ArrayList<WindowState>(); |
| 10962 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10963 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10964 | long callingIdentity = Binder.clearCallingIdentity(); |
| 10965 | try { |
| 10966 | // There was some problem... first, do a sanity check of the |
| 10967 | // window list to make sure we haven't left any dangling surfaces |
| 10968 | // around. |
| 10969 | int N = mWindows.size(); |
| 10970 | boolean leakedSurface = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10971 | 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] | 10972 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10973 | WindowState ws = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10974 | if (ws.mSurface != null) { |
| 10975 | if (!mSessions.contains(ws.mSession)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10976 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10977 | + ws + " surface=" + ws.mSurface |
| 10978 | + " token=" + win.mToken |
| 10979 | + " pid=" + ws.mSession.mPid |
| 10980 | + " uid=" + ws.mSession.mUid); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 10981 | if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10982 | ws.mSurface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10983 | ws.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10984 | ws.mSurface = null; |
| 10985 | mForceRemoves.add(ws); |
| 10986 | i--; |
| 10987 | N--; |
| 10988 | leakedSurface = true; |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 10989 | } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10990 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10991 | + ws + " surface=" + ws.mSurface |
| 10992 | + " token=" + win.mAppToken); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 10993 | if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10994 | ws.mSurface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10995 | ws.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10996 | ws.mSurface = null; |
| 10997 | leakedSurface = true; |
| 10998 | } |
| 10999 | } |
| 11000 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11001 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11002 | boolean killedApps = false; |
| 11003 | if (!leakedSurface) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11004 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11005 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 11006 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 11007 | WindowState ws = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11008 | if (ws.mSurface != null) { |
| 11009 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 11010 | } |
| 11011 | } |
| 11012 | if (pidCandidates.size() > 0) { |
| 11013 | int[] pids = new int[pidCandidates.size()]; |
| 11014 | for (int i=0; i<pids.length; i++) { |
| 11015 | pids[i] = pidCandidates.keyAt(i); |
| 11016 | } |
| 11017 | try { |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 11018 | if (mActivityManager.killPids(pids, "Free memory")) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11019 | killedApps = true; |
| 11020 | } |
| 11021 | } catch (RemoteException e) { |
| 11022 | } |
| 11023 | } |
| 11024 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11025 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11026 | if (leakedSurface || killedApps) { |
| 11027 | // We managed to reclaim some memory, so get rid of the trouble |
| 11028 | // surface and ask the app to request another one. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11029 | 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] | 11030 | if (surface != null) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 11031 | if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11032 | surface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11033 | win.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11034 | win.mSurface = null; |
| 11035 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11036 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11037 | try { |
| 11038 | win.mClient.dispatchGetNewSurface(); |
| 11039 | } catch (RemoteException e) { |
| 11040 | } |
| 11041 | } |
| 11042 | } finally { |
| 11043 | Binder.restoreCallingIdentity(callingIdentity); |
| 11044 | } |
| 11045 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11046 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 11047 | private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11048 | WindowState newFocus = computeFocusedWindowLocked(); |
| 11049 | if (mCurrentFocus != newFocus) { |
| 11050 | // This check makes sure that we don't already have the focus |
| 11051 | // change message pending. |
| 11052 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 11053 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11054 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11055 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 11056 | final WindowState oldFocus = mCurrentFocus; |
| 11057 | mCurrentFocus = newFocus; |
| 11058 | mLosingFocus.remove(newFocus); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11059 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11060 | final WindowState imWindow = mInputMethodWindow; |
| 11061 | if (newFocus != imWindow && oldFocus != imWindow) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11062 | if (moveInputMethodWindowsIfNeededLocked( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11063 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11064 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 11065 | mLayoutNeeded = true; |
| 11066 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11067 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 11068 | performLayoutLockedInner(true /*initial*/, updateInputWindows); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11069 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 11070 | // Client will do the layout, but we need to assign layers |
| 11071 | // for handleNewWindowLocked() below. |
| 11072 | assignLayersLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11073 | } |
| 11074 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11075 | |
| 11076 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 11077 | // If we defer assigning layers, then the caller is responsible for |
| 11078 | // doing this part. |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 11079 | finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11080 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11081 | return true; |
| 11082 | } |
| 11083 | return false; |
| 11084 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11085 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 11086 | private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) { |
| 11087 | mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11088 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11089 | |
| 11090 | private WindowState computeFocusedWindowLocked() { |
| 11091 | WindowState result = null; |
| 11092 | WindowState win; |
| 11093 | |
| 11094 | int i = mWindows.size() - 1; |
| 11095 | int nextAppIndex = mAppTokens.size()-1; |
| 11096 | WindowToken nextApp = nextAppIndex >= 0 |
| 11097 | ? mAppTokens.get(nextAppIndex) : null; |
| 11098 | |
| 11099 | while (i >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 11100 | win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11101 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11102 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11103 | TAG, "Looking for focus: " + i |
| 11104 | + " = " + win |
| 11105 | + ", flags=" + win.mAttrs.flags |
| 11106 | + ", canReceive=" + win.canReceiveKeys()); |
| 11107 | |
| 11108 | AppWindowToken thisApp = win.mAppToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11109 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11110 | // If this window's application has been removed, just skip it. |
| 11111 | if (thisApp != null && thisApp.removed) { |
| 11112 | i--; |
| 11113 | continue; |
| 11114 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11115 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11116 | // If there is a focused app, don't allow focus to go to any |
| 11117 | // windows below it. If this is an application window, step |
| 11118 | // through the app tokens until we find its app. |
| 11119 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 11120 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 11121 | int origAppIndex = nextAppIndex; |
| 11122 | while (nextAppIndex > 0) { |
| 11123 | if (nextApp == mFocusedApp) { |
| 11124 | // Whoops, we are below the focused app... no focus |
| 11125 | // for you! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11126 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11127 | TAG, "Reached focused app: " + mFocusedApp); |
| 11128 | return null; |
| 11129 | } |
| 11130 | nextAppIndex--; |
| 11131 | nextApp = mAppTokens.get(nextAppIndex); |
| 11132 | if (nextApp == thisApp) { |
| 11133 | break; |
| 11134 | } |
| 11135 | } |
| 11136 | if (thisApp != nextApp) { |
| 11137 | // Uh oh, the app token doesn't exist! This shouldn't |
| 11138 | // happen, but if it does we can get totally hosed... |
| 11139 | // so restart at the original app. |
| 11140 | nextAppIndex = origAppIndex; |
| 11141 | nextApp = mAppTokens.get(nextAppIndex); |
| 11142 | } |
| 11143 | } |
| 11144 | |
| 11145 | // Dispatch to this window if it is wants key events. |
| 11146 | if (win.canReceiveKeys()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11147 | if (DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11148 | TAG, "Found focus @ " + i + " = " + win); |
| 11149 | result = win; |
| 11150 | break; |
| 11151 | } |
| 11152 | |
| 11153 | i--; |
| 11154 | } |
| 11155 | |
| 11156 | return result; |
| 11157 | } |
| 11158 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 11159 | private void startFreezingDisplayLocked(boolean inTransaction) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11160 | if (mDisplayFrozen) { |
| 11161 | return; |
| 11162 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11163 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11164 | mScreenFrozenLock.acquire(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11165 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11166 | long now = SystemClock.uptimeMillis(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11167 | //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11168 | if (mFreezeGcPending != 0) { |
| 11169 | if (now > (mFreezeGcPending+1000)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11170 | //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11171 | mH.removeMessages(H.FORCE_GC); |
| 11172 | Runtime.getRuntime().gc(); |
| 11173 | mFreezeGcPending = now; |
| 11174 | } |
| 11175 | } else { |
| 11176 | mFreezeGcPending = now; |
| 11177 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11178 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11179 | mDisplayFrozen = true; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11180 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 11181 | mInputMonitor.freezeInputDispatchingLw(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11182 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 11183 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 11184 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11185 | mNextAppTransitionPackage = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11186 | mAppTransitionReady = true; |
| 11187 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11188 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11189 | if (PROFILE_ORIENTATION) { |
| 11190 | File file = new File("/data/system/frozen"); |
| 11191 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 11192 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11193 | |
| 11194 | if (CUSTOM_SCREEN_ROTATION) { |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 11195 | if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) { |
| 11196 | mScreenRotationAnimation.kill(); |
| 11197 | mScreenRotationAnimation = null; |
| 11198 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11199 | if (mScreenRotationAnimation == null) { |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 11200 | mScreenRotationAnimation = new ScreenRotationAnimation(mContext, |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 11201 | mDisplay, mFxSession, inTransaction); |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11202 | } |
| 11203 | } else { |
| 11204 | Surface.freezeDisplay(0); |
| 11205 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11206 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11207 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11208 | private void stopFreezingDisplayLocked() { |
| 11209 | if (!mDisplayFrozen) { |
| 11210 | return; |
| 11211 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11212 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11213 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) { |
| 11214 | return; |
| 11215 | } |
| 11216 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11217 | mDisplayFrozen = false; |
| 11218 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 11219 | if (PROFILE_ORIENTATION) { |
| 11220 | Debug.stopMethodTracing(); |
| 11221 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11222 | |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame^] | 11223 | boolean updateRotation = false; |
| 11224 | |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11225 | if (CUSTOM_SCREEN_ROTATION) { |
| 11226 | if (mScreenRotationAnimation != null) { |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 11227 | if (mScreenRotationAnimation.dismiss(MAX_ANIMATION_DURATION, |
| 11228 | mTransitionAnimationScale)) { |
| 11229 | requestAnimationLocked(0); |
| 11230 | } else { |
| 11231 | mScreenRotationAnimation = null; |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame^] | 11232 | updateRotation = true; |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 11233 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11234 | } |
| 11235 | } else { |
| 11236 | Surface.unfreezeDisplay(0); |
| 11237 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11238 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 11239 | mInputMonitor.thawInputDispatchingLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11240 | |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 11241 | // While the display is frozen we don't re-compute the orientation |
| 11242 | // to avoid inconsistent states. However, something interesting |
| 11243 | // could have actually changed during that time so re-evaluate it |
| 11244 | // now to catch that. |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 11245 | if (updateOrientationFromAppTokensLocked(false)) { |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 11246 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 11247 | } |
| 11248 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11249 | // A little kludge: a lot could have happened while the |
| 11250 | // display was frozen, so now that we are coming back we |
| 11251 | // do a gc so that any remote references the system |
| 11252 | // processes holds on others can be released if they are |
| 11253 | // no longer needed. |
| 11254 | mH.removeMessages(H.FORCE_GC); |
| 11255 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 11256 | 2000); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11257 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11258 | mScreenFrozenLock.release(); |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame^] | 11259 | |
| 11260 | if (updateRotation) { |
| 11261 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation"); |
| 11262 | boolean changed = setRotationUncheckedLocked( |
| 11263 | WindowManagerPolicy.USE_LAST_ROTATION, 0, false); |
| 11264 | if (changed) { |
| 11265 | sendNewConfiguration(); |
| 11266 | } |
| 11267 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11268 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11269 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11270 | static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps, |
| 11271 | DisplayMetrics dm) { |
| 11272 | if (index < tokens.length) { |
| 11273 | String str = tokens[index]; |
| 11274 | if (str != null && str.length() > 0) { |
| 11275 | try { |
| 11276 | int val = Integer.parseInt(str); |
| 11277 | return val; |
| 11278 | } catch (Exception e) { |
| 11279 | } |
| 11280 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11281 | } |
| 11282 | if (defUnits == TypedValue.COMPLEX_UNIT_PX) { |
| 11283 | return defDps; |
| 11284 | } |
| 11285 | int val = (int)TypedValue.applyDimension(defUnits, defDps, dm); |
| 11286 | return val; |
| 11287 | } |
| 11288 | |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11289 | static class Watermark { |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11290 | final String[] mTokens; |
| 11291 | final String mText; |
| 11292 | final Paint mTextPaint; |
| 11293 | final int mTextWidth; |
| 11294 | final int mTextHeight; |
| 11295 | final int mTextAscent; |
| 11296 | final int mTextDescent; |
| 11297 | final int mDeltaX; |
| 11298 | final int mDeltaY; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11299 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11300 | Surface mSurface; |
| 11301 | int mLastDW; |
| 11302 | int mLastDH; |
| 11303 | boolean mDrawNeeded; |
| 11304 | |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11305 | Watermark(Display display, SurfaceSession session, String[] tokens) { |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11306 | final DisplayMetrics dm = new DisplayMetrics(); |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11307 | display.getMetrics(dm); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11308 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11309 | if (false) { |
| 11310 | Log.i(TAG, "*********************** WATERMARK"); |
| 11311 | for (int i=0; i<tokens.length; i++) { |
| 11312 | Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]); |
| 11313 | } |
| 11314 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11315 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11316 | mTokens = tokens; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11317 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11318 | StringBuilder builder = new StringBuilder(32); |
| 11319 | int len = mTokens[0].length(); |
| 11320 | len = len & ~1; |
| 11321 | for (int i=0; i<len; i+=2) { |
| 11322 | int c1 = mTokens[0].charAt(i); |
| 11323 | int c2 = mTokens[0].charAt(i+1); |
| 11324 | if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10; |
| 11325 | else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10; |
| 11326 | else c1 -= '0'; |
| 11327 | if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10; |
| 11328 | else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10; |
| 11329 | else c2 -= '0'; |
| 11330 | builder.append((char)(255-((c1*16)+c2))); |
| 11331 | } |
| 11332 | mText = builder.toString(); |
| 11333 | if (false) { |
| 11334 | Log.i(TAG, "Final text: " + mText); |
| 11335 | } |
| 11336 | |
| 11337 | int fontSize = getPropertyInt(tokens, 1, |
| 11338 | TypedValue.COMPLEX_UNIT_DIP, 20, dm); |
| 11339 | |
| 11340 | mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
| 11341 | mTextPaint.setTextSize(fontSize); |
| 11342 | mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD)); |
| 11343 | |
| 11344 | FontMetricsInt fm = mTextPaint.getFontMetricsInt(); |
| 11345 | mTextWidth = (int)mTextPaint.measureText(mText); |
| 11346 | mTextAscent = fm.ascent; |
| 11347 | mTextDescent = fm.descent; |
| 11348 | mTextHeight = fm.descent - fm.ascent; |
| 11349 | |
| 11350 | mDeltaX = getPropertyInt(tokens, 2, |
| 11351 | TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm); |
| 11352 | mDeltaY = getPropertyInt(tokens, 3, |
| 11353 | TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm); |
| 11354 | int shadowColor = getPropertyInt(tokens, 4, |
| 11355 | TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm); |
| 11356 | int color = getPropertyInt(tokens, 5, |
| 11357 | TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm); |
| 11358 | int shadowRadius = getPropertyInt(tokens, 6, |
| 11359 | TypedValue.COMPLEX_UNIT_PX, 7, dm); |
| 11360 | int shadowDx = getPropertyInt(tokens, 8, |
| 11361 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 11362 | int shadowDy = getPropertyInt(tokens, 9, |
| 11363 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 11364 | |
| 11365 | mTextPaint.setColor(color); |
| 11366 | mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11367 | |
| 11368 | try { |
| 11369 | mSurface = new Surface(session, 0, |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11370 | "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11371 | mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100); |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11372 | mSurface.setPosition(0, 0); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11373 | mSurface.show(); |
| 11374 | } catch (OutOfResourcesException e) { |
| 11375 | } |
| 11376 | } |
| 11377 | |
| 11378 | void positionSurface(int dw, int dh) { |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11379 | if (mLastDW != dw || mLastDH != dh) { |
| 11380 | mLastDW = dw; |
| 11381 | mLastDH = dh; |
| 11382 | mSurface.setSize(dw, dh); |
| 11383 | mDrawNeeded = true; |
| 11384 | } |
| 11385 | } |
| 11386 | |
| 11387 | void drawIfNeeded() { |
| 11388 | if (mDrawNeeded) { |
| 11389 | final int dw = mLastDW; |
| 11390 | final int dh = mLastDH; |
| 11391 | |
| 11392 | mDrawNeeded = false; |
| 11393 | Rect dirty = new Rect(0, 0, dw, dh); |
| 11394 | Canvas c = null; |
| 11395 | try { |
| 11396 | c = mSurface.lockCanvas(dirty); |
| 11397 | } catch (IllegalArgumentException e) { |
| 11398 | } catch (OutOfResourcesException e) { |
| 11399 | } |
| 11400 | if (c != null) { |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11401 | c.drawColor(0, PorterDuff.Mode.CLEAR); |
| 11402 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11403 | int deltaX = mDeltaX; |
| 11404 | int deltaY = mDeltaY; |
| 11405 | |
| 11406 | // deltaX shouldn't be close to a round fraction of our |
| 11407 | // x step, or else things will line up too much. |
| 11408 | int div = (dw+mTextWidth)/deltaX; |
| 11409 | int rem = (dw+mTextWidth) - (div*deltaX); |
| 11410 | int qdelta = deltaX/4; |
| 11411 | if (rem < qdelta || rem > (deltaX-qdelta)) { |
| 11412 | deltaX += deltaX/3; |
| 11413 | } |
| 11414 | |
| 11415 | int y = -mTextHeight; |
| 11416 | int x = -mTextWidth; |
| 11417 | while (y < (dh+mTextHeight)) { |
| 11418 | c.drawText(mText, x, y, mTextPaint); |
| 11419 | x += deltaX; |
| 11420 | if (x >= dw) { |
| 11421 | x -= (dw+mTextWidth); |
| 11422 | y += deltaY; |
| 11423 | } |
| 11424 | } |
| 11425 | mSurface.unlockCanvasAndPost(c); |
| 11426 | } |
| 11427 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11428 | } |
| 11429 | } |
| 11430 | |
| 11431 | void createWatermark() { |
| 11432 | if (mWatermark != null) { |
| 11433 | return; |
| 11434 | } |
| 11435 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11436 | File file = new File("/system/etc/setup.conf"); |
| 11437 | FileInputStream in = null; |
| 11438 | try { |
| 11439 | in = new FileInputStream(file); |
| 11440 | DataInputStream ind = new DataInputStream(in); |
| 11441 | String line = ind.readLine(); |
| 11442 | if (line != null) { |
| 11443 | String[] toks = line.split("%"); |
| 11444 | if (toks != null && toks.length > 0) { |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11445 | mWatermark = new Watermark(mDisplay, mFxSession, toks); |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11446 | } |
| 11447 | } |
| 11448 | } catch (FileNotFoundException e) { |
| 11449 | } catch (IOException e) { |
| 11450 | } finally { |
| 11451 | if (in != null) { |
| 11452 | try { |
| 11453 | in.close(); |
| 11454 | } catch (IOException e) { |
| 11455 | } |
| 11456 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11457 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11458 | } |
| 11459 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11460 | @Override |
| 11461 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 11462 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 11463 | != PackageManager.PERMISSION_GRANTED) { |
| 11464 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 11465 | + Binder.getCallingPid() |
| 11466 | + ", uid=" + Binder.getCallingUid()); |
| 11467 | return; |
| 11468 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11469 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 11470 | mInputManager.dump(pw); |
Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 11471 | pw.println(" "); |
| 11472 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11473 | synchronized(mWindowMap) { |
| 11474 | pw.println("Current Window Manager state:"); |
| 11475 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 11476 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11477 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 11478 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11479 | w.dump(pw, " "); |
| 11480 | } |
| 11481 | if (mInputMethodDialogs.size() > 0) { |
| 11482 | pw.println(" "); |
| 11483 | pw.println(" Input method dialogs:"); |
| 11484 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 11485 | WindowState w = mInputMethodDialogs.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11486 | 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] | 11487 | } |
| 11488 | } |
| 11489 | if (mPendingRemove.size() > 0) { |
| 11490 | pw.println(" "); |
| 11491 | pw.println(" Remove pending for:"); |
| 11492 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 11493 | WindowState w = mPendingRemove.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11494 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 11495 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11496 | w.dump(pw, " "); |
| 11497 | } |
| 11498 | } |
| 11499 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 11500 | pw.println(" "); |
| 11501 | pw.println(" Windows force removing:"); |
| 11502 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 11503 | WindowState w = mForceRemoves.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11504 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 11505 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11506 | w.dump(pw, " "); |
| 11507 | } |
| 11508 | } |
| 11509 | if (mDestroySurface.size() > 0) { |
| 11510 | pw.println(" "); |
| 11511 | pw.println(" Windows waiting to destroy their surface:"); |
| 11512 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 11513 | WindowState w = mDestroySurface.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11514 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 11515 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11516 | w.dump(pw, " "); |
| 11517 | } |
| 11518 | } |
| 11519 | if (mLosingFocus.size() > 0) { |
| 11520 | pw.println(" "); |
| 11521 | pw.println(" Windows losing focus:"); |
| 11522 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 11523 | WindowState w = mLosingFocus.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11524 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 11525 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11526 | w.dump(pw, " "); |
| 11527 | } |
| 11528 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11529 | if (mResizingWindows.size() > 0) { |
| 11530 | pw.println(" "); |
| 11531 | pw.println(" Windows waiting to resize:"); |
| 11532 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 11533 | WindowState w = mResizingWindows.get(i); |
| 11534 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 11535 | pw.print(w); pw.println(":"); |
| 11536 | w.dump(pw, " "); |
| 11537 | } |
| 11538 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11539 | if (mSessions.size() > 0) { |
| 11540 | pw.println(" "); |
| 11541 | pw.println(" All active sessions:"); |
| 11542 | Iterator<Session> it = mSessions.iterator(); |
| 11543 | while (it.hasNext()) { |
| 11544 | Session s = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11545 | pw.print(" Session "); pw.print(s); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11546 | s.dump(pw, " "); |
| 11547 | } |
| 11548 | } |
| 11549 | if (mTokenMap.size() > 0) { |
| 11550 | pw.println(" "); |
| 11551 | pw.println(" All tokens:"); |
| 11552 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 11553 | while (it.hasNext()) { |
| 11554 | WindowToken token = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11555 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11556 | token.dump(pw, " "); |
| 11557 | } |
| 11558 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 11559 | if (mWallpaperTokens.size() > 0) { |
| 11560 | pw.println(" "); |
| 11561 | pw.println(" Wallpaper tokens:"); |
| 11562 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 11563 | WindowToken token = mWallpaperTokens.get(i); |
| 11564 | pw.print(" Wallpaper #"); pw.print(i); |
| 11565 | pw.print(' '); pw.print(token); pw.println(':'); |
| 11566 | token.dump(pw, " "); |
| 11567 | } |
| 11568 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11569 | if (mAppTokens.size() > 0) { |
| 11570 | pw.println(" "); |
| 11571 | pw.println(" Application tokens in Z order:"); |
| 11572 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11573 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 11574 | pw.println(mAppTokens.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11575 | } |
| 11576 | } |
| 11577 | if (mFinishedStarting.size() > 0) { |
| 11578 | pw.println(" "); |
| 11579 | pw.println(" Finishing start of application tokens:"); |
| 11580 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 11581 | WindowToken token = mFinishedStarting.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11582 | pw.print(" Finished Starting #"); pw.print(i); |
| 11583 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11584 | token.dump(pw, " "); |
| 11585 | } |
| 11586 | } |
| 11587 | if (mExitingTokens.size() > 0) { |
| 11588 | pw.println(" "); |
| 11589 | pw.println(" Exiting tokens:"); |
| 11590 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 11591 | WindowToken token = mExitingTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11592 | pw.print(" Exiting #"); pw.print(i); |
| 11593 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11594 | token.dump(pw, " "); |
| 11595 | } |
| 11596 | } |
| 11597 | if (mExitingAppTokens.size() > 0) { |
| 11598 | pw.println(" "); |
| 11599 | pw.println(" Exiting application tokens:"); |
| 11600 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 11601 | WindowToken token = mExitingAppTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11602 | pw.print(" Exiting App #"); pw.print(i); |
| 11603 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11604 | token.dump(pw, " "); |
| 11605 | } |
| 11606 | } |
| 11607 | pw.println(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11608 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 11609 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 11610 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 11611 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 11612 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 11613 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11614 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 11615 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 11616 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 11617 | } |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 11618 | if (mWindowDetachedWallpaper != null) { |
| 11619 | pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper); |
| 11620 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11621 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 11622 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 11623 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11624 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 11625 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 11626 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 11627 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11628 | if (mDimAnimator != null) { |
| 11629 | mDimAnimator.printTo(pw); |
| 11630 | } else { |
Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 11631 | pw.println( " no DimAnimator "); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11632 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11633 | pw.print(" mInputMethodAnimLayerAdjustment="); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 11634 | pw.print(mInputMethodAnimLayerAdjustment); |
| 11635 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 11636 | pw.println(mWallpaperAnimLayerAdjustment); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11637 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 11638 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11639 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 11640 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11641 | pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); |
| 11642 | pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11643 | pw.print(" mRotation="); pw.print(mRotation); |
| 11644 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 11645 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame^] | 11646 | pw.print(" mDeferredRotation="); pw.print(mDeferredRotation); |
| 11647 | pw.print(", mDeferredRotationAnimFlags="); pw.print(mDeferredRotationAnimFlags); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11648 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 11649 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 11650 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 11651 | pw.print(" mNextAppTransition=0x"); |
| 11652 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 11653 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11654 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11655 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11656 | if (mNextAppTransitionPackage != null) { |
| 11657 | pw.print(" mNextAppTransitionPackage="); |
| 11658 | pw.print(mNextAppTransitionPackage); |
| 11659 | pw.print(", mNextAppTransitionEnter=0x"); |
| 11660 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 11661 | pw.print(", mNextAppTransitionExit=0x"); |
| 11662 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 11663 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11664 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 11665 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
| 11666 | if (mOpeningApps.size() > 0) { |
| 11667 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 11668 | } |
| 11669 | if (mClosingApps.size() > 0) { |
| 11670 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 11671 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11672 | if (mToTopApps.size() > 0) { |
| 11673 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 11674 | } |
| 11675 | if (mToBottomApps.size() > 0) { |
| 11676 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 11677 | } |
Dianne Hackborn | 87fc308 | 2010-12-03 13:09:12 -0800 | [diff] [blame] | 11678 | if (mDisplay != null) { |
| 11679 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 11680 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
| 11681 | } else { |
| 11682 | pw.println(" NO DISPLAY"); |
| 11683 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 11684 | pw.println(" Policy:"); |
| 11685 | mPolicy.dump(" ", fd, pw, args); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11686 | } |
| 11687 | } |
| 11688 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11689 | // 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] | 11690 | public void monitor() { |
| 11691 | synchronized (mWindowMap) { } |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 11692 | synchronized (mKeyguardTokenWatcher) { } |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 11693 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11694 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11695 | /** |
| 11696 | * DimAnimator class that controls the dim animation. This holds the surface and |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11697 | * all state used for dim animation. |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11698 | */ |
| 11699 | private static class DimAnimator { |
| 11700 | Surface mDimSurface; |
| 11701 | boolean mDimShown = false; |
| 11702 | float mDimCurrentAlpha; |
| 11703 | float mDimTargetAlpha; |
| 11704 | float mDimDeltaPerMs; |
| 11705 | long mLastDimAnimTime; |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11706 | |
| 11707 | int mLastDimWidth, mLastDimHeight; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11708 | |
| 11709 | DimAnimator (SurfaceSession session) { |
| 11710 | if (mDimSurface == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11711 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11712 | + mDimSurface + ": CREATE"); |
| 11713 | try { |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 11714 | mDimSurface = new Surface(session, 0, |
| 11715 | "DimSurface", |
| 11716 | -1, 16, 16, PixelFormat.OPAQUE, |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11717 | Surface.FX_SURFACE_DIM); |
Maciej Białka | 9ee5c22 | 2010-03-24 10:25:40 +0100 | [diff] [blame] | 11718 | mDimSurface.setAlpha(0.0f); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11719 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11720 | Slog.e(TAG, "Exception creating Dim surface", e); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11721 | } |
| 11722 | } |
| 11723 | } |
| 11724 | |
| 11725 | /** |
| 11726 | * Show the dim surface. |
| 11727 | */ |
| 11728 | void show(int dw, int dh) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11729 | if (!mDimShown) { |
| 11730 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 11731 | dw + "x" + dh + ")"); |
| 11732 | mDimShown = true; |
| 11733 | try { |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11734 | mLastDimWidth = dw; |
| 11735 | mLastDimHeight = dh; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11736 | mDimSurface.setPosition(0, 0); |
| 11737 | mDimSurface.setSize(dw, dh); |
| 11738 | mDimSurface.show(); |
| 11739 | } catch (RuntimeException e) { |
| 11740 | Slog.w(TAG, "Failure showing dim surface", e); |
| 11741 | } |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11742 | } else if (mLastDimWidth != dw || mLastDimHeight != dh) { |
| 11743 | mLastDimWidth = dw; |
| 11744 | mLastDimHeight = dh; |
| 11745 | mDimSurface.setSize(dw, dh); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11746 | } |
| 11747 | } |
| 11748 | |
| 11749 | /** |
| 11750 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 11751 | * {@link updateSurface} after all windows are examined. |
| 11752 | */ |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 11753 | void updateParameters(Resources res, WindowState w, long currentTime) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11754 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 11755 | |
| 11756 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11757 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11758 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11759 | if (mDimTargetAlpha != target) { |
| 11760 | // If the desired dim level has changed, then |
| 11761 | // start an animation to it. |
| 11762 | mLastDimAnimTime = currentTime; |
| 11763 | long duration = (w.mAnimating && w.mAnimation != null) |
| 11764 | ? w.mAnimation.computeDurationHint() |
| 11765 | : DEFAULT_DIM_DURATION; |
| 11766 | if (target > mDimTargetAlpha) { |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 11767 | TypedValue tv = new TypedValue(); |
| 11768 | res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration, |
| 11769 | tv, true); |
| 11770 | if (tv.type == TypedValue.TYPE_FRACTION) { |
| 11771 | duration = (long)tv.getFraction((float)duration, (float)duration); |
| 11772 | } else if (tv.type >= TypedValue.TYPE_FIRST_INT |
| 11773 | && tv.type <= TypedValue.TYPE_LAST_INT) { |
| 11774 | duration = tv.data; |
| 11775 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11776 | } |
| 11777 | if (duration < 1) { |
| 11778 | // Don't divide by zero |
| 11779 | duration = 1; |
| 11780 | } |
| 11781 | mDimTargetAlpha = target; |
| 11782 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 11783 | } |
| 11784 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11785 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11786 | /** |
| 11787 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 11788 | * false when the animation is finished and the dim surface is hidden. |
| 11789 | */ |
| 11790 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 11791 | if (!dimming) { |
| 11792 | if (mDimTargetAlpha != 0) { |
| 11793 | mLastDimAnimTime = currentTime; |
| 11794 | mDimTargetAlpha = 0; |
| 11795 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 11796 | } |
| 11797 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11798 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11799 | boolean animating = false; |
| 11800 | if (mLastDimAnimTime != 0) { |
| 11801 | mDimCurrentAlpha += mDimDeltaPerMs |
| 11802 | * (currentTime-mLastDimAnimTime); |
| 11803 | boolean more = true; |
| 11804 | if (displayFrozen) { |
| 11805 | // If the display is frozen, there is no reason to animate. |
| 11806 | more = false; |
| 11807 | } else if (mDimDeltaPerMs > 0) { |
| 11808 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 11809 | more = false; |
| 11810 | } |
| 11811 | } else if (mDimDeltaPerMs < 0) { |
| 11812 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 11813 | more = false; |
| 11814 | } |
| 11815 | } else { |
| 11816 | more = false; |
| 11817 | } |
| 11818 | |
| 11819 | // Do we need to continue animating? |
| 11820 | if (more) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11821 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11822 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 11823 | mLastDimAnimTime = currentTime; |
| 11824 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11825 | animating = true; |
| 11826 | } else { |
| 11827 | mDimCurrentAlpha = mDimTargetAlpha; |
| 11828 | mLastDimAnimTime = 0; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11829 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11830 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 11831 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11832 | if (!dimming) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11833 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11834 | + ": HIDE"); |
| 11835 | try { |
| 11836 | mDimSurface.hide(); |
| 11837 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11838 | Slog.w(TAG, "Illegal argument exception hiding dim surface"); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11839 | } |
| 11840 | mDimShown = false; |
| 11841 | } |
| 11842 | } |
| 11843 | } |
| 11844 | return animating; |
| 11845 | } |
| 11846 | |
| 11847 | public void printTo(PrintWriter pw) { |
| 11848 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 11849 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 11850 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 11851 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 11852 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 11853 | } |
| 11854 | } |
| 11855 | |
| 11856 | /** |
| 11857 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 11858 | * This is used for opening/closing transition for apps in compatible mode. |
| 11859 | */ |
| 11860 | private static class FadeInOutAnimation extends Animation { |
| 11861 | int mWidth; |
| 11862 | boolean mFadeIn; |
| 11863 | |
| 11864 | public FadeInOutAnimation(boolean fadeIn) { |
| 11865 | setInterpolator(new AccelerateInterpolator()); |
| 11866 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 11867 | mFadeIn = fadeIn; |
| 11868 | } |
| 11869 | |
| 11870 | @Override |
| 11871 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 11872 | float x = interpolatedTime; |
| 11873 | if (!mFadeIn) { |
| 11874 | x = 1.0f - x; // reverse the interpolation for fade out |
| 11875 | } |
| 11876 | if (x < 0.5) { |
| 11877 | // move the window out of the screen. |
| 11878 | t.getMatrix().setTranslate(mWidth, 0); |
| 11879 | } else { |
| 11880 | t.getMatrix().setTranslate(0, 0);// show |
| 11881 | t.setAlpha((x - 0.5f) * 2); |
| 11882 | } |
| 11883 | } |
| 11884 | |
| 11885 | @Override |
| 11886 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 11887 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 11888 | mWidth = width; |
| 11889 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11890 | |
| 11891 | @Override |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 11892 | public int getZAdjustment() { |
| 11893 | return Animation.ZORDER_TOP; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11894 | } |
| 11895 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11896 | } |