| 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; |
| Joe Onorato | ac0ee89 | 2011-01-30 15:38:30 -0800 | [diff] [blame] | 50 | import android.app.StatusBarManager; |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 51 | import android.app.admin.DevicePolicyManager; |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 52 | import android.content.BroadcastReceiver; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 53 | import android.content.ClipData; |
| 54 | import android.content.ClipDescription; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | import android.content.Context; |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 56 | import android.content.Intent; |
| 57 | import android.content.IntentFilter; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | import android.content.pm.ActivityInfo; |
| 59 | import android.content.pm.PackageManager; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 60 | import android.content.res.CompatibilityInfo; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | import android.content.res.Configuration; |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 62 | import android.content.res.Resources; |
| Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 63 | import android.graphics.Bitmap; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 64 | import android.graphics.Canvas; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | import android.graphics.Matrix; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 66 | import android.graphics.Paint; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | import android.graphics.PixelFormat; |
| Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 68 | import android.graphics.PorterDuff; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | import android.graphics.Rect; |
| 70 | import android.graphics.Region; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 71 | import android.graphics.Typeface; |
| 72 | import android.graphics.Paint.FontMetricsInt; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | import android.os.BatteryStats; |
| 74 | import android.os.Binder; |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 75 | import android.os.Bundle; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | import android.os.Debug; |
| 77 | import android.os.Handler; |
| 78 | import android.os.IBinder; |
| 79 | import android.os.LocalPowerManager; |
| 80 | import android.os.Looper; |
| 81 | import android.os.Message; |
| 82 | import android.os.Parcel; |
| 83 | import android.os.ParcelFileDescriptor; |
| 84 | import android.os.Power; |
| 85 | import android.os.PowerManager; |
| 86 | import android.os.Process; |
| 87 | import android.os.RemoteException; |
| 88 | import android.os.ServiceManager; |
| Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 89 | import android.os.StrictMode; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | import android.os.SystemClock; |
| 91 | import android.os.SystemProperties; |
| 92 | import android.os.TokenWatcher; |
| 93 | import android.provider.Settings; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 94 | import android.util.DisplayMetrics; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | import android.util.EventLog; |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 96 | import android.util.Log; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 97 | import android.util.Slog; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | import android.util.SparseIntArray; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 99 | import android.util.TypedValue; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | import android.view.Display; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 101 | import android.view.DragEvent; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | import android.view.Gravity; |
| 103 | import android.view.IApplicationToken; |
| 104 | import android.view.IOnKeyguardExitResult; |
| 105 | import android.view.IRotationWatcher; |
| 106 | import android.view.IWindow; |
| 107 | import android.view.IWindowManager; |
| 108 | import android.view.IWindowSession; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 109 | import android.view.InputChannel; |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 110 | import android.view.InputDevice; |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 111 | import android.view.InputEvent; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 112 | import android.view.InputHandler; |
| 113 | import android.view.InputQueue; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | import android.view.KeyEvent; |
| 115 | import android.view.MotionEvent; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | import android.view.Surface; |
| 117 | import android.view.SurfaceSession; |
| 118 | import android.view.View; |
| 119 | import android.view.ViewTreeObserver; |
| 120 | import android.view.WindowManager; |
| 121 | import android.view.WindowManagerImpl; |
| 122 | import android.view.WindowManagerPolicy; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 123 | import android.view.Surface.OutOfResourcesException; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | import android.view.WindowManager.LayoutParams; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 125 | import android.view.animation.AccelerateInterpolator; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | import android.view.animation.Animation; |
| 127 | import android.view.animation.AnimationUtils; |
| 128 | import android.view.animation.Transformation; |
| 129 | |
| 130 | import java.io.BufferedWriter; |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 131 | import java.io.DataInputStream; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | import java.io.File; |
| 133 | import java.io.FileDescriptor; |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 134 | import java.io.FileInputStream; |
| 135 | import java.io.FileNotFoundException; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | import java.io.IOException; |
| 137 | import java.io.OutputStream; |
| 138 | import java.io.OutputStreamWriter; |
| 139 | import java.io.PrintWriter; |
| 140 | import java.io.StringWriter; |
| 141 | import java.net.Socket; |
| 142 | import java.util.ArrayList; |
| 143 | import java.util.HashMap; |
| 144 | import java.util.HashSet; |
| 145 | import java.util.Iterator; |
| 146 | import java.util.List; |
| 147 | |
| 148 | /** {@hide} */ |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 149 | public class WindowManagerService extends IWindowManager.Stub |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 150 | implements Watchdog.Monitor { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | static final String TAG = "WindowManager"; |
| 152 | static final boolean DEBUG = false; |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 153 | static final boolean DEBUG_ADD_REMOVE = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | static final boolean DEBUG_FOCUS = false; |
| 155 | static final boolean DEBUG_ANIM = false; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 156 | static final boolean DEBUG_LAYOUT = false; |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 157 | static final boolean DEBUG_RESIZE = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | static final boolean DEBUG_LAYERS = false; |
| 159 | static final boolean DEBUG_INPUT = false; |
| 160 | static final boolean DEBUG_INPUT_METHOD = false; |
| 161 | static final boolean DEBUG_VISIBILITY = false; |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 162 | static final boolean DEBUG_WINDOW_MOVEMENT = false; |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 163 | static final boolean DEBUG_TOKEN_MOVEMENT = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | static final boolean DEBUG_ORIENTATION = false; |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 165 | static final boolean DEBUG_CONFIGURATION = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 167 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 168 | static final boolean DEBUG_REORDER = false; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 169 | static final boolean DEBUG_WALLPAPER = false; |
| Christopher Tate | 994ef92 | 2011-01-12 20:06:07 -0800 | [diff] [blame] | 170 | static final boolean DEBUG_DRAG = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | static final boolean SHOW_TRANSACTIONS = false; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 172 | static final boolean HIDE_STACK_CRAWLS = true; |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 173 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | static final boolean PROFILE_ORIENTATION = false; |
| 175 | static final boolean BLUR = true; |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 176 | static final boolean localLOGV = DEBUG; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 177 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | /** How much to multiply the policy's type layer, to reserve room |
| 179 | * for multiple windows of the same type and Z-ordering adjustment |
| 180 | * with TYPE_LAYER_OFFSET. */ |
| 181 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 182 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 184 | * or below others in the same layer. */ |
| 185 | static final int TYPE_LAYER_OFFSET = 1000; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 186 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | /** How much to increment the layer for each window, to reserve room |
| 188 | * for effect surfaces between them. |
| 189 | */ |
| 190 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 191 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 192 | /** The maximum length we will accept for a loaded animation duration: |
| 193 | * this is 10 seconds. |
| 194 | */ |
| 195 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 196 | |
| 197 | /** Amount of time (in milliseconds) to animate the dim surface from one |
| 198 | * value to another, when no window animation is driving it. |
| 199 | */ |
| 200 | static final int DEFAULT_DIM_DURATION = 200; |
| 201 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 202 | /** Amount of time (in milliseconds) to animate the fade-in-out transition for |
| 203 | * compatible windows. |
| 204 | */ |
| 205 | static final int DEFAULT_FADE_IN_OUT_DURATION = 400; |
| 206 | |
| Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 207 | /** |
| 208 | * If true, the window manager will do its own custom freezing and general |
| 209 | * management of the screen during rotation. |
| 210 | */ |
| 211 | static final boolean CUSTOM_SCREEN_ROTATION = true; |
| 212 | |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 213 | // Maximum number of milliseconds to wait for input event injection. |
| 214 | // FIXME is this value reasonable? |
| 215 | private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000; |
| Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 216 | |
| 217 | // Maximum number of milliseconds to wait for input devices to be enumerated before |
| 218 | // proceding with safe mode detection. |
| 219 | 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] | 220 | |
| 221 | // Default input dispatching timeout in nanoseconds. |
| 222 | private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 223 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 225 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 226 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 227 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 228 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | private static final String SYSTEM_SECURE = "ro.secure"; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 230 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | |
| 232 | /** |
| 233 | * Condition waited on by {@link #reenableKeyguard} to know the call to |
| 234 | * the window policy has finished. |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 235 | * This is set to true only if mKeyguardTokenWatcher.acquired() has |
| 236 | * actually disabled the keyguard. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | */ |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 238 | private boolean mKeyguardDisabled = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 240 | private static final int ALLOW_DISABLE_YES = 1; |
| 241 | private static final int ALLOW_DISABLE_NO = 0; |
| 242 | private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager |
| 243 | private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher |
| 244 | |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 245 | final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher( |
| 246 | new Handler(), "WindowManagerService.mKeyguardTokenWatcher") { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | public void acquired() { |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 248 | if (shouldAllowDisableKeyguard()) { |
| 249 | mPolicy.enableKeyguard(false); |
| 250 | mKeyguardDisabled = true; |
| 251 | } else { |
| 252 | Log.v(TAG, "Not disabling keyguard since device policy is enforced"); |
| 253 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | } |
| 255 | public void released() { |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 256 | mPolicy.enableKeyguard(true); |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 257 | synchronized (mKeyguardTokenWatcher) { |
| 258 | mKeyguardDisabled = false; |
| 259 | mKeyguardTokenWatcher.notifyAll(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | } |
| 261 | } |
| 262 | }; |
| 263 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 264 | final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 265 | @Override |
| 266 | public void onReceive(Context context, Intent intent) { |
| 267 | mPolicy.enableKeyguard(true); |
| 268 | synchronized(mKeyguardTokenWatcher) { |
| 269 | // lazily evaluate this next time we're asked to disable keyguard |
| 270 | mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; |
| 271 | mKeyguardDisabled = false; |
| 272 | } |
| 273 | } |
| 274 | }; |
| 275 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 276 | final Context mContext; |
| 277 | |
| 278 | final boolean mHaveInputMethods; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 279 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 280 | final boolean mLimitedAlphaCompositing; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 281 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 282 | final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 283 | |
| 284 | final IActivityManager mActivityManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 285 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | final IBatteryStats mBatteryStats; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 287 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 288 | /** |
| 289 | * All currently active sessions with clients. |
| 290 | */ |
| 291 | final HashSet<Session> mSessions = new HashSet<Session>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 292 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 293 | /** |
| 294 | * Mapping from an IWindow IBinder to the server's Window object. |
| 295 | * This is also used as the lock for all of our state. |
| 296 | */ |
| 297 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 298 | |
| 299 | /** |
| 300 | * Mapping from a token IBinder to a WindowToken object. |
| 301 | */ |
| 302 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 303 | new HashMap<IBinder, WindowToken>(); |
| 304 | |
| 305 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 306 | * Window tokens that are in the process of exiting, but still |
| 307 | * on screen for animations. |
| 308 | */ |
| 309 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 310 | |
| 311 | /** |
| 312 | * Z-ordered (bottom-most first) list of all application tokens, for |
| 313 | * controlling the ordering of windows in different applications. This |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 314 | * contains AppWindowToken objects. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 315 | */ |
| 316 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
| 317 | |
| 318 | /** |
| 319 | * Application tokens that are in the process of exiting, but still |
| 320 | * on screen for animations. |
| 321 | */ |
| 322 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 323 | |
| 324 | /** |
| 325 | * List of window tokens that have finished starting their application, |
| 326 | * and now need to have the policy remove their windows. |
| 327 | */ |
| 328 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 329 | |
| 330 | /** |
| 331 | * Z-ordered (bottom-most first) list of all Window objects. |
| 332 | */ |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 333 | final ArrayList<WindowState> mWindows = new ArrayList<WindowState>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 334 | |
| 335 | /** |
| 336 | * Windows that are being resized. Used so we can tell the client about |
| 337 | * the resize after closing the transaction in which we resized the |
| 338 | * underlying surface. |
| 339 | */ |
| 340 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 341 | |
| 342 | /** |
| 343 | * Windows whose animations have ended and now must be removed. |
| 344 | */ |
| 345 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 346 | |
| 347 | /** |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 348 | * Used when processing mPendingRemove to avoid working on the original array. |
| 349 | */ |
| 350 | WindowState[] mPendingRemoveTmp = new WindowState[20]; |
| 351 | |
| 352 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 353 | * Windows whose surface should be destroyed. |
| 354 | */ |
| 355 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 356 | |
| 357 | /** |
| 358 | * Windows that have lost input focus and are waiting for the new |
| 359 | * focus window to be displayed before they are told about this. |
| 360 | */ |
| 361 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 362 | |
| 363 | /** |
| 364 | * This is set when we have run out of memory, and will either be an empty |
| 365 | * list or contain windows that need to be force removed. |
| 366 | */ |
| 367 | ArrayList<WindowState> mForceRemoves; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 368 | |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 369 | /** |
| 370 | * Used when rebuilding window list to keep track of windows that have |
| 371 | * been removed. |
| 372 | */ |
| 373 | WindowState[] mRebuildTmp = new WindowState[20]; |
| 374 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 375 | IInputMethodManager mInputMethodManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 376 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 377 | SurfaceSession mFxSession; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 378 | private DimAnimator mDimAnimator = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 379 | Surface mBlurSurface; |
| 380 | boolean mBlurShown; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 381 | Watermark mWatermark; |
| Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 382 | StrictModeFlash mStrictModeFlash; |
| Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 383 | ScreenRotationAnimation mScreenRotationAnimation; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 384 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 385 | int mTransactionSequence = 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 386 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 387 | final float[] mTmpFloats = new float[9]; |
| 388 | |
| 389 | boolean mSafeMode; |
| 390 | boolean mDisplayEnabled = false; |
| 391 | boolean mSystemBooted = false; |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 392 | int mInitialDisplayWidth = 0; |
| 393 | int mInitialDisplayHeight = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 394 | int mRotation = 0; |
| 395 | int mRequestedRotation = 0; |
| 396 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 397 | int mLastRotationFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 398 | ArrayList<IRotationWatcher> mRotationWatchers |
| 399 | = new ArrayList<IRotationWatcher>(); |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 400 | int mDeferredRotation; |
| 401 | int mDeferredRotationAnimFlags; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 402 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 403 | boolean mLayoutNeeded = true; |
| 404 | boolean mAnimationPending = false; |
| 405 | boolean mDisplayFrozen = false; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 406 | boolean mWaitingForConfig = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 407 | boolean mWindowsFreezingScreen = false; |
| 408 | long mFreezeGcPending = 0; |
| 409 | int mAppsFreezingScreen = 0; |
| 410 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 411 | int mLayoutSeq = 0; |
| 412 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 413 | // State while inside of layoutAndPlaceSurfacesLocked(). |
| 414 | boolean mFocusMayChange; |
| 415 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 416 | Configuration mCurConfiguration = new Configuration(); |
| 417 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | // This is held as long as we have the screen frozen, to give us time to |
| 419 | // perform a rotation animation when turning off shows the lock screen which |
| 420 | // changes the orientation. |
| 421 | PowerManager.WakeLock mScreenFrozenLock; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 422 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | // State management of app transitions. When we are preparing for a |
| 424 | // transition, mNextAppTransition will be the kind of transition to |
| 425 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 426 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 427 | // made visible or hidden at the next transition. |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 428 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 429 | String mNextAppTransitionPackage; |
| 430 | int mNextAppTransitionEnter; |
| 431 | int mNextAppTransitionExit; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 432 | boolean mAppTransitionReady = false; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 433 | boolean mAppTransitionRunning = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 434 | boolean mAppTransitionTimeout = false; |
| 435 | boolean mStartingIconInTransition = false; |
| 436 | boolean mSkipAppTransitionAnimation = false; |
| 437 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 438 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 439 | final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>(); |
| 440 | final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 441 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 442 | Display mDisplay; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 443 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | H mH = new H(); |
| 445 | |
| 446 | WindowState mCurrentFocus = null; |
| 447 | WindowState mLastFocus = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 448 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 449 | // This just indicates the window the input method is on top of, not |
| 450 | // necessarily the window its input is going to. |
| 451 | WindowState mInputMethodTarget = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 452 | boolean mInputMethodTargetWaitingAnim; |
| 453 | int mInputMethodAnimLayerAdjustment; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 454 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 455 | WindowState mInputMethodWindow = null; |
| 456 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 457 | |
| Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 458 | boolean mHardKeyboardAvailable; |
| 459 | boolean mHardKeyboardEnabled; |
| 460 | OnHardKeyboardStatusChangeListener mHardKeyboardStatusChangeListener; |
| 461 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 462 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 463 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 464 | // If non-null, this is the currently visible window that is associated |
| 465 | // with the wallpaper. |
| 466 | WindowState mWallpaperTarget = null; |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 467 | // If non-null, we are in the middle of animating from one wallpaper target |
| 468 | // to another, and this is the lower one in Z-order. |
| 469 | WindowState mLowerWallpaperTarget = null; |
| 470 | // If non-null, we are in the middle of animating from one wallpaper target |
| 471 | // to another, and this is the higher one in Z-order. |
| 472 | WindowState mUpperWallpaperTarget = null; |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 473 | // Window currently running an animation that has requested it be detached |
| 474 | // from the wallpaper. This means we need to ensure the wallpaper is |
| 475 | // visible behind it in case it animates in a way that would allow it to be |
| 476 | // seen. |
| 477 | WindowState mWindowDetachedWallpaper = null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 478 | int mWallpaperAnimLayerAdjustment; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 479 | float mLastWallpaperX = -1; |
| 480 | float mLastWallpaperY = -1; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 481 | float mLastWallpaperXStep = -1; |
| 482 | float mLastWallpaperYStep = -1; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 483 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 484 | // changing its scroll position. |
| 485 | WindowState mWaitingOnWallpaper; |
| 486 | // The last time we had a timeout when waiting for a wallpaper. |
| 487 | long mLastWallpaperTimeoutTime; |
| 488 | // We give a wallpaper up to 150ms to finish scrolling. |
| 489 | static final long WALLPAPER_TIMEOUT = 150; |
| 490 | // Time we wait after a timeout before trying to wait again. |
| 491 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 492 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 493 | AppWindowToken mFocusedApp = null; |
| 494 | |
| 495 | PowerManagerService mPowerManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 496 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 497 | float mWindowAnimationScale = 1.0f; |
| 498 | float mTransitionAnimationScale = 1.0f; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 499 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 500 | final InputManager mInputManager; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 501 | |
| 502 | // Who is holding the screen on. |
| 503 | Session mHoldingScreenOn; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 504 | PowerManager.WakeLock mHoldingScreenWakeLock; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 505 | |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 506 | boolean mTurnOnScreen; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 507 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 508 | /** |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 509 | * Drag/drop state |
| 510 | */ |
| 511 | class DragState { |
| 512 | IBinder mToken; |
| 513 | Surface mSurface; |
| Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 514 | int mFlags; |
| Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 515 | IBinder mLocalWin; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 516 | ClipData mData; |
| 517 | ClipDescription mDataDescription; |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 518 | boolean mDragResult; |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 519 | float mCurrentX, mCurrentY; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 520 | float mThumbOffsetX, mThumbOffsetY; |
| 521 | InputChannel mServerChannel, mClientChannel; |
| 522 | WindowState mTargetWindow; |
| 523 | ArrayList<WindowState> mNotifiedWindows; |
| Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 524 | boolean mDragInProgress; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 525 | |
| Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 526 | private final Region mTmpRegion = new Region(); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 527 | |
| Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 528 | DragState(IBinder token, Surface surface, int flags, IBinder localWin) { |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 529 | mToken = token; |
| 530 | mSurface = surface; |
| Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 531 | mFlags = flags; |
| Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 532 | mLocalWin = localWin; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 533 | mNotifiedWindows = new ArrayList<WindowState>(); |
| 534 | } |
| 535 | |
| 536 | void reset() { |
| 537 | if (mSurface != null) { |
| 538 | mSurface.destroy(); |
| 539 | } |
| 540 | mSurface = null; |
| Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 541 | mFlags = 0; |
| Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 542 | mLocalWin = null; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 543 | mToken = null; |
| 544 | mData = null; |
| 545 | mThumbOffsetX = mThumbOffsetY = 0; |
| 546 | mNotifiedWindows = null; |
| 547 | } |
| 548 | |
| 549 | void register() { |
| 550 | if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel"); |
| 551 | if (mClientChannel != null) { |
| 552 | Slog.e(TAG, "Duplicate register of drag input channel"); |
| 553 | } else { |
| 554 | InputChannel[] channels = InputChannel.openInputChannelPair("drag"); |
| 555 | mServerChannel = channels[0]; |
| 556 | mClientChannel = channels[1]; |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 557 | mInputManager.registerInputChannel(mServerChannel, null); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 558 | InputQueue.registerInputChannel(mClientChannel, mDragInputHandler, |
| 559 | mH.getLooper().getQueue()); |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | void unregister() { |
| 564 | if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel"); |
| 565 | if (mClientChannel == null) { |
| 566 | Slog.e(TAG, "Unregister of nonexistent drag input channel"); |
| 567 | } else { |
| 568 | mInputManager.unregisterInputChannel(mServerChannel); |
| 569 | InputQueue.unregisterInputChannel(mClientChannel); |
| 570 | mClientChannel.dispose(); |
| Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 571 | mServerChannel.dispose(); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 572 | mClientChannel = null; |
| 573 | mServerChannel = null; |
| 574 | } |
| 575 | } |
| 576 | |
| Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 577 | int getDragLayerLw() { |
| 578 | return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG) |
| 579 | * TYPE_LAYER_MULTIPLIER |
| 580 | + TYPE_LAYER_OFFSET; |
| 581 | } |
| 582 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 583 | /* call out to each visible window/session informing it about the drag |
| 584 | */ |
| Chris Tate | b8203e9 | 2010-10-12 14:23:21 -0700 | [diff] [blame] | 585 | void broadcastDragStartedLw(final float touchX, final float touchY) { |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 586 | // Cache a base-class instance of the clip metadata so that parceling |
| 587 | // works correctly in calling out to the apps. |
| Christopher Tate | 1fc014f | 2011-01-19 12:56:26 -0800 | [diff] [blame] | 588 | mDataDescription = (mData != null) ? mData.getDescription() : null; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 589 | mNotifiedWindows.clear(); |
| Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 590 | mDragInProgress = true; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 591 | |
| 592 | if (DEBUG_DRAG) { |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 593 | Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")"); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 594 | } |
| 595 | |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 596 | final int N = mWindows.size(); |
| 597 | for (int i = 0; i < N; i++) { |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 598 | sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 599 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the |
| 603 | * designated window is potentially a drop recipient. There are race situations |
| 604 | * around DRAG_ENDED broadcast, so we make sure that once we've declared that |
| 605 | * 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] | 606 | * |
| 607 | * This method clones the 'event' parameter if it's being delivered to the same |
| 608 | * 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] | 609 | */ |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 610 | private void sendDragStartedLw(WindowState newWin, float touchX, float touchY, |
| 611 | ClipDescription desc) { |
| Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 612 | // Don't actually send the event if the drag is supposed to be pinned |
| 613 | // to the originating window but 'newWin' is not that window. |
| Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 614 | if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) { |
| Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 615 | final IBinder winBinder = newWin.mClient.asBinder(); |
| 616 | if (winBinder != mLocalWin) { |
| 617 | if (DEBUG_DRAG) { |
| 618 | Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin); |
| 619 | } |
| 620 | return; |
| 621 | } |
| 622 | } |
| 623 | |
| Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 624 | if (mDragInProgress && newWin.isPotentialDragTarget()) { |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 625 | DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED, |
| 626 | touchX - newWin.mFrame.left, touchY - newWin.mFrame.top, |
| Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 627 | null, desc, null, false); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 628 | try { |
| 629 | newWin.mClient.dispatchDragEvent(event); |
| 630 | // track each window that we've notified that the drag is starting |
| 631 | mNotifiedWindows.add(newWin); |
| 632 | } catch (RemoteException e) { |
| 633 | Slog.w(TAG, "Unable to drag-start window " + newWin); |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 634 | } finally { |
| 635 | // if the callee was local, the dispatch has already recycled the event |
| 636 | if (Process.myPid() != newWin.mSession.mPid) { |
| 637 | event.recycle(); |
| 638 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 639 | } |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | /* helper - construct and send a DRAG_STARTED event only if the window has not |
| 644 | * previously been notified, i.e. it became visible after the drag operation |
| 645 | * was begun. This is a rare case. |
| 646 | */ |
| 647 | private void sendDragStartedIfNeededLw(WindowState newWin) { |
| Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 648 | if (mDragInProgress) { |
| 649 | // If we have sent the drag-started, we needn't do so again |
| 650 | for (WindowState ws : mNotifiedWindows) { |
| 651 | if (ws == newWin) { |
| 652 | return; |
| 653 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 654 | } |
| Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 655 | if (DEBUG_DRAG) { |
| Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 656 | Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin); |
| Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 657 | } |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 658 | sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 659 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 660 | } |
| 661 | |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 662 | void broadcastDragEndedLw() { |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 663 | if (DEBUG_DRAG) { |
| 664 | Slog.d(TAG, "broadcasting DRAG_ENDED"); |
| 665 | } |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 666 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED, |
| Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 667 | 0, 0, null, null, null, mDragResult); |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 668 | for (WindowState ws: mNotifiedWindows) { |
| 669 | try { |
| 670 | ws.mClient.dispatchDragEvent(evt); |
| 671 | } catch (RemoteException e) { |
| 672 | Slog.w(TAG, "Unable to drag-end window " + ws); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 673 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 674 | } |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 675 | mNotifiedWindows.clear(); |
| 676 | mDragInProgress = false; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 677 | evt.recycle(); |
| 678 | } |
| 679 | |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 680 | void endDragLw() { |
| 681 | mDragState.broadcastDragEndedLw(); |
| 682 | |
| 683 | // stop intercepting input |
| 684 | mDragState.unregister(); |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 685 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 686 | |
| 687 | // free our resources and drop all the object references |
| 688 | mDragState.reset(); |
| 689 | mDragState = null; |
| Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 690 | |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 691 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-drag rotation"); |
| 692 | boolean changed = setRotationUncheckedLocked( |
| 693 | WindowManagerPolicy.USE_LAST_ROTATION, 0, false); |
| 694 | if (changed) { |
| Dianne Hackborn | 3e4f9d04 | 2011-02-04 14:05:55 -0800 | [diff] [blame^] | 695 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 696 | } |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 697 | } |
| 698 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 699 | void notifyMoveLw(float x, float y) { |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 700 | final int myPid = Process.myPid(); |
| 701 | |
| 702 | // Move the surface to the given touch |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 703 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION notifyMoveLw"); |
| Christopher Tate | f01af75 | 2011-01-19 16:22:07 -0800 | [diff] [blame] | 704 | Surface.openTransaction(); |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 705 | try { |
| 706 | mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY)); |
| Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 707 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DRAG " |
| 708 | + mSurface + ": pos=(" + |
| 709 | (int)(x - mThumbOffsetX) + "," + (int)(y - mThumbOffsetY) + ")"); |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 710 | } finally { |
| Christopher Tate | f01af75 | 2011-01-19 16:22:07 -0800 | [diff] [blame] | 711 | Surface.closeTransaction(); |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 712 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION notifyMoveLw"); |
| 713 | } |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 714 | |
| 715 | // Tell the affected window |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 716 | WindowState touchedWin = getTouchedWinAtPointLw(x, y); |
| Christopher Tate | f01af75 | 2011-01-19 16:22:07 -0800 | [diff] [blame] | 717 | if (touchedWin == null) { |
| 718 | if (DEBUG_DRAG) Slog.d(TAG, "No touched win at x=" + x + " y=" + y); |
| 719 | return; |
| 720 | } |
| Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 721 | if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) { |
| Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 722 | final IBinder touchedBinder = touchedWin.mClient.asBinder(); |
| 723 | if (touchedBinder != mLocalWin) { |
| 724 | // This drag is pinned only to the originating window, but the drag |
| 725 | // point is outside that window. Pretend it's over empty space. |
| 726 | touchedWin = null; |
| 727 | } |
| 728 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 729 | try { |
| 730 | // have we dragged over a new window? |
| 731 | if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) { |
| 732 | if (DEBUG_DRAG) { |
| 733 | Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow); |
| 734 | } |
| 735 | // force DRAG_EXITED_EVENT if appropriate |
| 736 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED, |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 737 | x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top, |
| Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 738 | null, null, null, false); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 739 | mTargetWindow.mClient.dispatchDragEvent(evt); |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 740 | if (myPid != mTargetWindow.mSession.mPid) { |
| 741 | evt.recycle(); |
| 742 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 743 | } |
| 744 | if (touchedWin != null) { |
| Chris Tate | 9d1ab88 | 2010-11-02 15:55:39 -0700 | [diff] [blame] | 745 | if (false && DEBUG_DRAG) { |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 746 | Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin); |
| 747 | } |
| 748 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION, |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 749 | x - touchedWin.mFrame.left, y - touchedWin.mFrame.top, |
| Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 750 | null, null, null, false); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 751 | touchedWin.mClient.dispatchDragEvent(evt); |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 752 | if (myPid != touchedWin.mSession.mPid) { |
| 753 | evt.recycle(); |
| 754 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 755 | } |
| 756 | } catch (RemoteException e) { |
| 757 | Slog.w(TAG, "can't send drag notification to windows"); |
| 758 | } |
| 759 | mTargetWindow = touchedWin; |
| 760 | } |
| 761 | |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 762 | // Tell the drop target about the data. Returns 'true' if we can immediately |
| 763 | // dispatch the global drag-ended message, 'false' if we need to wait for a |
| 764 | // result from the recipient. |
| 765 | boolean notifyDropLw(float x, float y) { |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 766 | WindowState touchedWin = getTouchedWinAtPointLw(x, y); |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 767 | if (touchedWin == null) { |
| 768 | // "drop" outside a valid window -- no recipient to apply a |
| 769 | // timeout to, and we can send the drag-ended message immediately. |
| 770 | mDragResult = false; |
| 771 | return true; |
| 772 | } |
| 773 | |
| 774 | if (DEBUG_DRAG) { |
| 775 | Slog.d(TAG, "sending DROP to " + touchedWin); |
| 776 | } |
| 777 | final int myPid = Process.myPid(); |
| 778 | final IBinder token = touchedWin.mClient.asBinder(); |
| 779 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP, |
| 780 | x - touchedWin.mFrame.left, y - touchedWin.mFrame.top, |
| Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 781 | null, null, mData, false); |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 782 | try { |
| 783 | touchedWin.mClient.dispatchDragEvent(evt); |
| 784 | |
| 785 | // 5 second timeout for this window to respond to the drop |
| 786 | mH.removeMessages(H.DRAG_END_TIMEOUT, token); |
| 787 | Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token); |
| 788 | mH.sendMessageDelayed(msg, 5000); |
| 789 | } catch (RemoteException e) { |
| 790 | Slog.w(TAG, "can't send drop notification to win " + touchedWin); |
| 791 | return true; |
| 792 | } finally { |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 793 | if (myPid != touchedWin.mSession.mPid) { |
| 794 | evt.recycle(); |
| 795 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 796 | } |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 797 | mToken = token; |
| 798 | return false; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | // Find the visible, touch-deliverable window under the given point |
| 802 | private WindowState getTouchedWinAtPointLw(float xf, float yf) { |
| 803 | WindowState touchedWin = null; |
| 804 | final int x = (int) xf; |
| 805 | final int y = (int) yf; |
| 806 | final ArrayList<WindowState> windows = mWindows; |
| 807 | final int N = windows.size(); |
| 808 | for (int i = N - 1; i >= 0; i--) { |
| 809 | WindowState child = windows.get(i); |
| 810 | final int flags = child.mAttrs.flags; |
| 811 | if (!child.isVisibleLw()) { |
| 812 | // not visible == don't tell about drags |
| 813 | continue; |
| 814 | } |
| 815 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 816 | // not touchable == don't tell about drags |
| 817 | continue; |
| 818 | } |
| Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 819 | |
| 820 | child.getTouchableRegion(mTmpRegion); |
| 821 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 822 | final int touchFlags = flags & |
| Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 823 | (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 824 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
| 825 | if (mTmpRegion.contains(x, y) || touchFlags == 0) { |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 826 | // Found it |
| 827 | touchedWin = child; |
| 828 | break; |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | return touchedWin; |
| 833 | } |
| 834 | } |
| 835 | |
| 836 | DragState mDragState = null; |
| 837 | private final InputHandler mDragInputHandler = new BaseInputHandler() { |
| 838 | @Override |
| Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 839 | public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) { |
| 840 | boolean handled = false; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 841 | try { |
| Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 842 | if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0 |
| 843 | && mDragState != null) { |
| 844 | boolean endDrag = false; |
| 845 | final float newX = event.getRawX(); |
| 846 | final float newY = event.getRawY(); |
| 847 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 848 | switch (event.getAction()) { |
| 849 | case MotionEvent.ACTION_DOWN: { |
| 850 | if (DEBUG_DRAG) { |
| 851 | Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer"); |
| 852 | } |
| 853 | } break; |
| 854 | |
| 855 | case MotionEvent.ACTION_MOVE: { |
| 856 | synchronized (mWindowMap) { |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 857 | // move the surface and tell the involved window(s) where we are |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 858 | mDragState.notifyMoveLw(newX, newY); |
| 859 | } |
| 860 | } break; |
| 861 | |
| 862 | case MotionEvent.ACTION_UP: { |
| 863 | if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at " |
| 864 | + newX + "," + newY); |
| 865 | synchronized (mWindowMap) { |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 866 | endDrag = mDragState.notifyDropLw(newX, newY); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 867 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 868 | } break; |
| 869 | |
| 870 | case MotionEvent.ACTION_CANCEL: { |
| 871 | if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!"); |
| 872 | endDrag = true; |
| 873 | } break; |
| 874 | } |
| 875 | |
| 876 | if (endDrag) { |
| 877 | if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state"); |
| 878 | // tell all the windows that the drag has ended |
| Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 879 | synchronized (mWindowMap) { |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 880 | mDragState.endDragLw(); |
| Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 881 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 882 | } |
| Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 883 | |
| 884 | handled = true; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 885 | } |
| 886 | } catch (Exception e) { |
| 887 | Slog.e(TAG, "Exception caught by drag handleMotion", e); |
| 888 | } finally { |
| Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 889 | finishedCallback.finished(handled); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 890 | } |
| 891 | } |
| 892 | }; |
| 893 | |
| 894 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 895 | * Whether the UI is currently running in touch mode (not showing |
| 896 | * navigational focus because the user is directly pressing the screen). |
| 897 | */ |
| 898 | boolean mInTouchMode = false; |
| 899 | |
| 900 | private ViewServer mViewServer; |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 901 | private ArrayList<WindowChangeListener> mWindowChangeListeners = |
| 902 | new ArrayList<WindowChangeListener>(); |
| 903 | private boolean mWindowsChanged = false; |
| 904 | |
| 905 | public interface WindowChangeListener { |
| 906 | public void windowsChanged(); |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 907 | public void focusChanged(); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 908 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 909 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 910 | final Configuration mTempConfiguration = new Configuration(); |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 911 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 912 | |
| 913 | // The frame use to limit the size of the app running in compatibility mode. |
| 914 | Rect mCompatibleScreenFrame = new Rect(); |
| 915 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 916 | Surface mBackgroundFillerSurface = null; |
| Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 917 | WindowState mBackgroundFillerTarget = null; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 918 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 919 | public static WindowManagerService main(Context context, |
| 920 | PowerManagerService pm, boolean haveInputMethods) { |
| 921 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 922 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 923 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 924 | synchronized (thr) { |
| 925 | while (thr.mService == null) { |
| 926 | try { |
| 927 | thr.wait(); |
| 928 | } catch (InterruptedException e) { |
| 929 | } |
| 930 | } |
| 931 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 932 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 933 | return thr.mService; |
| 934 | } |
| 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 | static class WMThread extends Thread { |
| 937 | WindowManagerService mService; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 938 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 939 | private final Context mContext; |
| 940 | private final PowerManagerService mPM; |
| 941 | private final boolean mHaveInputMethods; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 942 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 943 | public WMThread(Context context, PowerManagerService pm, |
| 944 | boolean haveInputMethods) { |
| 945 | super("WindowManager"); |
| 946 | mContext = context; |
| 947 | mPM = pm; |
| 948 | mHaveInputMethods = haveInputMethods; |
| 949 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 950 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 951 | public void run() { |
| 952 | Looper.prepare(); |
| 953 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 954 | mHaveInputMethods); |
| 955 | android.os.Process.setThreadPriority( |
| 956 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
| Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 957 | android.os.Process.setCanSelfBackground(false); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 958 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 959 | synchronized (this) { |
| 960 | mService = s; |
| 961 | notifyAll(); |
| 962 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 963 | |
| Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 964 | // For debug builds, log event loop stalls to dropbox for analysis. |
| 965 | if (StrictMode.conditionallyEnableDebugLogging()) { |
| 966 | Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper"); |
| 967 | } |
| 968 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 969 | Looper.loop(); |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | static class PolicyThread extends Thread { |
| 974 | private final WindowManagerPolicy mPolicy; |
| 975 | private final WindowManagerService mService; |
| 976 | private final Context mContext; |
| 977 | private final PowerManagerService mPM; |
| 978 | boolean mRunning = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 979 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 980 | public PolicyThread(WindowManagerPolicy policy, |
| 981 | WindowManagerService service, Context context, |
| 982 | PowerManagerService pm) { |
| 983 | super("WindowManagerPolicy"); |
| 984 | mPolicy = policy; |
| 985 | mService = service; |
| 986 | mContext = context; |
| 987 | mPM = pm; |
| 988 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 989 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 990 | public void run() { |
| 991 | Looper.prepare(); |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 992 | WindowManagerPolicyThread.set(this, Looper.myLooper()); |
| 993 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 994 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 995 | // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 996 | android.os.Process.setThreadPriority( |
| 997 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
| Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 998 | android.os.Process.setCanSelfBackground(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 999 | mPolicy.init(mContext, mService, mPM); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1000 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1001 | synchronized (this) { |
| 1002 | mRunning = true; |
| 1003 | notifyAll(); |
| 1004 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1005 | |
| Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 1006 | // For debug builds, log event loop stalls to dropbox for analysis. |
| 1007 | if (StrictMode.conditionallyEnableDebugLogging()) { |
| 1008 | Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper"); |
| 1009 | } |
| 1010 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1011 | Looper.loop(); |
| 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | private WindowManagerService(Context context, PowerManagerService pm, |
| 1016 | boolean haveInputMethods) { |
| 1017 | mContext = context; |
| 1018 | mHaveInputMethods = haveInputMethods; |
| 1019 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 1020 | com.android.internal.R.bool.config_sf_limitedAlpha); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1021 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1022 | mPowerManager = pm; |
| 1023 | mPowerManager.setPolicy(mPolicy); |
| 1024 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 1025 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 1026 | "SCREEN_FROZEN"); |
| 1027 | mScreenFrozenLock.setReferenceCounted(false); |
| 1028 | |
| 1029 | mActivityManager = ActivityManagerNative.getDefault(); |
| 1030 | mBatteryStats = BatteryStatsService.getService(); |
| 1031 | |
| 1032 | // Get persisted window scale setting |
| 1033 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 1034 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 1035 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 1036 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1037 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1038 | // Track changes to DevicePolicyManager state so we can enable/disable keyguard. |
| 1039 | IntentFilter filter = new IntentFilter(); |
| 1040 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 1041 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 1042 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1043 | mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 1044 | "KEEP_SCREEN_ON_FLAG"); |
| 1045 | mHoldingScreenWakeLock.setReferenceCounted(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1046 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1047 | mInputManager = new InputManager(context, this); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1048 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1049 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 1050 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1051 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1052 | synchronized (thr) { |
| 1053 | while (!thr.mRunning) { |
| 1054 | try { |
| 1055 | thr.wait(); |
| 1056 | } catch (InterruptedException e) { |
| 1057 | } |
| 1058 | } |
| 1059 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1060 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1061 | mInputManager.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1062 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1063 | // Add ourself to the Watchdog monitors. |
| 1064 | Watchdog.getInstance().addMonitor(this); |
| 1065 | } |
| 1066 | |
| 1067 | @Override |
| 1068 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 1069 | throws RemoteException { |
| 1070 | try { |
| 1071 | return super.onTransact(code, data, reply, flags); |
| 1072 | } catch (RuntimeException e) { |
| 1073 | // The window manager only throws security exceptions, so let's |
| 1074 | // log all others. |
| 1075 | if (!(e instanceof SecurityException)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1076 | Slog.e(TAG, "Window Manager Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1077 | } |
| 1078 | throw e; |
| 1079 | } |
| 1080 | } |
| 1081 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1082 | private void placeWindowAfter(WindowState pos, WindowState window) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1083 | final int i = mWindows.indexOf(pos); |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1084 | 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] | 1085 | TAG, "Adding window " + window + " at " |
| 1086 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 1087 | mWindows.add(i+1, window); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1088 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1089 | } |
| 1090 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1091 | private void placeWindowBefore(WindowState pos, WindowState window) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1092 | final int i = mWindows.indexOf(pos); |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1093 | 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] | 1094 | TAG, "Adding window " + window + " at " |
| 1095 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 1096 | mWindows.add(i, window); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1097 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | //This method finds out the index of a window that has the same app token as |
| 1101 | //win. used for z ordering the windows in mWindows |
| 1102 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 1103 | //use a local variable to cache mWindows |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1104 | ArrayList<WindowState> localmWindows = mWindows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1105 | int jmax = localmWindows.size(); |
| 1106 | if(jmax == 0) { |
| 1107 | return -1; |
| 1108 | } |
| 1109 | for(int j = (jmax-1); j >= 0; j--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1110 | WindowState wentry = localmWindows.get(j); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1111 | if(wentry.mAppToken == win.mAppToken) { |
| 1112 | return j; |
| 1113 | } |
| 1114 | } |
| 1115 | return -1; |
| 1116 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1117 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1118 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 1119 | final IWindow client = win.mClient; |
| 1120 | final WindowToken token = win.mToken; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1121 | final ArrayList<WindowState> localmWindows = mWindows; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1122 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1123 | final int N = localmWindows.size(); |
| 1124 | final WindowState attached = win.mAttachedWindow; |
| 1125 | int i; |
| 1126 | if (attached == null) { |
| 1127 | int tokenWindowsPos = token.windows.size(); |
| 1128 | if (token.appWindowToken != null) { |
| 1129 | int index = tokenWindowsPos-1; |
| 1130 | if (index >= 0) { |
| 1131 | // If this application has existing windows, we |
| 1132 | // simply place the new window on top of them... but |
| 1133 | // keep the starting window on top. |
| 1134 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 1135 | // Base windows go behind everything else. |
| 1136 | placeWindowBefore(token.windows.get(0), win); |
| 1137 | tokenWindowsPos = 0; |
| 1138 | } else { |
| 1139 | AppWindowToken atoken = win.mAppToken; |
| 1140 | if (atoken != null && |
| 1141 | token.windows.get(index) == atoken.startingWindow) { |
| 1142 | placeWindowBefore(token.windows.get(index), win); |
| 1143 | tokenWindowsPos--; |
| 1144 | } else { |
| 1145 | int newIdx = findIdxBasedOnAppTokens(win); |
| 1146 | if(newIdx != -1) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1147 | //there is a window above this one associated with the same |
| 1148 | //apptoken note that the window could be a floating window |
| 1149 | //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] | 1150 | //windows associated with this token. |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1151 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 1152 | Slog.v(TAG, "Adding window " + win + " at " |
| 1153 | + (newIdx+1) + " of " + N); |
| 1154 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1155 | localmWindows.add(newIdx+1, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1156 | mWindowsChanged = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1157 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1158 | } |
| 1159 | } |
| 1160 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1161 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1162 | TAG, "Figuring out where to add app window " |
| 1163 | + client.asBinder() + " (token=" + token + ")"); |
| 1164 | // Figure out where the window should go, based on the |
| 1165 | // order of applications. |
| 1166 | final int NA = mAppTokens.size(); |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1167 | WindowState pos = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1168 | for (i=NA-1; i>=0; i--) { |
| 1169 | AppWindowToken t = mAppTokens.get(i); |
| 1170 | if (t == token) { |
| 1171 | i--; |
| 1172 | break; |
| 1173 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1174 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1175 | // We haven't reached the token yet; if this token |
| 1176 | // is not going to the bottom and has windows, we can |
| 1177 | // use it as an anchor for when we do reach the token. |
| 1178 | if (!t.sendingToBottom && t.windows.size() > 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1179 | pos = t.windows.get(0); |
| 1180 | } |
| 1181 | } |
| 1182 | // We now know the index into the apps. If we found |
| 1183 | // an app window above, that gives us the position; else |
| 1184 | // we need to look some more. |
| 1185 | if (pos != null) { |
| 1186 | // Move behind any windows attached to this one. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1187 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1188 | if (atoken != null) { |
| 1189 | final int NC = atoken.windows.size(); |
| 1190 | if (NC > 0) { |
| 1191 | WindowState bottom = atoken.windows.get(0); |
| 1192 | if (bottom.mSubLayer < 0) { |
| 1193 | pos = bottom; |
| 1194 | } |
| 1195 | } |
| 1196 | } |
| 1197 | placeWindowBefore(pos, win); |
| 1198 | } else { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1199 | // Continue looking down until we find the first |
| 1200 | // token that has windows. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1201 | while (i >= 0) { |
| 1202 | AppWindowToken t = mAppTokens.get(i); |
| 1203 | final int NW = t.windows.size(); |
| 1204 | if (NW > 0) { |
| 1205 | pos = t.windows.get(NW-1); |
| 1206 | break; |
| 1207 | } |
| 1208 | i--; |
| 1209 | } |
| 1210 | if (pos != null) { |
| 1211 | // Move in front of any windows attached to this |
| 1212 | // one. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1213 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1214 | if (atoken != null) { |
| 1215 | final int NC = atoken.windows.size(); |
| 1216 | if (NC > 0) { |
| 1217 | WindowState top = atoken.windows.get(NC-1); |
| 1218 | if (top.mSubLayer >= 0) { |
| 1219 | pos = top; |
| 1220 | } |
| 1221 | } |
| 1222 | } |
| 1223 | placeWindowAfter(pos, win); |
| 1224 | } else { |
| 1225 | // Just search for the start of this layer. |
| 1226 | final int myLayer = win.mBaseLayer; |
| 1227 | for (i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1228 | WindowState w = localmWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1229 | if (w.mBaseLayer > myLayer) { |
| 1230 | break; |
| 1231 | } |
| 1232 | } |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1233 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 1234 | Slog.v(TAG, "Adding window " + win + " at " |
| 1235 | + i + " of " + N); |
| 1236 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1237 | localmWindows.add(i, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1238 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1239 | } |
| 1240 | } |
| 1241 | } |
| 1242 | } else { |
| 1243 | // Figure out where window should go, based on layer. |
| 1244 | final int myLayer = win.mBaseLayer; |
| 1245 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1246 | if (localmWindows.get(i).mBaseLayer <= myLayer) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1247 | i++; |
| 1248 | break; |
| 1249 | } |
| 1250 | } |
| 1251 | if (i < 0) i = 0; |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1252 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1253 | TAG, "Adding window " + win + " at " |
| 1254 | + i + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1255 | localmWindows.add(i, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1256 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1257 | } |
| 1258 | if (addToToken) { |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1259 | 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] | 1260 | token.windows.add(tokenWindowsPos, win); |
| 1261 | } |
| 1262 | |
| 1263 | } else { |
| 1264 | // Figure out this window's ordering relative to the window |
| 1265 | // it is attached to. |
| 1266 | final int NA = token.windows.size(); |
| 1267 | final int sublayer = win.mSubLayer; |
| 1268 | int largestSublayer = Integer.MIN_VALUE; |
| 1269 | WindowState windowWithLargestSublayer = null; |
| 1270 | for (i=0; i<NA; i++) { |
| 1271 | WindowState w = token.windows.get(i); |
| 1272 | final int wSublayer = w.mSubLayer; |
| 1273 | if (wSublayer >= largestSublayer) { |
| 1274 | largestSublayer = wSublayer; |
| 1275 | windowWithLargestSublayer = w; |
| 1276 | } |
| 1277 | if (sublayer < 0) { |
| 1278 | // For negative sublayers, we go below all windows |
| 1279 | // in the same sublayer. |
| 1280 | if (wSublayer >= sublayer) { |
| 1281 | if (addToToken) { |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1282 | 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] | 1283 | token.windows.add(i, win); |
| 1284 | } |
| 1285 | placeWindowBefore( |
| 1286 | wSublayer >= 0 ? attached : w, win); |
| 1287 | break; |
| 1288 | } |
| 1289 | } else { |
| 1290 | // For positive sublayers, we go above all windows |
| 1291 | // in the same sublayer. |
| 1292 | if (wSublayer > sublayer) { |
| 1293 | if (addToToken) { |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1294 | 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] | 1295 | token.windows.add(i, win); |
| 1296 | } |
| 1297 | placeWindowBefore(w, win); |
| 1298 | break; |
| 1299 | } |
| 1300 | } |
| 1301 | } |
| 1302 | if (i >= NA) { |
| 1303 | if (addToToken) { |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1304 | 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] | 1305 | token.windows.add(win); |
| 1306 | } |
| 1307 | if (sublayer < 0) { |
| 1308 | placeWindowBefore(attached, win); |
| 1309 | } else { |
| 1310 | placeWindowAfter(largestSublayer >= 0 |
| 1311 | ? windowWithLargestSublayer |
| 1312 | : attached, |
| 1313 | win); |
| 1314 | } |
| 1315 | } |
| 1316 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1317 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1318 | if (win.mAppToken != null && addToToken) { |
| 1319 | win.mAppToken.allAppWindows.add(win); |
| 1320 | } |
| 1321 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1322 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1323 | static boolean canBeImeTarget(WindowState w) { |
| 1324 | final int fl = w.mAttrs.flags |
| 1325 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1326 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM) |
| 1327 | || w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 1328 | if (DEBUG_INPUT_METHOD) { |
| 1329 | Slog.i(TAG, "isVisibleOrAdding " + w + ": " + w.isVisibleOrAdding()); |
| 1330 | if (!w.isVisibleOrAdding()) { |
| 1331 | Slog.i(TAG, " mSurface=" + w.mSurface + " reportDestroy=" + w.mReportDestroySurface |
| 1332 | + " relayoutCalled=" + w.mRelayoutCalled + " viewVis=" + w.mViewVisibility |
| 1333 | + " policyVis=" + w.mPolicyVisibility + " attachHid=" + w.mAttachedHidden |
| 1334 | + " exiting=" + w.mExiting + " destroying=" + w.mDestroying); |
| 1335 | if (w.mAppToken != null) { |
| 1336 | Slog.i(TAG, " mAppToken.hiddenRequested=" + w.mAppToken.hiddenRequested); |
| 1337 | } |
| 1338 | } |
| 1339 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1340 | return w.isVisibleOrAdding(); |
| 1341 | } |
| 1342 | return false; |
| 1343 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1344 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1345 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1346 | final ArrayList<WindowState> localmWindows = mWindows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1347 | final int N = localmWindows.size(); |
| 1348 | WindowState w = null; |
| 1349 | int i = N; |
| 1350 | while (i > 0) { |
| 1351 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1352 | w = localmWindows.get(i); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1353 | |
| Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1354 | if (DEBUG_INPUT_METHOD && willMove) Slog.i(TAG, "Checking window @" + i |
| 1355 | + " " + w + " fl=0x" + Integer.toHexString(w.mAttrs.flags)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1356 | if (canBeImeTarget(w)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1357 | //Slog.i(TAG, "Putting input method here!"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1358 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1359 | // Yet more tricksyness! If this window is a "starting" |
| 1360 | // window, we do actually want to be on top of it, but |
| 1361 | // it is not -really- where input will go. So if the caller |
| 1362 | // is not actually looking to move the IME, look down below |
| 1363 | // for a real window to target... |
| 1364 | if (!willMove |
| 1365 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 1366 | && i > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1367 | WindowState wb = localmWindows.get(i-1); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1368 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 1369 | i--; |
| 1370 | w = wb; |
| 1371 | } |
| 1372 | } |
| 1373 | break; |
| 1374 | } |
| 1375 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1376 | |
| Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1377 | if (DEBUG_INPUT_METHOD && willMove) Slog.v(TAG, "Proposed new IME target: " + w); |
| 1378 | |
| Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1379 | // Now, a special case -- if the last target's window is in the |
| 1380 | // process of exiting, and is above the new target, keep on the |
| 1381 | // last target to avoid flicker. Consider for example a Dialog with |
| 1382 | // the IME shown: when the Dialog is dismissed, we want to keep |
| 1383 | // the IME above it until it is completely gone so it doesn't drop |
| 1384 | // behind the dialog or its full-screen scrim. |
| 1385 | if (mInputMethodTarget != null && w != null |
| 1386 | && mInputMethodTarget.isDisplayedLw() |
| 1387 | && mInputMethodTarget.mExiting) { |
| 1388 | if (mInputMethodTarget.mAnimLayer > w.mAnimLayer) { |
| 1389 | w = mInputMethodTarget; |
| 1390 | i = localmWindows.indexOf(w); |
| Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1391 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Current target higher, switching to: " + w); |
| Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1392 | } |
| 1393 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1394 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1395 | 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] | 1396 | + w + " willMove=" + willMove); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1397 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1398 | if (willMove && w != null) { |
| 1399 | final WindowState curTarget = mInputMethodTarget; |
| 1400 | if (curTarget != null && curTarget.mAppToken != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1401 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1402 | // Now some fun for dealing with window animations that |
| 1403 | // modify the Z order. We need to look at all windows below |
| 1404 | // the current target that are in this app, finding the highest |
| 1405 | // visible one in layering. |
| 1406 | AppWindowToken token = curTarget.mAppToken; |
| 1407 | WindowState highestTarget = null; |
| 1408 | int highestPos = 0; |
| 1409 | if (token.animating || token.animation != null) { |
| 1410 | int pos = 0; |
| 1411 | pos = localmWindows.indexOf(curTarget); |
| 1412 | while (pos >= 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1413 | WindowState win = localmWindows.get(pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1414 | if (win.mAppToken != token) { |
| 1415 | break; |
| 1416 | } |
| 1417 | if (!win.mRemoved) { |
| 1418 | if (highestTarget == null || win.mAnimLayer > |
| 1419 | highestTarget.mAnimLayer) { |
| 1420 | highestTarget = win; |
| 1421 | highestPos = pos; |
| 1422 | } |
| 1423 | } |
| 1424 | pos--; |
| 1425 | } |
| 1426 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1427 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1428 | if (highestTarget != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1429 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1430 | + mNextAppTransition + " " + highestTarget |
| 1431 | + " animating=" + highestTarget.isAnimating() |
| 1432 | + " layer=" + highestTarget.mAnimLayer |
| 1433 | + " new layer=" + w.mAnimLayer); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1434 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1435 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1436 | // If we are currently setting up for an animation, |
| 1437 | // hold everything until we can find out what will happen. |
| 1438 | mInputMethodTargetWaitingAnim = true; |
| 1439 | mInputMethodTarget = highestTarget; |
| 1440 | return highestPos + 1; |
| 1441 | } else if (highestTarget.isAnimating() && |
| 1442 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 1443 | // If the window we are currently targeting is involved |
| 1444 | // with an animation, and it is on top of the next target |
| 1445 | // we will be over, then hold off on moving until |
| 1446 | // that is done. |
| Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1447 | mInputMethodTargetWaitingAnim = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1448 | mInputMethodTarget = highestTarget; |
| 1449 | return highestPos + 1; |
| 1450 | } |
| 1451 | } |
| 1452 | } |
| 1453 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1454 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1455 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1456 | if (w != null) { |
| 1457 | if (willMove) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1458 | if (DEBUG_INPUT_METHOD) { |
| 1459 | RuntimeException e = null; |
| 1460 | if (!HIDE_STACK_CRAWLS) { |
| 1461 | e = new RuntimeException(); |
| 1462 | e.fillInStackTrace(); |
| 1463 | } |
| 1464 | Slog.w(TAG, "Moving IM target from " |
| 1465 | + mInputMethodTarget + " to " + w, e); |
| 1466 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1467 | mInputMethodTarget = w; |
| Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1468 | mInputMethodTargetWaitingAnim = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1469 | if (w.mAppToken != null) { |
| 1470 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 1471 | } else { |
| 1472 | setInputMethodAnimLayerAdjustment(0); |
| 1473 | } |
| 1474 | } |
| 1475 | return i+1; |
| 1476 | } |
| 1477 | if (willMove) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1478 | if (DEBUG_INPUT_METHOD) { |
| 1479 | RuntimeException e = null; |
| 1480 | if (!HIDE_STACK_CRAWLS) { |
| 1481 | e = new RuntimeException(); |
| 1482 | e.fillInStackTrace(); |
| 1483 | } |
| 1484 | Slog.w(TAG, "Moving IM target from " |
| 1485 | + mInputMethodTarget + " to null", e); |
| 1486 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1487 | mInputMethodTarget = null; |
| 1488 | setInputMethodAnimLayerAdjustment(0); |
| 1489 | } |
| 1490 | return -1; |
| 1491 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1492 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1493 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1494 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1495 | if (pos >= 0) { |
| 1496 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1497 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1498 | TAG, "Adding input method window " + win + " at " + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1499 | mWindows.add(pos, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1500 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1501 | moveInputMethodDialogsLocked(pos+1); |
| 1502 | return; |
| 1503 | } |
| 1504 | win.mTargetAppToken = null; |
| 1505 | addWindowToListInOrderLocked(win, true); |
| 1506 | moveInputMethodDialogsLocked(pos); |
| 1507 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1508 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1509 | void setInputMethodAnimLayerAdjustment(int adj) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1510 | 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] | 1511 | mInputMethodAnimLayerAdjustment = adj; |
| 1512 | WindowState imw = mInputMethodWindow; |
| 1513 | if (imw != null) { |
| 1514 | imw.mAnimLayer = imw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1515 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1516 | + " anim layer: " + imw.mAnimLayer); |
| 1517 | int wi = imw.mChildWindows.size(); |
| 1518 | while (wi > 0) { |
| 1519 | wi--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1520 | WindowState cw = imw.mChildWindows.get(wi); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1521 | cw.mAnimLayer = cw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1522 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1523 | + " anim layer: " + cw.mAnimLayer); |
| 1524 | } |
| 1525 | } |
| 1526 | int di = mInputMethodDialogs.size(); |
| 1527 | while (di > 0) { |
| 1528 | di --; |
| 1529 | imw = mInputMethodDialogs.get(di); |
| 1530 | imw.mAnimLayer = imw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1531 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1532 | + " anim layer: " + imw.mAnimLayer); |
| 1533 | } |
| 1534 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1535 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1536 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1537 | int wpos = mWindows.indexOf(win); |
| 1538 | if (wpos >= 0) { |
| 1539 | if (wpos < interestingPos) interestingPos--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1540 | 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] | 1541 | mWindows.remove(wpos); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1542 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1543 | int NC = win.mChildWindows.size(); |
| 1544 | while (NC > 0) { |
| 1545 | NC--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1546 | WindowState cw = win.mChildWindows.get(NC); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1547 | int cpos = mWindows.indexOf(cw); |
| 1548 | if (cpos >= 0) { |
| 1549 | if (cpos < interestingPos) interestingPos--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1550 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1551 | + cpos + ": " + cw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1552 | mWindows.remove(cpos); |
| 1553 | } |
| 1554 | } |
| 1555 | } |
| 1556 | return interestingPos; |
| 1557 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1558 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1559 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1560 | addWindowToListInOrderLocked(win, false); |
| 1561 | // This is a hack to get all of the child windows added as well |
| 1562 | // at the right position. Child windows should be rare and |
| 1563 | // this case should be rare, so it shouldn't be that big a deal. |
| 1564 | int wpos = mWindows.indexOf(win); |
| 1565 | if (wpos >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1566 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1567 | + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1568 | mWindows.remove(wpos); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1569 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1570 | reAddWindowLocked(wpos, win); |
| 1571 | } |
| 1572 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1573 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1574 | void logWindowList(String prefix) { |
| 1575 | int N = mWindows.size(); |
| 1576 | while (N > 0) { |
| 1577 | N--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1578 | Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1579 | } |
| 1580 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1581 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1582 | void moveInputMethodDialogsLocked(int pos) { |
| 1583 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1584 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1585 | final int N = dialogs.size(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1586 | 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] | 1587 | for (int i=0; i<N; i++) { |
| 1588 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1589 | } |
| 1590 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1591 | Slog.v(TAG, "Window list w/pos=" + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1592 | logWindowList(" "); |
| 1593 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1594 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1595 | if (pos >= 0) { |
| 1596 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1597 | if (pos < mWindows.size()) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1598 | WindowState wp = mWindows.get(pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1599 | if (wp == mInputMethodWindow) { |
| 1600 | pos++; |
| 1601 | } |
| 1602 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1603 | 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] | 1604 | for (int i=0; i<N; i++) { |
| 1605 | WindowState win = dialogs.get(i); |
| 1606 | win.mTargetAppToken = targetAppToken; |
| 1607 | pos = reAddWindowLocked(pos, win); |
| 1608 | } |
| 1609 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1610 | Slog.v(TAG, "Final window list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1611 | logWindowList(" "); |
| 1612 | } |
| 1613 | return; |
| 1614 | } |
| 1615 | for (int i=0; i<N; i++) { |
| 1616 | WindowState win = dialogs.get(i); |
| 1617 | win.mTargetAppToken = null; |
| 1618 | reAddWindowToListInOrderLocked(win); |
| 1619 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1620 | Slog.v(TAG, "No IM target, final list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1621 | logWindowList(" "); |
| 1622 | } |
| 1623 | } |
| 1624 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1625 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1626 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1627 | final WindowState imWin = mInputMethodWindow; |
| 1628 | final int DN = mInputMethodDialogs.size(); |
| 1629 | if (imWin == null && DN == 0) { |
| 1630 | return false; |
| 1631 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1632 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1633 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1634 | if (imPos >= 0) { |
| 1635 | // In this case, the input method windows are to be placed |
| 1636 | // immediately above the window they are targeting. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1637 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1638 | // First check to see if the input method windows are already |
| 1639 | // located here, and contiguous. |
| 1640 | final int N = mWindows.size(); |
| 1641 | WindowState firstImWin = imPos < N |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1642 | ? mWindows.get(imPos) : null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1643 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1644 | // Figure out the actual input method window that should be |
| 1645 | // at the bottom of their stack. |
| 1646 | WindowState baseImWin = imWin != null |
| 1647 | ? imWin : mInputMethodDialogs.get(0); |
| 1648 | if (baseImWin.mChildWindows.size() > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1649 | WindowState cw = baseImWin.mChildWindows.get(0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1650 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1651 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1652 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1653 | if (firstImWin == baseImWin) { |
| 1654 | // The windows haven't moved... but are they still contiguous? |
| 1655 | // First find the top IM window. |
| 1656 | int pos = imPos+1; |
| 1657 | while (pos < N) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1658 | if (!(mWindows.get(pos)).mIsImWindow) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1659 | break; |
| 1660 | } |
| 1661 | pos++; |
| 1662 | } |
| 1663 | pos++; |
| 1664 | // Now there should be no more input method windows above. |
| 1665 | while (pos < N) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1666 | if ((mWindows.get(pos)).mIsImWindow) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1667 | break; |
| 1668 | } |
| 1669 | pos++; |
| 1670 | } |
| 1671 | if (pos >= N) { |
| 1672 | // All is good! |
| 1673 | return false; |
| 1674 | } |
| 1675 | } |
| 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) { |
| 1678 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1679 | Slog.v(TAG, "Moving IM from " + imPos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1680 | logWindowList(" "); |
| 1681 | } |
| 1682 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1683 | if (DEBUG_INPUT_METHOD) { |
| Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1684 | 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] | 1685 | logWindowList(" "); |
| 1686 | } |
| 1687 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1688 | reAddWindowLocked(imPos, imWin); |
| 1689 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1690 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1691 | logWindowList(" "); |
| 1692 | } |
| 1693 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1694 | } else { |
| 1695 | moveInputMethodDialogsLocked(imPos); |
| 1696 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1697 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1698 | } else { |
| 1699 | // In this case, the input method windows go in a fixed layer, |
| 1700 | // because they aren't currently associated with a focus window. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1701 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1702 | if (imWin != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1703 | 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] | 1704 | tmpRemoveWindowLocked(0, imWin); |
| 1705 | imWin.mTargetAppToken = null; |
| 1706 | reAddWindowToListInOrderLocked(imWin); |
| 1707 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1708 | Slog.v(TAG, "List with no IM target:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1709 | logWindowList(" "); |
| 1710 | } |
| 1711 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1712 | } else { |
| 1713 | moveInputMethodDialogsLocked(-1);; |
| 1714 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1715 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1716 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1717 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1718 | if (needAssignLayers) { |
| 1719 | assignLayersLocked(); |
| 1720 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1721 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1722 | return true; |
| 1723 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1724 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1725 | void adjustInputMethodDialogsLocked() { |
| 1726 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1727 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1728 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1729 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1730 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured=" |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1731 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1732 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1733 | ? wallpaperTarget.mAppToken.animation : null) |
| 1734 | + " upper=" + mUpperWallpaperTarget |
| 1735 | + " lower=" + mLowerWallpaperTarget); |
| 1736 | return (wallpaperTarget != null |
| 1737 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1738 | && wallpaperTarget.mAppToken.animation != null))) |
| 1739 | || mUpperWallpaperTarget != null |
| 1740 | || mLowerWallpaperTarget != null; |
| 1741 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1742 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1743 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1744 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1745 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1746 | int adjustWallpaperWindowsLocked() { |
| 1747 | int changed = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1748 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1749 | final int dw = mDisplay.getWidth(); |
| 1750 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1751 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1752 | // First find top-most window that has asked to be on top of the |
| 1753 | // wallpaper; all wallpapers go behind it. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1754 | final ArrayList<WindowState> localmWindows = mWindows; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1755 | int N = localmWindows.size(); |
| 1756 | WindowState w = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1757 | WindowState foundW = null; |
| 1758 | int foundI = 0; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1759 | WindowState topCurW = null; |
| 1760 | int topCurI = 0; |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1761 | int windowDetachedI = -1; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1762 | int i = N; |
| 1763 | while (i > 0) { |
| 1764 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1765 | w = localmWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1766 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1767 | if (topCurW == null) { |
| 1768 | topCurW = w; |
| 1769 | topCurI = i; |
| 1770 | } |
| 1771 | continue; |
| 1772 | } |
| 1773 | topCurW = null; |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1774 | if (w != mWindowDetachedWallpaper && w.mAppToken != null) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1775 | // If this window's app token is hidden and not animating, |
| 1776 | // it is of no interest to us. |
| 1777 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1778 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1779 | "Skipping not hidden or animating token: " + w); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1780 | continue; |
| 1781 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1782 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1783 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay=" |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1784 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1785 | + " commitdrawpending=" + w.mCommitDrawPending); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1786 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1787 | && (mWallpaperTarget == w |
| 1788 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1789 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1790 | "Found wallpaper activity: #" + i + "=" + w); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1791 | foundW = w; |
| 1792 | foundI = i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1793 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1794 | && w.mAppToken.animation != null) |
| 1795 | || w.mAnimation != null)) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1796 | // The current wallpaper target is animating, so we'll |
| 1797 | // look behind it for another possible target and figure |
| 1798 | // out what is going on below. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1799 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1800 | + ": token animating, looking behind."); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1801 | continue; |
| 1802 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1803 | break; |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1804 | } else if (w == mWindowDetachedWallpaper) { |
| 1805 | windowDetachedI = i; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1806 | } |
| 1807 | } |
| 1808 | |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1809 | if (foundW == null && windowDetachedI >= 0) { |
| 1810 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 1811 | "Found animating detached wallpaper activity: #" + i + "=" + w); |
| 1812 | foundW = w; |
| 1813 | foundI = windowDetachedI; |
| 1814 | } |
| 1815 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1816 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1817 | // If we are currently waiting for an app transition, and either |
| 1818 | // the current target or the next target are involved with it, |
| 1819 | // then hold off on doing anything with the wallpaper. |
| 1820 | // Note that we are checking here for just whether the target |
| 1821 | // is part of an app token... which is potentially overly aggressive |
| 1822 | // (the app token may not be involved in the transition), but good |
| 1823 | // enough (we'll just wait until whatever transition is pending |
| 1824 | // executes). |
| 1825 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1826 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1827 | "Wallpaper not changing: waiting for app anim in current target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1828 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1829 | } |
| 1830 | if (foundW != null && foundW.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1831 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1832 | "Wallpaper not changing: waiting for app anim in found target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1833 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1834 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1835 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1836 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1837 | if (mWallpaperTarget != foundW) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1838 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1839 | Slog.v(TAG, "New wallpaper target: " + foundW |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1840 | + " oldTarget: " + mWallpaperTarget); |
| 1841 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1842 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1843 | mLowerWallpaperTarget = null; |
| 1844 | mUpperWallpaperTarget = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1845 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1846 | WindowState oldW = mWallpaperTarget; |
| 1847 | mWallpaperTarget = foundW; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1848 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1849 | // Now what is happening... if the current and new targets are |
| 1850 | // animating, then we are in our super special mode! |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1851 | if (foundW != null && oldW != null) { |
| 1852 | boolean oldAnim = oldW.mAnimation != null |
| 1853 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1854 | boolean foundAnim = foundW.mAnimation != null |
| 1855 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1856 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1857 | Slog.v(TAG, "New animation: " + foundAnim |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1858 | + " old animation: " + oldAnim); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1859 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1860 | if (foundAnim && oldAnim) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1861 | int oldI = localmWindows.indexOf(oldW); |
| 1862 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1863 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1864 | } |
| 1865 | if (oldI >= 0) { |
| 1866 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1867 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1868 | + "=" + oldW + "; new#" + foundI |
| 1869 | + "=" + foundW); |
| 1870 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1871 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1872 | // Set the new target correctly. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1873 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1874 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1875 | Slog.v(TAG, "Old wallpaper still the target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1876 | } |
| 1877 | mWallpaperTarget = oldW; |
| 1878 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1879 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1880 | // Now set the upper and lower wallpaper targets |
| 1881 | // correctly, and make sure that we are positioning |
| 1882 | // the wallpaper below the lower. |
| 1883 | if (foundI > oldI) { |
| 1884 | // The new target is on top of the old one. |
| 1885 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1886 | Slog.v(TAG, "Found target above old target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1887 | } |
| 1888 | mUpperWallpaperTarget = foundW; |
| 1889 | mLowerWallpaperTarget = oldW; |
| 1890 | foundW = oldW; |
| 1891 | foundI = oldI; |
| 1892 | } else { |
| 1893 | // The new target is below the old one. |
| 1894 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1895 | Slog.v(TAG, "Found target below old target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1896 | } |
| 1897 | mUpperWallpaperTarget = oldW; |
| 1898 | mLowerWallpaperTarget = foundW; |
| 1899 | } |
| 1900 | } |
| 1901 | } |
| 1902 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1903 | |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1904 | } else if (mLowerWallpaperTarget != null) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1905 | // Is it time to stop animating? |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1906 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1907 | || (mLowerWallpaperTarget.mAppToken != null |
| 1908 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1909 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1910 | || (mUpperWallpaperTarget.mAppToken != null |
| 1911 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1912 | if (!lowerAnimating || !upperAnimating) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1913 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1914 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1915 | } |
| 1916 | mLowerWallpaperTarget = null; |
| 1917 | mUpperWallpaperTarget = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1918 | } |
| 1919 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1920 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1921 | boolean visible = foundW != null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1922 | if (visible) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1923 | // The window is visible to the compositor... but is it visible |
| 1924 | // to the user? That is what the wallpaper cares about. |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1925 | visible = isWallpaperVisible(foundW); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1926 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1927 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1928 | // If the wallpaper target is animating, we may need to copy |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1929 | // its layer adjustment. Only do this if we are not transfering |
| 1930 | // between two wallpaper targets. |
| 1931 | mWallpaperAnimLayerAdjustment = |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1932 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1933 | ? foundW.mAppToken.animLayerAdjustment : 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1934 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1935 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1936 | * TYPE_LAYER_MULTIPLIER |
| 1937 | + TYPE_LAYER_OFFSET; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1938 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1939 | // Now w is the window we are supposed to be behind... but we |
| 1940 | // 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] | 1941 | // AND any starting window associated with it, AND below the |
| 1942 | // maximum layer the policy allows for wallpapers. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1943 | while (foundI > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1944 | WindowState wb = localmWindows.get(foundI-1); |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1945 | if (wb.mBaseLayer < maxLayer && |
| 1946 | wb.mAttachedWindow != foundW && |
| Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 1947 | (foundW.mAttachedWindow == null || |
| 1948 | wb.mAttachedWindow != foundW.mAttachedWindow) && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1949 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
| Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 1950 | foundW.mToken == null || wb.mToken != foundW.mToken)) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1951 | // This window is not related to the previous one in any |
| 1952 | // interesting way, so stop here. |
| 1953 | break; |
| 1954 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1955 | foundW = wb; |
| 1956 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1957 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1958 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1959 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1960 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1961 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1962 | if (foundW == null && topCurW != null) { |
| 1963 | // There is no wallpaper target, so it goes at the bottom. |
| 1964 | // We will assume it is the same place as last time, if known. |
| 1965 | foundW = topCurW; |
| 1966 | foundI = topCurI+1; |
| 1967 | } else { |
| 1968 | // Okay i is the position immediately above the wallpaper. Look at |
| 1969 | // what is below it for later. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1970 | foundW = foundI > 0 ? localmWindows.get(foundI-1) : null; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1971 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1972 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1973 | if (visible) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1974 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1975 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1976 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1977 | } |
| 1978 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1979 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1980 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1981 | } |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1982 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1983 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1984 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1985 | // are correctly placed. |
| 1986 | int curTokenIndex = mWallpaperTokens.size(); |
| 1987 | while (curTokenIndex > 0) { |
| 1988 | curTokenIndex--; |
| 1989 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1990 | if (token.hidden == visible) { |
| 1991 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1992 | token.hidden = !visible; |
| 1993 | // Need to do a layout to ensure the wallpaper now has the |
| 1994 | // correct size. |
| 1995 | mLayoutNeeded = true; |
| 1996 | } |
| 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 | int curWallpaperIndex = token.windows.size(); |
| 1999 | while (curWallpaperIndex > 0) { |
| 2000 | curWallpaperIndex--; |
| 2001 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2002 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2003 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2004 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2005 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2006 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2007 | // First, make sure the client has the current visibility |
| 2008 | // state. |
| 2009 | if (wallpaper.mWallpaperVisible != visible) { |
| 2010 | wallpaper.mWallpaperVisible = visible; |
| 2011 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2012 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2013 | "Setting visibility of wallpaper " + wallpaper |
| 2014 | + ": " + visible); |
| 2015 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 2016 | } catch (RemoteException e) { |
| 2017 | } |
| 2018 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2019 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2020 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2021 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2022 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2023 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2024 | // First, if this window is at the current index, then all |
| 2025 | // is well. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2026 | if (wallpaper == foundW) { |
| 2027 | foundI--; |
| 2028 | foundW = foundI > 0 |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2029 | ? localmWindows.get(foundI-1) : null; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2030 | continue; |
| 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 | // The window didn't match... the current wallpaper window, |
| 2034 | // wherever it is, is in the wrong place, so make sure it is |
| 2035 | // not in the list. |
| 2036 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 2037 | if (oldIndex >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2038 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 2039 | + oldIndex + ": " + wallpaper); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2040 | localmWindows.remove(oldIndex); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2041 | mWindowsChanged = true; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2042 | if (oldIndex < foundI) { |
| 2043 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2044 | } |
| 2045 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2046 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2047 | // Now stick it in. |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2048 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 2049 | Slog.v(TAG, "Moving wallpaper " + wallpaper |
| 2050 | + " from " + oldIndex + " to " + foundI); |
| 2051 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2052 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2053 | localmWindows.add(foundI, wallpaper); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2054 | mWindowsChanged = true; |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2055 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2056 | } |
| 2057 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2058 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2059 | return changed; |
| 2060 | } |
| 2061 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2062 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2063 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2064 | "Setting wallpaper layer adj to " + adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2065 | mWallpaperAnimLayerAdjustment = adj; |
| 2066 | int curTokenIndex = mWallpaperTokens.size(); |
| 2067 | while (curTokenIndex > 0) { |
| 2068 | curTokenIndex--; |
| 2069 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2070 | int curWallpaperIndex = token.windows.size(); |
| 2071 | while (curWallpaperIndex > 0) { |
| 2072 | curWallpaperIndex--; |
| 2073 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2074 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2075 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2076 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2077 | } |
| 2078 | } |
| 2079 | } |
| 2080 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2081 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 2082 | boolean sync) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2083 | boolean changed = false; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2084 | boolean rawChanged = false; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2085 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2086 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2087 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 2088 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 2089 | changed = wallpaperWin.mXOffset != offset; |
| 2090 | if (changed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2091 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2092 | + wallpaperWin + " x: " + offset); |
| 2093 | wallpaperWin.mXOffset = offset; |
| 2094 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2095 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2096 | wallpaperWin.mWallpaperX = wpx; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2097 | wallpaperWin.mWallpaperXStep = wpxs; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2098 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2099 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2100 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2101 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2102 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2103 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 2104 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 2105 | if (wallpaperWin.mYOffset != offset) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2106 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2107 | + wallpaperWin + " y: " + offset); |
| 2108 | changed = true; |
| 2109 | wallpaperWin.mYOffset = offset; |
| 2110 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2111 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2112 | wallpaperWin.mWallpaperY = wpy; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2113 | wallpaperWin.mWallpaperYStep = wpys; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2114 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2115 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2116 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2117 | if (rawChanged) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2118 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2119 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2120 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 2121 | + " y=" + wallpaperWin.mWallpaperY); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2122 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2123 | mWaitingOnWallpaper = wallpaperWin; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2124 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2125 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2126 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 2127 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2128 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2129 | if (mWaitingOnWallpaper != null) { |
| 2130 | long start = SystemClock.uptimeMillis(); |
| 2131 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 2132 | < start) { |
| 2133 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2134 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2135 | "Waiting for offset complete..."); |
| 2136 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 2137 | } catch (InterruptedException e) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2138 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2139 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2140 | if ((start+WALLPAPER_TIMEOUT) |
| 2141 | < SystemClock.uptimeMillis()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2142 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2143 | + wallpaperWin); |
| 2144 | mLastWallpaperTimeoutTime = start; |
| 2145 | } |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2146 | } |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2147 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2148 | } |
| 2149 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2150 | } catch (RemoteException e) { |
| 2151 | } |
| 2152 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2153 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2154 | return changed; |
| 2155 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2156 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2157 | void wallpaperOffsetsComplete(IBinder window) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2158 | synchronized (mWindowMap) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2159 | if (mWaitingOnWallpaper != null && |
| 2160 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2161 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2162 | mWindowMap.notifyAll(); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2163 | } |
| 2164 | } |
| 2165 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2166 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2167 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2168 | final int dw = mDisplay.getWidth(); |
| 2169 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2170 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2171 | boolean changed = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2172 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2173 | WindowState target = mWallpaperTarget; |
| 2174 | if (target != null) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2175 | if (target.mWallpaperX >= 0) { |
| 2176 | mLastWallpaperX = target.mWallpaperX; |
| 2177 | } else if (changingTarget.mWallpaperX >= 0) { |
| 2178 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 2179 | } |
| 2180 | if (target.mWallpaperY >= 0) { |
| 2181 | mLastWallpaperY = target.mWallpaperY; |
| 2182 | } else if (changingTarget.mWallpaperY >= 0) { |
| 2183 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 2184 | } |
| 2185 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2186 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2187 | int curTokenIndex = mWallpaperTokens.size(); |
| 2188 | while (curTokenIndex > 0) { |
| 2189 | curTokenIndex--; |
| 2190 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2191 | int curWallpaperIndex = token.windows.size(); |
| 2192 | while (curWallpaperIndex > 0) { |
| 2193 | curWallpaperIndex--; |
| 2194 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2195 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 2196 | wallpaper.computeShownFrameLocked(); |
| 2197 | changed = true; |
| 2198 | // We only want to be synchronous with one wallpaper. |
| 2199 | sync = false; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2200 | } |
| 2201 | } |
| 2202 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2203 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2204 | return changed; |
| 2205 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2206 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2207 | void updateWallpaperVisibilityLocked() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2208 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2209 | final int dw = mDisplay.getWidth(); |
| 2210 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2211 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2212 | int curTokenIndex = mWallpaperTokens.size(); |
| 2213 | while (curTokenIndex > 0) { |
| 2214 | curTokenIndex--; |
| 2215 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2216 | if (token.hidden == visible) { |
| 2217 | token.hidden = !visible; |
| 2218 | // Need to do a layout to ensure the wallpaper now has the |
| 2219 | // correct size. |
| 2220 | mLayoutNeeded = true; |
| 2221 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2222 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2223 | int curWallpaperIndex = token.windows.size(); |
| 2224 | while (curWallpaperIndex > 0) { |
| 2225 | curWallpaperIndex--; |
| 2226 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2227 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2228 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2229 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2230 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2231 | if (wallpaper.mWallpaperVisible != visible) { |
| 2232 | wallpaper.mWallpaperVisible = visible; |
| 2233 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2234 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2235 | "Updating visibility of wallpaper " + wallpaper |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2236 | + ": " + visible); |
| 2237 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 2238 | } catch (RemoteException e) { |
| 2239 | } |
| 2240 | } |
| 2241 | } |
| 2242 | } |
| 2243 | } |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 2244 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2245 | public int addWindow(Session session, IWindow client, |
| 2246 | WindowManager.LayoutParams attrs, int viewVisibility, |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2247 | Rect outContentInsets, InputChannel outInputChannel) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2248 | int res = mPolicy.checkAddPermission(attrs); |
| 2249 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2250 | return res; |
| 2251 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2252 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2253 | boolean reportNewConfig = false; |
| 2254 | WindowState attachedWindow = null; |
| 2255 | WindowState win = null; |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2256 | long origId; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2257 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2258 | synchronized(mWindowMap) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2259 | if (mDisplay == null) { |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2260 | throw new IllegalStateException("Display has not been initialialized"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2261 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2262 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2263 | if (mWindowMap.containsKey(client.asBinder())) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2264 | Slog.w(TAG, "Window " + client + " is already added"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2265 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 2266 | } |
| 2267 | |
| 2268 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2269 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2270 | if (attachedWindow == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2271 | 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] | 2272 | + attrs.token + ". Aborting."); |
| 2273 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2274 | } |
| 2275 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 2276 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2277 | 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] | 2278 | + attrs.token + ". Aborting."); |
| 2279 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2280 | } |
| 2281 | } |
| 2282 | |
| 2283 | boolean addToken = false; |
| 2284 | WindowToken token = mTokenMap.get(attrs.token); |
| 2285 | if (token == null) { |
| 2286 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2287 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2288 | 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] | 2289 | + attrs.token + ". Aborting."); |
| 2290 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2291 | } |
| 2292 | if (attrs.type == TYPE_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2293 | 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] | 2294 | + attrs.token + ". Aborting."); |
| 2295 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2296 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2297 | if (attrs.type == TYPE_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2298 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2299 | + attrs.token + ". Aborting."); |
| 2300 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2301 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2302 | token = new WindowToken(attrs.token, -1, false); |
| 2303 | addToken = true; |
| 2304 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2305 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 2306 | AppWindowToken atoken = token.appWindowToken; |
| 2307 | if (atoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2308 | 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] | 2309 | + token + ". Aborting."); |
| 2310 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 2311 | } else if (atoken.removed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2312 | 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] | 2313 | + token + ". Aborting."); |
| 2314 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2315 | } |
| 2316 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 2317 | // No need for this guy! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2318 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2319 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 2320 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 2321 | } |
| 2322 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 2323 | if (token.windowType != TYPE_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2324 | 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] | 2325 | + attrs.token + ". Aborting."); |
| 2326 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2327 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2328 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 2329 | if (token.windowType != TYPE_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2330 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2331 | + attrs.token + ". Aborting."); |
| 2332 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2333 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2334 | } |
| 2335 | |
| 2336 | win = new WindowState(session, client, token, |
| 2337 | attachedWindow, attrs, viewVisibility); |
| 2338 | if (win.mDeathRecipient == null) { |
| 2339 | // Client has apparently died, so there is no reason to |
| 2340 | // continue. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2341 | Slog.w(TAG, "Adding window client " + client.asBinder() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2342 | + " that is dead, aborting."); |
| 2343 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2344 | } |
| 2345 | |
| 2346 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2347 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2348 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 2349 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2350 | return res; |
| 2351 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2352 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2353 | if (outInputChannel != null) { |
| 2354 | String name = win.makeInputChannelName(); |
| 2355 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 2356 | win.mInputChannel = inputChannels[0]; |
| 2357 | inputChannels[1].transferToBinderOutParameter(outInputChannel); |
| 2358 | |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 2359 | mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2360 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2361 | |
| 2362 | // From now on, no exceptions or errors allowed! |
| 2363 | |
| 2364 | res = WindowManagerImpl.ADD_OKAY; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2365 | |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2366 | origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2367 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2368 | if (addToken) { |
| 2369 | mTokenMap.put(attrs.token, token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2370 | } |
| 2371 | win.attach(); |
| 2372 | mWindowMap.put(client.asBinder(), win); |
| 2373 | |
| 2374 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 2375 | token.appWindowToken != null) { |
| 2376 | token.appWindowToken.startingWindow = win; |
| 2377 | } |
| 2378 | |
| 2379 | boolean imMayMove = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2380 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2381 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 2382 | mInputMethodWindow = win; |
| 2383 | addInputMethodWindowToListLocked(win); |
| 2384 | imMayMove = false; |
| 2385 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2386 | mInputMethodDialogs.add(win); |
| 2387 | addWindowToListInOrderLocked(win, true); |
| 2388 | adjustInputMethodDialogsLocked(); |
| 2389 | imMayMove = false; |
| 2390 | } else { |
| 2391 | addWindowToListInOrderLocked(win, true); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2392 | if (attrs.type == TYPE_WALLPAPER) { |
| 2393 | mLastWallpaperTimeoutTime = 0; |
| 2394 | adjustWallpaperWindowsLocked(); |
| 2395 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2396 | adjustWallpaperWindowsLocked(); |
| 2397 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2398 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2399 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2400 | win.mEnterAnimationPending = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2401 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2402 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2403 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2404 | if (mInTouchMode) { |
| 2405 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 2406 | } |
| 2407 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 2408 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 2409 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2410 | |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2411 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 2412 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2413 | boolean focusChanged = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2414 | if (win.canReceiveKeys()) { |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2415 | focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS, |
| 2416 | false /*updateInputWindows*/); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2417 | if (focusChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2418 | imMayMove = false; |
| 2419 | } |
| 2420 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2421 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2422 | if (imMayMove) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2423 | moveInputMethodWindowsIfNeededLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2424 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2425 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2426 | assignLayersLocked(); |
| 2427 | // Don't do layout here, the window must call |
| 2428 | // relayout to be displayed, so we'll do it there. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2429 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2430 | //dump(); |
| 2431 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2432 | if (focusChanged) { |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2433 | finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2434 | } |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2435 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2436 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2437 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2438 | TAG, "New client " + client.asBinder() |
| 2439 | + ": window=" + win); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2440 | |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2441 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2442 | reportNewConfig = true; |
| 2443 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2444 | } |
| 2445 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2446 | if (reportNewConfig) { |
| 2447 | sendNewConfiguration(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2448 | } |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2449 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2450 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2451 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2452 | return res; |
| 2453 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2454 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2455 | public void removeWindow(Session session, IWindow client) { |
| 2456 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2457 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2458 | if (win == null) { |
| 2459 | return; |
| 2460 | } |
| 2461 | removeWindowLocked(session, win); |
| 2462 | } |
| 2463 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2464 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2465 | public void removeWindowLocked(Session session, WindowState win) { |
| 2466 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2467 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2468 | TAG, "Remove " + win + " client=" |
| 2469 | + Integer.toHexString(System.identityHashCode( |
| 2470 | win.mClient.asBinder())) |
| 2471 | + ", surface=" + win.mSurface); |
| 2472 | |
| 2473 | final long origId = Binder.clearCallingIdentity(); |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2474 | |
| 2475 | win.disposeInputChannel(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2476 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2477 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2478 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2479 | + " mExiting=" + win.mExiting |
| 2480 | + " isAnimating=" + win.isAnimating() |
| 2481 | + " app-animation=" |
| 2482 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2483 | + " inPendingTransaction=" |
| 2484 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2485 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2486 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2487 | boolean wasVisible = false; |
| 2488 | // First, see if we need to run an animation. If we do, we have |
| 2489 | // to hold off on removing the window until the animation is done. |
| 2490 | // If the display is frozen, just remove immediately, since the |
| 2491 | // animation wouldn't be seen. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2492 | if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2493 | // If we are not currently running the exit animation, we |
| 2494 | // need to see about starting one. |
| 2495 | if (wasVisible=win.isWinVisibleLw()) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2496 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2497 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2498 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2499 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2500 | } |
| 2501 | // Try starting an animation. |
| 2502 | if (applyAnimationLocked(win, transit, false)) { |
| 2503 | win.mExiting = true; |
| 2504 | } |
| 2505 | } |
| 2506 | if (win.mExiting || win.isAnimating()) { |
| 2507 | // The exit animation is running... wait for it! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2508 | //Slog.i(TAG, "*** Running exit animation..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2509 | win.mExiting = true; |
| 2510 | win.mRemoveOnExit = true; |
| 2511 | mLayoutNeeded = true; |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2512 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 2513 | false /*updateInputWindows*/); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2514 | performLayoutAndPlaceSurfacesLocked(); |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2515 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2516 | if (win.mAppToken != null) { |
| 2517 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2518 | } |
| 2519 | //dump(); |
| 2520 | Binder.restoreCallingIdentity(origId); |
| 2521 | return; |
| 2522 | } |
| 2523 | } |
| 2524 | |
| 2525 | removeWindowInnerLocked(session, win); |
| 2526 | // Removing a visible window will effect the computed orientation |
| 2527 | // So just update orientation if needed. |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2528 | if (wasVisible && computeForcedAppOrientationLocked() |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2529 | != mForcedAppOrientation |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2530 | && updateOrientationFromAppTokensLocked(false)) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2531 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2532 | } |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2533 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2534 | Binder.restoreCallingIdentity(origId); |
| 2535 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2536 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2537 | private void removeWindowInnerLocked(Session session, WindowState win) { |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2538 | if (win.mRemoved) { |
| 2539 | // Nothing to do. |
| 2540 | return; |
| 2541 | } |
| 2542 | |
| 2543 | for (int i=win.mChildWindows.size()-1; i>=0; i--) { |
| 2544 | WindowState cwin = win.mChildWindows.get(i); |
| 2545 | Slog.w(TAG, "Force-removing child win " + cwin + " from container " |
| 2546 | + win); |
| 2547 | removeWindowInnerLocked(cwin.mSession, cwin); |
| 2548 | } |
| 2549 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2550 | win.mRemoved = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2551 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2552 | if (mInputMethodTarget == win) { |
| 2553 | moveInputMethodWindowsIfNeededLocked(false); |
| 2554 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2555 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2556 | if (false) { |
| 2557 | RuntimeException e = new RuntimeException("here"); |
| 2558 | e.fillInStackTrace(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2559 | Slog.w(TAG, "Removing window " + win, e); |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2560 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2561 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2562 | mPolicy.removeWindowLw(win); |
| 2563 | win.removeLocked(); |
| 2564 | |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2565 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2566 | mWindowMap.remove(win.mClient.asBinder()); |
| 2567 | mWindows.remove(win); |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2568 | mPendingRemove.remove(win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2569 | mWindowsChanged = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2570 | 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] | 2571 | |
| 2572 | if (mInputMethodWindow == win) { |
| 2573 | mInputMethodWindow = null; |
| 2574 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2575 | mInputMethodDialogs.remove(win); |
| 2576 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2577 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2578 | final WindowToken token = win.mToken; |
| 2579 | final AppWindowToken atoken = win.mAppToken; |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2580 | 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] | 2581 | token.windows.remove(win); |
| 2582 | if (atoken != null) { |
| 2583 | atoken.allAppWindows.remove(win); |
| 2584 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2585 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2586 | TAG, "**** Removing window " + win + ": count=" |
| 2587 | + token.windows.size()); |
| 2588 | if (token.windows.size() == 0) { |
| 2589 | if (!token.explicit) { |
| 2590 | mTokenMap.remove(token.token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2591 | } else if (atoken != null) { |
| 2592 | atoken.firstWindowDrawn = false; |
| 2593 | } |
| 2594 | } |
| 2595 | |
| 2596 | if (atoken != null) { |
| 2597 | if (atoken.startingWindow == win) { |
| 2598 | atoken.startingWindow = null; |
| 2599 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2600 | // If this is the last window and we had requested a starting |
| 2601 | // transition window, well there is no point now. |
| 2602 | atoken.startingData = null; |
| 2603 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2604 | // If this is the last window except for a starting transition |
| 2605 | // window, we need to get rid of the starting transition. |
| 2606 | if (DEBUG_STARTING_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2607 | Slog.v(TAG, "Schedule remove starting " + token |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2608 | + ": no more real windows"); |
| 2609 | } |
| 2610 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2611 | mH.sendMessage(m); |
| 2612 | } |
| 2613 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2614 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2615 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2616 | mLastWallpaperTimeoutTime = 0; |
| 2617 | adjustWallpaperWindowsLocked(); |
| 2618 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2619 | adjustWallpaperWindowsLocked(); |
| 2620 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2621 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2622 | if (!mInLayout) { |
| 2623 | assignLayersLocked(); |
| 2624 | mLayoutNeeded = true; |
| 2625 | performLayoutAndPlaceSurfacesLocked(); |
| 2626 | if (win.mAppToken != null) { |
| 2627 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2628 | } |
| 2629 | } |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2630 | |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2631 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2632 | } |
| 2633 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2634 | private static void logSurface(WindowState w, String msg, RuntimeException where) { |
| 2635 | String str = " SURFACE " + Integer.toHexString(w.hashCode()) |
| 2636 | + ": " + msg + " / " + w.mAttrs.getTitle(); |
| 2637 | if (where != null) { |
| 2638 | Slog.i(TAG, str, where); |
| 2639 | } else { |
| 2640 | Slog.i(TAG, str); |
| 2641 | } |
| 2642 | } |
| 2643 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2644 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 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) && (w.mSurface != null)) { |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2650 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 2651 | ">>> OPEN TRANSACTION setTransparentRegion"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2652 | Surface.openTransaction(); |
| 2653 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2654 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 2655 | "transparentRegionHint=" + region, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2656 | w.mSurface.setTransparentRegionHint(region); |
| 2657 | } finally { |
| 2658 | Surface.closeTransaction(); |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2659 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 2660 | "<<< CLOSE TRANSACTION setTransparentRegion"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2661 | } |
| 2662 | } |
| 2663 | } |
| 2664 | } finally { |
| 2665 | Binder.restoreCallingIdentity(origId); |
| 2666 | } |
| 2667 | } |
| 2668 | |
| 2669 | void setInsetsWindow(Session session, IWindow client, |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2670 | int touchableInsets, Rect contentInsets, |
| Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2671 | Rect visibleInsets, Region touchableRegion) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2672 | long origId = Binder.clearCallingIdentity(); |
| 2673 | try { |
| 2674 | synchronized (mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2675 | WindowState w = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2676 | if (w != null) { |
| 2677 | w.mGivenInsetsPending = false; |
| 2678 | w.mGivenContentInsets.set(contentInsets); |
| 2679 | w.mGivenVisibleInsets.set(visibleInsets); |
| Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2680 | w.mGivenTouchableRegion.set(touchableRegion); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2681 | w.mTouchableInsets = touchableInsets; |
| 2682 | mLayoutNeeded = true; |
| 2683 | performLayoutAndPlaceSurfacesLocked(); |
| 2684 | } |
| 2685 | } |
| 2686 | } finally { |
| 2687 | Binder.restoreCallingIdentity(origId); |
| 2688 | } |
| 2689 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2690 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2691 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2692 | Rect outDisplayFrame) { |
| 2693 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2694 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2695 | if (win == null) { |
| 2696 | outDisplayFrame.setEmpty(); |
| 2697 | return; |
| 2698 | } |
| 2699 | outDisplayFrame.set(win.mDisplayFrame); |
| 2700 | } |
| 2701 | } |
| 2702 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2703 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2704 | float xStep, float yStep) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2705 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2706 | window.mWallpaperX = x; |
| 2707 | window.mWallpaperY = y; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2708 | window.mWallpaperXStep = xStep; |
| 2709 | window.mWallpaperYStep = yStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2710 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2711 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2712 | } |
| 2713 | } |
| 2714 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2715 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2716 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2717 | synchronized (mWindowMap) { |
| 2718 | if (mWaitingOnWallpaper != null && |
| 2719 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2720 | mWaitingOnWallpaper = null; |
| 2721 | mWindowMap.notifyAll(); |
| 2722 | } |
| 2723 | } |
| 2724 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2725 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2726 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2727 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2728 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2729 | || window == mUpperWallpaperTarget) { |
| 2730 | boolean doWait = sync; |
| 2731 | int curTokenIndex = mWallpaperTokens.size(); |
| 2732 | while (curTokenIndex > 0) { |
| 2733 | curTokenIndex--; |
| 2734 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2735 | int curWallpaperIndex = token.windows.size(); |
| 2736 | while (curWallpaperIndex > 0) { |
| 2737 | curWallpaperIndex--; |
| 2738 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2739 | try { |
| 2740 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2741 | x, y, z, extras, sync); |
| 2742 | // We only want to be synchronous with one wallpaper. |
| 2743 | sync = false; |
| 2744 | } catch (RemoteException e) { |
| 2745 | } |
| 2746 | } |
| 2747 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2748 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2749 | if (doWait) { |
| 2750 | // XXX Need to wait for result. |
| 2751 | } |
| 2752 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2753 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2754 | return null; |
| 2755 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2756 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2757 | public int relayoutWindow(Session session, IWindow client, |
| 2758 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2759 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2760 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2761 | Configuration outConfig, Surface outSurface) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2762 | boolean displayed = false; |
| 2763 | boolean inTouchMode; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2764 | boolean configChanged; |
| Joe Onorato | ac0ee89 | 2011-01-30 15:38:30 -0800 | [diff] [blame] | 2765 | |
| 2766 | // if they don't have this permission, mask out the status bar bits |
| 2767 | if (attrs != null) { |
| 2768 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR) |
| 2769 | != PackageManager.PERMISSION_GRANTED) { |
| 2770 | attrs.systemUiVisibility &= ~StatusBarManager.DISABLE_MASK; |
| 2771 | attrs.subtreeSystemUiVisibility &= ~StatusBarManager.DISABLE_MASK; |
| 2772 | } |
| 2773 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2774 | long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2775 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2776 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2777 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2778 | if (win == null) { |
| 2779 | return 0; |
| 2780 | } |
| 2781 | win.mRequestedWidth = requestedWidth; |
| 2782 | win.mRequestedHeight = requestedHeight; |
| 2783 | |
| 2784 | if (attrs != null) { |
| 2785 | mPolicy.adjustWindowParamsLw(attrs); |
| 2786 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2787 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2788 | int attrChanges = 0; |
| 2789 | int flagChanges = 0; |
| 2790 | if (attrs != null) { |
| 2791 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2792 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2793 | } |
| 2794 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2795 | 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] | 2796 | |
| 2797 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2798 | win.mAlpha = attrs.alpha; |
| 2799 | } |
| 2800 | |
| 2801 | final boolean scaledWindow = |
| 2802 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2803 | |
| 2804 | if (scaledWindow) { |
| 2805 | // requested{Width|Height} Surface's physical size |
| 2806 | // attrs.{width|height} Size on screen |
| 2807 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2808 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2809 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2810 | (attrs.height / (float)requestedHeight) : 1.0f; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2811 | } else { |
| 2812 | win.mHScale = win.mVScale = 1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2813 | } |
| 2814 | |
| 2815 | boolean imMayMove = (flagChanges&( |
| 2816 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2817 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2818 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2819 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2820 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2821 | || (!win.mRelayoutCalled); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2822 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2823 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2824 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2825 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2826 | win.mRelayoutCalled = true; |
| 2827 | final int oldVisibility = win.mViewVisibility; |
| 2828 | win.mViewVisibility = viewVisibility; |
| 2829 | if (viewVisibility == View.VISIBLE && |
| 2830 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2831 | displayed = !win.isVisibleLw(); |
| 2832 | if (win.mExiting) { |
| 2833 | win.mExiting = false; |
| Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 2834 | if (win.mAnimation != null) { |
| 2835 | win.mAnimation.cancel(); |
| 2836 | win.mAnimation = null; |
| 2837 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2838 | } |
| 2839 | if (win.mDestroying) { |
| 2840 | win.mDestroying = false; |
| 2841 | mDestroySurface.remove(win); |
| 2842 | } |
| 2843 | if (oldVisibility == View.GONE) { |
| 2844 | win.mEnterAnimationPending = true; |
| 2845 | } |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2846 | if (displayed) { |
| 2847 | if (win.mSurface != null && !win.mDrawPending |
| 2848 | && !win.mCommitDrawPending && !mDisplayFrozen |
| 2849 | && mPolicy.isScreenOn()) { |
| 2850 | applyEnterAnimationLocked(win); |
| 2851 | } |
| 2852 | if ((win.mAttrs.flags |
| 2853 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2854 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2855 | "Relayout window turning screen on: " + win); |
| 2856 | win.mTurnOnScreen = true; |
| 2857 | } |
| 2858 | int diff = 0; |
| 2859 | if (win.mConfiguration != mCurConfiguration |
| 2860 | && (win.mConfiguration == null |
| 2861 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2862 | win.mConfiguration = mCurConfiguration; |
| 2863 | if (DEBUG_CONFIGURATION) { |
| 2864 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2865 | + win.mConfiguration + " / 0x" |
| 2866 | + Integer.toHexString(diff)); |
| 2867 | } |
| 2868 | outConfig.setTo(mCurConfiguration); |
| 2869 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2870 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2871 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2872 | // To change the format, we need to re-build the surface. |
| 2873 | win.destroySurfaceLocked(); |
| 2874 | displayed = true; |
| 2875 | } |
| 2876 | try { |
| 2877 | Surface surface = win.createSurfaceLocked(); |
| 2878 | if (surface != null) { |
| 2879 | outSurface.copyFrom(surface); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2880 | win.mReportDestroySurface = false; |
| 2881 | win.mSurfacePendingDestroy = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2882 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2883 | " OUT SURFACE " + outSurface + ": copied"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2884 | } else { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2885 | // For some reason there isn't a surface. Clear the |
| 2886 | // caller's object so they see the same state. |
| 2887 | outSurface.release(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2888 | } |
| 2889 | } catch (Exception e) { |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2890 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2891 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2892 | Slog.w(TAG, "Exception thrown when creating surface for client " |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2893 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2894 | e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2895 | Binder.restoreCallingIdentity(origId); |
| 2896 | return 0; |
| 2897 | } |
| 2898 | if (displayed) { |
| 2899 | focusMayChange = true; |
| 2900 | } |
| 2901 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2902 | && mInputMethodWindow == null) { |
| 2903 | mInputMethodWindow = win; |
| 2904 | imMayMove = true; |
| 2905 | } |
| Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2906 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2907 | && win.mAppToken != null |
| 2908 | && win.mAppToken.startingWindow != null) { |
| 2909 | // Special handling of starting window over the base |
| 2910 | // window of the app: propagate lock screen flags to it, |
| 2911 | // to provide the correct semantics while starting. |
| 2912 | final int mask = |
| 2913 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
| Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2914 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2915 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
| Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2916 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2917 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2918 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2919 | } else { |
| 2920 | win.mEnterAnimationPending = false; |
| 2921 | if (win.mSurface != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2922 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2923 | + ": mExiting=" + win.mExiting |
| 2924 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2925 | // If we are not currently running the exit animation, we |
| 2926 | // need to see about starting one. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2927 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2928 | // Try starting an animation; if there isn't one, we |
| 2929 | // can destroy the surface right away. |
| 2930 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2931 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2932 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2933 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2934 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2935 | applyAnimationLocked(win, transit, false)) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2936 | focusMayChange = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2937 | win.mExiting = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2938 | } else if (win.isAnimating()) { |
| 2939 | // Currently in a hide animation... turn this into |
| 2940 | // an exit. |
| 2941 | win.mExiting = true; |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2942 | } else if (win == mWallpaperTarget) { |
| 2943 | // If the wallpaper is currently behind this |
| 2944 | // window, we need to change both of them inside |
| 2945 | // of a transaction to avoid artifacts. |
| 2946 | win.mExiting = true; |
| 2947 | win.mAnimating = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2948 | } else { |
| 2949 | if (mInputMethodWindow == win) { |
| 2950 | mInputMethodWindow = null; |
| 2951 | } |
| 2952 | win.destroySurfaceLocked(); |
| 2953 | } |
| 2954 | } |
| 2955 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2956 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2957 | if (win.mSurface == null || (win.getAttrs().flags |
| 2958 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2959 | || win.mSurfacePendingDestroy) { |
| 2960 | // We are being called from a local process, which |
| 2961 | // means outSurface holds its current surface. Ensure the |
| 2962 | // surface object is cleared, but we don't want it actually |
| 2963 | // destroyed at this point. |
| 2964 | win.mSurfacePendingDestroy = false; |
| 2965 | outSurface.release(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2966 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2967 | } else if (win.mSurface != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2968 | if (DEBUG_VISIBILITY) Slog.i(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2969 | "Keeping surface, will report destroy: " + win); |
| 2970 | win.mReportDestroySurface = true; |
| 2971 | outSurface.copyFrom(win.mSurface); |
| 2972 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2973 | } |
| 2974 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2975 | if (focusMayChange) { |
| 2976 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2977 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 2978 | false /*updateInputWindows*/)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2979 | imMayMove = false; |
| 2980 | } |
| 2981 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2982 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2983 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2984 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2985 | // reassign them at this point if the IM window state gets shuffled |
| 2986 | boolean assignLayers = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2987 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2988 | if (imMayMove) { |
| Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2989 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2990 | // Little hack here -- we -should- be able to rely on the |
| 2991 | // function to return true if the IME has moved and needs |
| 2992 | // its layer recomputed. However, if the IME was hidden |
| 2993 | // and isn't actually moved in the list, its layer may be |
| 2994 | // 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] | 2995 | assignLayers = true; |
| 2996 | } |
| 2997 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2998 | if (wallpaperMayMove) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2999 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3000 | assignLayers = true; |
| 3001 | } |
| 3002 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3003 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3004 | mLayoutNeeded = true; |
| 3005 | win.mGivenInsetsPending = insetsPending; |
| 3006 | if (assignLayers) { |
| 3007 | assignLayersLocked(); |
| 3008 | } |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3009 | configChanged = updateOrientationFromAppTokensLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3010 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3011 | if (displayed && win.mIsWallpaper) { |
| 3012 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 3013 | mDisplay.getHeight(), false); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3014 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3015 | if (win.mAppToken != null) { |
| 3016 | win.mAppToken.updateReportedVisibilityLocked(); |
| 3017 | } |
| 3018 | outFrame.set(win.mFrame); |
| 3019 | outContentInsets.set(win.mContentInsets); |
| 3020 | outVisibleInsets.set(win.mVisibleInsets); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3021 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3022 | TAG, "Relayout given client " + client.asBinder() |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3023 | + ", requestedWidth=" + requestedWidth |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3024 | + ", requestedHeight=" + requestedHeight |
| 3025 | + ", viewVisibility=" + viewVisibility |
| 3026 | + "\nRelayout returning frame=" + outFrame |
| 3027 | + ", surface=" + outSurface); |
| 3028 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3029 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3030 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 3031 | |
| 3032 | inTouchMode = mInTouchMode; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3033 | |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 3034 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3035 | } |
| 3036 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3037 | if (configChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3038 | sendNewConfiguration(); |
| 3039 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3040 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3041 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3042 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3043 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 3044 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 3045 | } |
| 3046 | |
| 3047 | public void finishDrawingWindow(Session session, IWindow client) { |
| 3048 | final long origId = Binder.clearCallingIdentity(); |
| 3049 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3050 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3051 | if (win != null && win.finishDrawingLocked()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 3052 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 3053 | adjustWallpaperWindowsLocked(); |
| 3054 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3055 | mLayoutNeeded = true; |
| 3056 | performLayoutAndPlaceSurfacesLocked(); |
| 3057 | } |
| 3058 | } |
| 3059 | Binder.restoreCallingIdentity(origId); |
| 3060 | } |
| 3061 | |
| 3062 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
| Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 3063 | 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] | 3064 | + (lp != null ? lp.packageName : null) |
| 3065 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 3066 | if (lp != null && lp.windowAnimations != 0) { |
| 3067 | // If this is a system resource, don't try to load it from the |
| 3068 | // application resources. It is nice to avoid loading application |
| 3069 | // resources if we can. |
| 3070 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 3071 | int resId = lp.windowAnimations; |
| 3072 | if ((resId&0xFF000000) == 0x01000000) { |
| 3073 | packageName = "android"; |
| 3074 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3075 | 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] | 3076 | + packageName); |
| 3077 | return AttributeCache.instance().get(packageName, resId, |
| 3078 | com.android.internal.R.styleable.WindowAnimation); |
| 3079 | } |
| 3080 | return null; |
| 3081 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3082 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3083 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
| Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 3084 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3085 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 3086 | if (packageName != null) { |
| 3087 | if ((resId&0xFF000000) == 0x01000000) { |
| 3088 | packageName = "android"; |
| 3089 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3090 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3091 | + packageName); |
| 3092 | return AttributeCache.instance().get(packageName, resId, |
| 3093 | com.android.internal.R.styleable.WindowAnimation); |
| 3094 | } |
| 3095 | return null; |
| 3096 | } |
| 3097 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3098 | private void applyEnterAnimationLocked(WindowState win) { |
| 3099 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 3100 | if (win.mEnterAnimationPending) { |
| 3101 | win.mEnterAnimationPending = false; |
| 3102 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 3103 | } |
| 3104 | |
| 3105 | applyAnimationLocked(win, transit, true); |
| 3106 | } |
| 3107 | |
| 3108 | private boolean applyAnimationLocked(WindowState win, |
| 3109 | int transit, boolean isEntrance) { |
| 3110 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 3111 | // If we are trying to apply an animation, but already running |
| 3112 | // an animation of the same type, then just leave that one alone. |
| 3113 | return true; |
| 3114 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3115 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3116 | // Only apply an animation if the display isn't frozen. If it is |
| 3117 | // frozen, there is no reason to animate and it can cause strange |
| 3118 | // artifacts when we unfreeze the display if some different animation |
| 3119 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3120 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3121 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 3122 | int attr = -1; |
| 3123 | Animation a = null; |
| 3124 | if (anim != 0) { |
| 3125 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 3126 | } else { |
| 3127 | switch (transit) { |
| 3128 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 3129 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 3130 | break; |
| 3131 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 3132 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 3133 | break; |
| 3134 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 3135 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 3136 | break; |
| 3137 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 3138 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 3139 | break; |
| 3140 | } |
| 3141 | if (attr >= 0) { |
| 3142 | a = loadAnimation(win.mAttrs, attr); |
| 3143 | } |
| 3144 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3145 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3146 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 3147 | + " mAnimation=" + win.mAnimation |
| 3148 | + " isEntrance=" + isEntrance); |
| 3149 | if (a != null) { |
| 3150 | if (DEBUG_ANIM) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3151 | RuntimeException e = null; |
| 3152 | if (!HIDE_STACK_CRAWLS) { |
| 3153 | e = new RuntimeException(); |
| 3154 | e.fillInStackTrace(); |
| 3155 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3156 | Slog.v(TAG, "Loaded animation " + a + " for " + win, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3157 | } |
| 3158 | win.setAnimation(a); |
| 3159 | win.mAnimationIsEntrance = isEntrance; |
| 3160 | } |
| 3161 | } else { |
| 3162 | win.clearAnimation(); |
| 3163 | } |
| 3164 | |
| 3165 | return win.mAnimation != null; |
| 3166 | } |
| 3167 | |
| 3168 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 3169 | int anim = 0; |
| 3170 | Context context = mContext; |
| 3171 | if (animAttr >= 0) { |
| 3172 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 3173 | if (ent != null) { |
| 3174 | context = ent.context; |
| 3175 | anim = ent.array.getResourceId(animAttr, 0); |
| 3176 | } |
| 3177 | } |
| 3178 | if (anim != 0) { |
| 3179 | return AnimationUtils.loadAnimation(context, anim); |
| 3180 | } |
| 3181 | return null; |
| 3182 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3183 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3184 | private Animation loadAnimation(String packageName, int resId) { |
| 3185 | int anim = 0; |
| 3186 | Context context = mContext; |
| 3187 | if (resId >= 0) { |
| 3188 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 3189 | if (ent != null) { |
| 3190 | context = ent.context; |
| 3191 | anim = resId; |
| 3192 | } |
| 3193 | } |
| 3194 | if (anim != 0) { |
| 3195 | return AnimationUtils.loadAnimation(context, anim); |
| 3196 | } |
| 3197 | return null; |
| 3198 | } |
| 3199 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3200 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 3201 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 3202 | // Only apply an animation if the display isn't frozen. If it is |
| 3203 | // frozen, there is no reason to animate and it can cause strange |
| 3204 | // artifacts when we unfreeze the display if some different animation |
| 3205 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3206 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3207 | Animation a; |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 3208 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3209 | a = new FadeInOutAnimation(enter); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3210 | if (DEBUG_ANIM) Slog.v(TAG, |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3211 | "applying FadeInOutAnimation for a window in compatibility mode"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3212 | } else if (mNextAppTransitionPackage != null) { |
| 3213 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 3214 | mNextAppTransitionEnter : mNextAppTransitionExit); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3215 | } else { |
| 3216 | int animAttr = 0; |
| 3217 | switch (transit) { |
| 3218 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 3219 | animAttr = enter |
| 3220 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 3221 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 3222 | break; |
| 3223 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 3224 | animAttr = enter |
| 3225 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 3226 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 3227 | break; |
| 3228 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 3229 | animAttr = enter |
| 3230 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 3231 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 3232 | break; |
| 3233 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 3234 | animAttr = enter |
| 3235 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 3236 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 3237 | break; |
| 3238 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 3239 | animAttr = enter |
| 3240 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 3241 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 3242 | break; |
| 3243 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 3244 | animAttr = enter |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 3245 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3246 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 3247 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3248 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3249 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3250 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 3251 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3252 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3253 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3254 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3255 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 3256 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 3257 | break; |
| 3258 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 3259 | animAttr = enter |
| 3260 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 3261 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 3262 | break; |
| 3263 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 3264 | animAttr = enter |
| 3265 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 3266 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3267 | break; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3268 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3269 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3270 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3271 | + " anim=" + a |
| 3272 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 3273 | + " transit=" + transit); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3274 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3275 | if (a != null) { |
| 3276 | if (DEBUG_ANIM) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3277 | RuntimeException e = null; |
| 3278 | if (!HIDE_STACK_CRAWLS) { |
| 3279 | e = new RuntimeException(); |
| 3280 | e.fillInStackTrace(); |
| 3281 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3282 | Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3283 | } |
| 3284 | wtoken.setAnimation(a); |
| 3285 | } |
| 3286 | } else { |
| 3287 | wtoken.clearAnimation(); |
| 3288 | } |
| 3289 | |
| 3290 | return wtoken.animation != null; |
| 3291 | } |
| 3292 | |
| 3293 | // ------------------------------------------------------------- |
| 3294 | // Application Window Tokens |
| 3295 | // ------------------------------------------------------------- |
| 3296 | |
| 3297 | public void validateAppTokens(List tokens) { |
| 3298 | int v = tokens.size()-1; |
| 3299 | int m = mAppTokens.size()-1; |
| 3300 | while (v >= 0 && m >= 0) { |
| 3301 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3302 | if (wtoken.removed) { |
| 3303 | m--; |
| 3304 | continue; |
| 3305 | } |
| 3306 | if (tokens.get(v) != wtoken.token) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3307 | 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] | 3308 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 3309 | } |
| 3310 | v--; |
| 3311 | m--; |
| 3312 | } |
| 3313 | while (v >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3314 | 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] | 3315 | v--; |
| 3316 | } |
| 3317 | while (m >= 0) { |
| 3318 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3319 | if (!wtoken.removed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3320 | Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3321 | } |
| 3322 | m--; |
| 3323 | } |
| 3324 | } |
| 3325 | |
| 3326 | boolean checkCallingPermission(String permission, String func) { |
| 3327 | // Quick check: if the calling permission is me, it's all okay. |
| 3328 | if (Binder.getCallingPid() == Process.myPid()) { |
| 3329 | return true; |
| 3330 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3331 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3332 | if (mContext.checkCallingPermission(permission) |
| 3333 | == PackageManager.PERMISSION_GRANTED) { |
| 3334 | return true; |
| 3335 | } |
| 3336 | String msg = "Permission Denial: " + func + " from pid=" |
| 3337 | + Binder.getCallingPid() |
| 3338 | + ", uid=" + Binder.getCallingUid() |
| 3339 | + " requires " + permission; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3340 | Slog.w(TAG, msg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3341 | return false; |
| 3342 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3343 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3344 | AppWindowToken findAppWindowToken(IBinder token) { |
| 3345 | WindowToken wtoken = mTokenMap.get(token); |
| 3346 | if (wtoken == null) { |
| 3347 | return null; |
| 3348 | } |
| 3349 | return wtoken.appWindowToken; |
| 3350 | } |
| 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 | public void addWindowToken(IBinder token, int type) { |
| 3353 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3354 | "addWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3355 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3356 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3357 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3358 | synchronized(mWindowMap) { |
| 3359 | WindowToken wtoken = mTokenMap.get(token); |
| 3360 | if (wtoken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3361 | 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] | 3362 | return; |
| 3363 | } |
| 3364 | wtoken = new WindowToken(token, type, true); |
| 3365 | mTokenMap.put(token, wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3366 | if (type == TYPE_WALLPAPER) { |
| 3367 | mWallpaperTokens.add(wtoken); |
| 3368 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3369 | } |
| 3370 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3371 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3372 | public void removeWindowToken(IBinder token) { |
| 3373 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3374 | "removeWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3375 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3376 | } |
| 3377 | |
| 3378 | final long origId = Binder.clearCallingIdentity(); |
| 3379 | synchronized(mWindowMap) { |
| 3380 | WindowToken wtoken = mTokenMap.remove(token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3381 | if (wtoken != null) { |
| 3382 | boolean delayed = false; |
| 3383 | if (!wtoken.hidden) { |
| 3384 | wtoken.hidden = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3385 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3386 | final int N = wtoken.windows.size(); |
| 3387 | boolean changed = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3388 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3389 | for (int i=0; i<N; i++) { |
| 3390 | WindowState win = wtoken.windows.get(i); |
| 3391 | |
| 3392 | if (win.isAnimating()) { |
| 3393 | delayed = true; |
| 3394 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3395 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3396 | if (win.isVisibleNow()) { |
| 3397 | applyAnimationLocked(win, |
| 3398 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3399 | changed = true; |
| 3400 | } |
| 3401 | } |
| 3402 | |
| 3403 | if (changed) { |
| 3404 | mLayoutNeeded = true; |
| 3405 | performLayoutAndPlaceSurfacesLocked(); |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3406 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, |
| 3407 | false /*updateInputWindows*/); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3408 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3409 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3410 | if (delayed) { |
| 3411 | mExitingTokens.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3412 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 3413 | mWallpaperTokens.remove(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3414 | } |
| 3415 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3416 | |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 3417 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3418 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3419 | 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] | 3420 | } |
| 3421 | } |
| 3422 | Binder.restoreCallingIdentity(origId); |
| 3423 | } |
| 3424 | |
| 3425 | public void addAppToken(int addPos, IApplicationToken token, |
| 3426 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 3427 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3428 | "addAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3429 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3430 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3431 | |
| 3432 | // Get the dispatching timeout here while we are not holding any locks so that it |
| 3433 | // can be cached by the AppWindowToken. The timeout value is used later by the |
| 3434 | // input dispatcher in code that does hold locks. If we did not cache the value |
| 3435 | // here we would run the chance of introducing a deadlock between the window manager |
| 3436 | // (which holds locks while updating the input dispatcher state) and the activity manager |
| 3437 | // (which holds locks while querying the application token). |
| 3438 | long inputDispatchingTimeoutNanos; |
| 3439 | try { |
| 3440 | inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L; |
| 3441 | } catch (RemoteException ex) { |
| 3442 | Slog.w(TAG, "Could not get dispatching timeout.", ex); |
| 3443 | inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 3444 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3445 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3446 | synchronized(mWindowMap) { |
| 3447 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3448 | if (wtoken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3449 | 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] | 3450 | return; |
| 3451 | } |
| 3452 | wtoken = new AppWindowToken(token); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3453 | wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3454 | wtoken.groupId = groupId; |
| 3455 | wtoken.appFullscreen = fullscreen; |
| 3456 | wtoken.requestedOrientation = requestedOrientation; |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3457 | 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] | 3458 | mAppTokens.add(addPos, wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3459 | mTokenMap.put(token.asBinder(), wtoken); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3460 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3461 | // Application tokens start out hidden. |
| 3462 | wtoken.hidden = true; |
| 3463 | wtoken.hiddenRequested = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3464 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3465 | //dump(); |
| 3466 | } |
| 3467 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3468 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3469 | public void setAppGroupId(IBinder token, int groupId) { |
| 3470 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3471 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3472 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3473 | } |
| 3474 | |
| 3475 | synchronized(mWindowMap) { |
| 3476 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3477 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3478 | 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] | 3479 | return; |
| 3480 | } |
| 3481 | wtoken.groupId = groupId; |
| 3482 | } |
| 3483 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3484 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3485 | public int getOrientationFromWindowsLocked() { |
| 3486 | int pos = mWindows.size() - 1; |
| 3487 | while (pos >= 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3488 | WindowState wtoken = mWindows.get(pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3489 | pos--; |
| 3490 | if (wtoken.mAppToken != null) { |
| 3491 | // We hit an application window. so the orientation will be determined by the |
| 3492 | // app window. No point in continuing further. |
| 3493 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3494 | } |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3495 | if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3496 | continue; |
| 3497 | } |
| 3498 | int req = wtoken.mAttrs.screenOrientation; |
| 3499 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 3500 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 3501 | continue; |
| 3502 | } else { |
| 3503 | return req; |
| 3504 | } |
| 3505 | } |
| 3506 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3507 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3508 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3509 | public int getOrientationFromAppTokensLocked() { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3510 | int pos = mAppTokens.size() - 1; |
| 3511 | int curGroup = 0; |
| 3512 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3513 | boolean findingBehind = false; |
| 3514 | boolean haveGroup = false; |
| 3515 | boolean lastFullscreen = false; |
| 3516 | while (pos >= 0) { |
| 3517 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 3518 | pos--; |
| 3519 | // if we're about to tear down this window and not seek for |
| 3520 | // the behind activity, don't use it for orientation |
| 3521 | if (!findingBehind |
| 3522 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| 3523 | continue; |
| 3524 | } |
| 3525 | |
| 3526 | if (!haveGroup) { |
| 3527 | // We ignore any hidden applications on the top. |
| 3528 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3529 | continue; |
| 3530 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3531 | haveGroup = true; |
| 3532 | curGroup = wtoken.groupId; |
| 3533 | lastOrientation = wtoken.requestedOrientation; |
| 3534 | } else if (curGroup != wtoken.groupId) { |
| 3535 | // If we have hit a new application group, and the bottom |
| 3536 | // of the previous group didn't explicitly say to use |
| 3537 | // the orientation behind it, and the last app was |
| 3538 | // full screen, then we'll stick with the |
| 3539 | // user's orientation. |
| 3540 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3541 | && lastFullscreen) { |
| 3542 | return lastOrientation; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3543 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3544 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3545 | int or = wtoken.requestedOrientation; |
| 3546 | // If this application is fullscreen, and didn't explicitly say |
| 3547 | // to use the orientation behind it, then just take whatever |
| 3548 | // orientation it has and ignores whatever is under it. |
| 3549 | lastFullscreen = wtoken.appFullscreen; |
| 3550 | if (lastFullscreen |
| 3551 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| 3552 | return or; |
| 3553 | } |
| 3554 | // If this application has requested an explicit orientation, |
| 3555 | // then use it. |
| Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 3556 | if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 3557 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3558 | return or; |
| 3559 | } |
| 3560 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| 3561 | } |
| 3562 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3563 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3564 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3565 | public Configuration updateOrientationFromAppTokens( |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3566 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3567 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3568 | "updateOrientationFromAppTokens()")) { |
| 3569 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3570 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3571 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3572 | Configuration config = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3573 | long ident = Binder.clearCallingIdentity(); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3574 | |
| 3575 | synchronized(mWindowMap) { |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3576 | if (updateOrientationFromAppTokensLocked(false)) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3577 | if (freezeThisOneIfNeeded != null) { |
| 3578 | AppWindowToken wtoken = findAppWindowToken( |
| 3579 | freezeThisOneIfNeeded); |
| 3580 | if (wtoken != null) { |
| 3581 | startAppFreezingScreenLocked(wtoken, |
| 3582 | ActivityInfo.CONFIG_ORIENTATION); |
| 3583 | } |
| 3584 | } |
| 3585 | config = computeNewConfigurationLocked(); |
| 3586 | |
| 3587 | } else if (currentConfig != null) { |
| 3588 | // No obvious action we need to take, but if our current |
| Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3589 | // state mismatches the activity manager's, update it, |
| 3590 | // disregarding font scale, which should remain set to |
| 3591 | // the value of the previous configuration. |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3592 | mTempConfiguration.setToDefaults(); |
| Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3593 | mTempConfiguration.fontScale = currentConfig.fontScale; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3594 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3595 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3596 | mWaitingForConfig = true; |
| 3597 | mLayoutNeeded = true; |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3598 | startFreezingDisplayLocked(false); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3599 | config = new Configuration(mTempConfiguration); |
| 3600 | } |
| 3601 | } |
| 3602 | } |
| 3603 | } |
| 3604 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3605 | Binder.restoreCallingIdentity(ident); |
| 3606 | return config; |
| 3607 | } |
| 3608 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3609 | /* |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3610 | * Determine the new desired orientation of the display, returning |
| 3611 | * a non-null new Configuration if it has changed from the current |
| 3612 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3613 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3614 | * SCREEN. This will typically be done for you if you call |
| 3615 | * sendNewConfiguration(). |
| 3616 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3617 | * The orientation is computed from non-application windows first. If none of |
| 3618 | * the non-application windows specify orientation, the orientation is computed from |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3619 | * application tokens. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3620 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3621 | * android.os.IBinder) |
| 3622 | */ |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3623 | boolean updateOrientationFromAppTokensLocked(boolean inTransaction) { |
| 3624 | if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) { |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3625 | // If the display is frozen, some activities may be in the middle |
| 3626 | // of restarting, and thus have removed their old window. If the |
| 3627 | // window has the flag to hide the lock screen, then the lock screen |
| 3628 | // can re-appear and inflict its own orientation on us. Keep the |
| 3629 | // orientation stable until this all settles down. |
| 3630 | return false; |
| 3631 | } |
| 3632 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3633 | boolean changed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3634 | long ident = Binder.clearCallingIdentity(); |
| 3635 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3636 | int req = computeForcedAppOrientationLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3637 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3638 | if (req != mForcedAppOrientation) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3639 | mForcedAppOrientation = req; |
| 3640 | //send a message to Policy indicating orientation change to take |
| 3641 | //action like disabling/enabling sensors etc., |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3642 | mPolicy.setCurrentOrientationLw(req); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3643 | if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION, |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3644 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE, |
| 3645 | inTransaction)) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3646 | changed = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3647 | } |
| 3648 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3649 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3650 | return changed; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3651 | } finally { |
| 3652 | Binder.restoreCallingIdentity(ident); |
| 3653 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3654 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3655 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3656 | int computeForcedAppOrientationLocked() { |
| 3657 | int req = getOrientationFromWindowsLocked(); |
| 3658 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3659 | req = getOrientationFromAppTokensLocked(); |
| 3660 | } |
| 3661 | return req; |
| 3662 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3663 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3664 | public void setNewConfiguration(Configuration config) { |
| 3665 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3666 | "setNewConfiguration()")) { |
| 3667 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3668 | } |
| 3669 | |
| 3670 | synchronized(mWindowMap) { |
| 3671 | mCurConfiguration = new Configuration(config); |
| 3672 | mWaitingForConfig = false; |
| 3673 | performLayoutAndPlaceSurfacesLocked(); |
| 3674 | } |
| 3675 | } |
| 3676 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3677 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3678 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3679 | "setAppOrientation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3680 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3681 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3682 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3683 | synchronized(mWindowMap) { |
| 3684 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3685 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3686 | 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] | 3687 | return; |
| 3688 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3689 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3690 | wtoken.requestedOrientation = requestedOrientation; |
| 3691 | } |
| 3692 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3693 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3694 | public int getAppOrientation(IApplicationToken token) { |
| 3695 | synchronized(mWindowMap) { |
| 3696 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3697 | if (wtoken == null) { |
| 3698 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3699 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3700 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3701 | return wtoken.requestedOrientation; |
| 3702 | } |
| 3703 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3704 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3705 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3706 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3707 | "setFocusedApp()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3708 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3709 | } |
| 3710 | |
| 3711 | synchronized(mWindowMap) { |
| 3712 | boolean changed = false; |
| 3713 | if (token == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3714 | 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] | 3715 | changed = mFocusedApp != null; |
| 3716 | mFocusedApp = null; |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3717 | if (changed) { |
| 3718 | mInputMonitor.setFocusedAppLw(null); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3719 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3720 | } else { |
| 3721 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3722 | if (newFocus == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3723 | 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] | 3724 | return; |
| 3725 | } |
| 3726 | changed = mFocusedApp != newFocus; |
| 3727 | mFocusedApp = newFocus; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3728 | if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3729 | if (changed) { |
| 3730 | mInputMonitor.setFocusedAppLw(newFocus); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3731 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3732 | } |
| 3733 | |
| 3734 | if (moveFocusNow && changed) { |
| 3735 | final long origId = Binder.clearCallingIdentity(); |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3736 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3737 | Binder.restoreCallingIdentity(origId); |
| 3738 | } |
| 3739 | } |
| 3740 | } |
| 3741 | |
| Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 3742 | public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3743 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3744 | "prepareAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3745 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3746 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3747 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3748 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3749 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3750 | TAG, "Prepare app transition: transit=" + transit |
| 3751 | + " mNextAppTransition=" + mNextAppTransition); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3752 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3753 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3754 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3755 | mNextAppTransition = transit; |
| Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 3756 | } else if (!alwaysKeepCurrent) { |
| 3757 | if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3758 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3759 | // Opening a new task always supersedes a close for the anim. |
| 3760 | mNextAppTransition = transit; |
| 3761 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3762 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3763 | // Opening a new activity always supersedes a close for the anim. |
| 3764 | mNextAppTransition = transit; |
| 3765 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3766 | } |
| 3767 | mAppTransitionReady = false; |
| 3768 | mAppTransitionTimeout = false; |
| 3769 | mStartingIconInTransition = false; |
| 3770 | mSkipAppTransitionAnimation = false; |
| 3771 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3772 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3773 | 5000); |
| 3774 | } |
| 3775 | } |
| 3776 | } |
| 3777 | |
| 3778 | public int getPendingAppTransition() { |
| 3779 | return mNextAppTransition; |
| 3780 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3781 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3782 | public void overridePendingAppTransition(String packageName, |
| 3783 | int enterAnim, int exitAnim) { |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3784 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3785 | mNextAppTransitionPackage = packageName; |
| 3786 | mNextAppTransitionEnter = enterAnim; |
| 3787 | mNextAppTransitionExit = exitAnim; |
| 3788 | } |
| 3789 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3790 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3791 | public void executeAppTransition() { |
| 3792 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3793 | "executeAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3794 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3795 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3796 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3797 | synchronized(mWindowMap) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3798 | if (DEBUG_APP_TRANSITIONS) { |
| 3799 | RuntimeException e = new RuntimeException("here"); |
| 3800 | e.fillInStackTrace(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3801 | Slog.w(TAG, "Execute app transition: mNextAppTransition=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3802 | + mNextAppTransition, e); |
| 3803 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3804 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3805 | mAppTransitionReady = true; |
| 3806 | final long origId = Binder.clearCallingIdentity(); |
| 3807 | performLayoutAndPlaceSurfacesLocked(); |
| 3808 | Binder.restoreCallingIdentity(origId); |
| 3809 | } |
| 3810 | } |
| 3811 | } |
| 3812 | |
| 3813 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3814 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
| Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 3815 | int windowFlags, IBinder transferFrom, boolean createIfNeeded) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3816 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3817 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3818 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3819 | } |
| 3820 | |
| 3821 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3822 | if (DEBUG_STARTING_WINDOW) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3823 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3824 | + " transferFrom=" + transferFrom); |
| 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 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3827 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3828 | 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] | 3829 | return; |
| 3830 | } |
| 3831 | |
| 3832 | // If the display is frozen, we won't do anything until the |
| 3833 | // actual window is displayed so there is no reason to put in |
| 3834 | // the starting window. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3835 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3836 | return; |
| 3837 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3838 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3839 | if (wtoken.startingData != null) { |
| 3840 | return; |
| 3841 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3842 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3843 | if (transferFrom != null) { |
| 3844 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3845 | if (ttoken != null) { |
| 3846 | WindowState startingWindow = ttoken.startingWindow; |
| 3847 | if (startingWindow != null) { |
| 3848 | if (mStartingIconInTransition) { |
| 3849 | // In this case, the starting icon has already |
| 3850 | // been displayed, so start letting windows get |
| 3851 | // shown immediately without any more transitions. |
| 3852 | mSkipAppTransitionAnimation = true; |
| 3853 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3854 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3855 | "Moving existing starting from " + ttoken |
| 3856 | + " to " + wtoken); |
| 3857 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3858 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3859 | // Transfer the starting window over to the new |
| 3860 | // token. |
| 3861 | wtoken.startingData = ttoken.startingData; |
| 3862 | wtoken.startingView = ttoken.startingView; |
| 3863 | wtoken.startingWindow = startingWindow; |
| 3864 | ttoken.startingData = null; |
| 3865 | ttoken.startingView = null; |
| 3866 | ttoken.startingWindow = null; |
| 3867 | ttoken.startingMoved = true; |
| 3868 | startingWindow.mToken = wtoken; |
| Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3869 | startingWindow.mRootToken = wtoken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3870 | startingWindow.mAppToken = wtoken; |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3871 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3872 | "Removing starting window: " + startingWindow); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3873 | mWindows.remove(startingWindow); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3874 | mWindowsChanged = true; |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3875 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing starting " + startingWindow |
| 3876 | + " from " + ttoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3877 | ttoken.windows.remove(startingWindow); |
| 3878 | ttoken.allAppWindows.remove(startingWindow); |
| 3879 | addWindowToListInOrderLocked(startingWindow, true); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3880 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3881 | // Propagate other interesting state between the |
| 3882 | // tokens. If the old token is displayed, we should |
| 3883 | // immediately force the new one to be displayed. If |
| 3884 | // it is animating, we need to move that animation to |
| 3885 | // the new one. |
| 3886 | if (ttoken.allDrawn) { |
| 3887 | wtoken.allDrawn = true; |
| 3888 | } |
| 3889 | if (ttoken.firstWindowDrawn) { |
| 3890 | wtoken.firstWindowDrawn = true; |
| 3891 | } |
| 3892 | if (!ttoken.hidden) { |
| 3893 | wtoken.hidden = false; |
| 3894 | wtoken.hiddenRequested = false; |
| 3895 | wtoken.willBeHidden = false; |
| 3896 | } |
| 3897 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3898 | wtoken.clientHidden = ttoken.clientHidden; |
| 3899 | wtoken.sendAppVisibilityToClients(); |
| 3900 | } |
| 3901 | if (ttoken.animation != null) { |
| 3902 | wtoken.animation = ttoken.animation; |
| 3903 | wtoken.animating = ttoken.animating; |
| 3904 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3905 | ttoken.animation = null; |
| 3906 | ttoken.animLayerAdjustment = 0; |
| 3907 | wtoken.updateLayers(); |
| 3908 | ttoken.updateLayers(); |
| 3909 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3910 | |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3911 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 3912 | true /*updateInputWindows*/); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3913 | mLayoutNeeded = true; |
| 3914 | performLayoutAndPlaceSurfacesLocked(); |
| 3915 | Binder.restoreCallingIdentity(origId); |
| 3916 | return; |
| 3917 | } else if (ttoken.startingData != null) { |
| 3918 | // The previous app was getting ready to show a |
| 3919 | // starting window, but hasn't yet done so. Steal it! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3920 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3921 | "Moving pending starting from " + ttoken |
| 3922 | + " to " + wtoken); |
| 3923 | wtoken.startingData = ttoken.startingData; |
| 3924 | ttoken.startingData = null; |
| 3925 | ttoken.startingMoved = true; |
| 3926 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3927 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3928 | // want to process the message ASAP, before any other queued |
| 3929 | // messages. |
| 3930 | mH.sendMessageAtFrontOfQueue(m); |
| 3931 | return; |
| 3932 | } |
| 3933 | } |
| 3934 | } |
| 3935 | |
| 3936 | // There is no existing starting window, and the caller doesn't |
| 3937 | // want us to create one, so that's it! |
| 3938 | if (!createIfNeeded) { |
| 3939 | return; |
| 3940 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3941 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3942 | // If this is a translucent or wallpaper window, then don't |
| 3943 | // show a starting window -- the current effect (a full-screen |
| 3944 | // opaque starting window that fades away to the real contents |
| 3945 | // when it is ready) does not work for this. |
| 3946 | if (theme != 0) { |
| 3947 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3948 | com.android.internal.R.styleable.Window); |
| 3949 | if (ent.array.getBoolean( |
| 3950 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3951 | return; |
| 3952 | } |
| 3953 | if (ent.array.getBoolean( |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3954 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3955 | return; |
| 3956 | } |
| 3957 | if (ent.array.getBoolean( |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3958 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3959 | return; |
| 3960 | } |
| 3961 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3962 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3963 | mStartingIconInTransition = true; |
| 3964 | wtoken.startingData = new StartingData( |
| 3965 | pkg, theme, nonLocalizedLabel, |
| Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 3966 | labelRes, icon, windowFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3967 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3968 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3969 | // want to process the message ASAP, before any other queued |
| 3970 | // messages. |
| 3971 | mH.sendMessageAtFrontOfQueue(m); |
| 3972 | } |
| 3973 | } |
| 3974 | |
| 3975 | public void setAppWillBeHidden(IBinder token) { |
| 3976 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3977 | "setAppWillBeHidden()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3978 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3979 | } |
| 3980 | |
| 3981 | AppWindowToken wtoken; |
| 3982 | |
| 3983 | synchronized(mWindowMap) { |
| 3984 | wtoken = findAppWindowToken(token); |
| 3985 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3986 | 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] | 3987 | return; |
| 3988 | } |
| 3989 | wtoken.willBeHidden = true; |
| 3990 | } |
| 3991 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3992 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3993 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3994 | boolean visible, int transit, boolean performLayout) { |
| 3995 | boolean delayed = false; |
| 3996 | |
| 3997 | if (wtoken.clientHidden == visible) { |
| 3998 | wtoken.clientHidden = !visible; |
| 3999 | wtoken.sendAppVisibilityToClients(); |
| 4000 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4001 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4002 | wtoken.willBeHidden = false; |
| 4003 | if (wtoken.hidden == visible) { |
| 4004 | final int N = wtoken.allAppWindows.size(); |
| 4005 | boolean changed = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4006 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4007 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 4008 | + " performLayout=" + performLayout); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4009 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4010 | boolean runningAppAnimation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4011 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4012 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4013 | if (wtoken.animation == sDummyAnimation) { |
| 4014 | wtoken.animation = null; |
| 4015 | } |
| 4016 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 4017 | changed = true; |
| 4018 | if (wtoken.animation != null) { |
| 4019 | delayed = runningAppAnimation = true; |
| 4020 | } |
| 4021 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4022 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4023 | for (int i=0; i<N; i++) { |
| 4024 | WindowState win = wtoken.allAppWindows.get(i); |
| 4025 | if (win == wtoken.startingWindow) { |
| 4026 | continue; |
| 4027 | } |
| 4028 | |
| 4029 | if (win.isAnimating()) { |
| 4030 | delayed = true; |
| 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 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4034 | //win.dump(" "); |
| 4035 | if (visible) { |
| 4036 | if (!win.isVisibleNow()) { |
| 4037 | if (!runningAppAnimation) { |
| 4038 | applyAnimationLocked(win, |
| 4039 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 4040 | } |
| 4041 | changed = true; |
| 4042 | } |
| 4043 | } else if (win.isVisibleNow()) { |
| 4044 | if (!runningAppAnimation) { |
| 4045 | applyAnimationLocked(win, |
| 4046 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 4047 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4048 | changed = true; |
| 4049 | } |
| 4050 | } |
| 4051 | |
| 4052 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 4053 | if (!visible) { |
| 4054 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 4055 | } else { |
| 4056 | // If we are being set visible, and the starting window is |
| 4057 | // not yet displayed, then make sure it doesn't get displayed. |
| 4058 | WindowState swin = wtoken.startingWindow; |
| 4059 | if (swin != null && (swin.mDrawPending |
| 4060 | || swin.mCommitDrawPending)) { |
| 4061 | swin.mPolicyVisibility = false; |
| 4062 | swin.mPolicyVisibilityAfterAnim = false; |
| 4063 | } |
| 4064 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4065 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4066 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4067 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 4068 | + wtoken.hiddenRequested); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4069 | |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 4070 | if (changed) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4071 | mLayoutNeeded = true; |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4072 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 4073 | if (performLayout) { |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4074 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4075 | false /*updateInputWindows*/); |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 4076 | performLayoutAndPlaceSurfacesLocked(); |
| 4077 | } |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4078 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4079 | } |
| 4080 | } |
| 4081 | |
| 4082 | if (wtoken.animation != null) { |
| 4083 | delayed = true; |
| 4084 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4085 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4086 | return delayed; |
| 4087 | } |
| 4088 | |
| 4089 | public void setAppVisibility(IBinder token, boolean visible) { |
| 4090 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4091 | "setAppVisibility()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4092 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4093 | } |
| 4094 | |
| 4095 | AppWindowToken wtoken; |
| 4096 | |
| 4097 | synchronized(mWindowMap) { |
| 4098 | wtoken = findAppWindowToken(token); |
| 4099 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4100 | 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] | 4101 | return; |
| 4102 | } |
| 4103 | |
| 4104 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 4105 | RuntimeException e = null; |
| 4106 | if (!HIDE_STACK_CRAWLS) { |
| 4107 | e = new RuntimeException(); |
| 4108 | e.fillInStackTrace(); |
| 4109 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4110 | Slog.v(TAG, "setAppVisibility(" + token + ", " + visible |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4111 | + "): mNextAppTransition=" + mNextAppTransition |
| 4112 | + " hidden=" + wtoken.hidden |
| 4113 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 4114 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4115 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4116 | // If we are preparing an app transition, then delay changing |
| 4117 | // the visibility of this token until we execute that transition. |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 4118 | if (!mDisplayFrozen && mPolicy.isScreenOn() |
| 4119 | && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4120 | // Already in requested state, don't do anything more. |
| 4121 | if (wtoken.hiddenRequested != visible) { |
| 4122 | return; |
| 4123 | } |
| 4124 | wtoken.hiddenRequested = !visible; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4125 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4126 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4127 | TAG, "Setting dummy animation on: " + wtoken); |
| 4128 | wtoken.setDummyAnimation(); |
| 4129 | mOpeningApps.remove(wtoken); |
| 4130 | mClosingApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4131 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4132 | wtoken.inPendingTransaction = true; |
| 4133 | if (visible) { |
| 4134 | mOpeningApps.add(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4135 | wtoken.startingDisplayed = false; |
| 4136 | wtoken.startingMoved = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4137 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4138 | // If the token is currently hidden (should be the |
| 4139 | // common case), then we need to set up to wait for |
| 4140 | // its windows to be ready. |
| 4141 | if (wtoken.hidden) { |
| 4142 | wtoken.allDrawn = false; |
| 4143 | wtoken.waitingToShow = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4144 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4145 | if (wtoken.clientHidden) { |
| 4146 | // In the case where we are making an app visible |
| 4147 | // but holding off for a transition, we still need |
| 4148 | // to tell the client to make its windows visible so |
| 4149 | // they get drawn. Otherwise, we will wait on |
| 4150 | // performing the transition until all windows have |
| 4151 | // been drawn, they never will be, and we are sad. |
| 4152 | wtoken.clientHidden = false; |
| 4153 | wtoken.sendAppVisibilityToClients(); |
| 4154 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4155 | } |
| 4156 | } else { |
| 4157 | mClosingApps.add(wtoken); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4158 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4159 | // If the token is currently visible (should be the |
| 4160 | // common case), then set up to wait for it to be hidden. |
| 4161 | if (!wtoken.hidden) { |
| 4162 | wtoken.waitingToHide = true; |
| 4163 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4164 | } |
| 4165 | return; |
| 4166 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4167 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4168 | final long origId = Binder.clearCallingIdentity(); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4169 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4170 | wtoken.updateReportedVisibilityLocked(); |
| 4171 | Binder.restoreCallingIdentity(origId); |
| 4172 | } |
| 4173 | } |
| 4174 | |
| 4175 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4176 | boolean unfreezeSurfaceNow, boolean force) { |
| 4177 | if (wtoken.freezingScreen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4178 | 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] | 4179 | + " force=" + force); |
| 4180 | final int N = wtoken.allAppWindows.size(); |
| 4181 | boolean unfrozeWindows = false; |
| 4182 | for (int i=0; i<N; i++) { |
| 4183 | WindowState w = wtoken.allAppWindows.get(i); |
| 4184 | if (w.mAppFreezing) { |
| 4185 | w.mAppFreezing = false; |
| 4186 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 4187 | w.mOrientationChanging = true; |
| 4188 | } |
| 4189 | unfrozeWindows = true; |
| 4190 | } |
| 4191 | } |
| 4192 | if (force || unfrozeWindows) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4193 | 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] | 4194 | wtoken.freezingScreen = false; |
| 4195 | mAppsFreezingScreen--; |
| 4196 | } |
| 4197 | if (unfreezeSurfaceNow) { |
| 4198 | if (unfrozeWindows) { |
| 4199 | mLayoutNeeded = true; |
| 4200 | performLayoutAndPlaceSurfacesLocked(); |
| 4201 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4202 | stopFreezingDisplayLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4203 | } |
| 4204 | } |
| 4205 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4206 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4207 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4208 | int configChanges) { |
| 4209 | if (DEBUG_ORIENTATION) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 4210 | RuntimeException e = null; |
| 4211 | if (!HIDE_STACK_CRAWLS) { |
| 4212 | e = new RuntimeException(); |
| 4213 | e.fillInStackTrace(); |
| 4214 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4215 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4216 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 4217 | + wtoken.freezingScreen, e); |
| 4218 | } |
| 4219 | if (!wtoken.hiddenRequested) { |
| 4220 | if (!wtoken.freezingScreen) { |
| 4221 | wtoken.freezingScreen = true; |
| 4222 | mAppsFreezingScreen++; |
| 4223 | if (mAppsFreezingScreen == 1) { |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4224 | startFreezingDisplayLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4225 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 4226 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 4227 | 5000); |
| 4228 | } |
| 4229 | } |
| 4230 | final int N = wtoken.allAppWindows.size(); |
| 4231 | for (int i=0; i<N; i++) { |
| 4232 | WindowState w = wtoken.allAppWindows.get(i); |
| 4233 | w.mAppFreezing = true; |
| 4234 | } |
| 4235 | } |
| 4236 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4237 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4238 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 4239 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4240 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4241 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4242 | } |
| 4243 | |
| 4244 | synchronized(mWindowMap) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 4245 | if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4246 | 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] | 4247 | return; |
| 4248 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4249 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4250 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4251 | if (wtoken == null || wtoken.appToken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4252 | 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] | 4253 | return; |
| 4254 | } |
| 4255 | final long origId = Binder.clearCallingIdentity(); |
| 4256 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 4257 | Binder.restoreCallingIdentity(origId); |
| 4258 | } |
| 4259 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4260 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4261 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 4262 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4263 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4264 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4265 | } |
| 4266 | |
| 4267 | synchronized(mWindowMap) { |
| 4268 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4269 | if (wtoken == null || wtoken.appToken == null) { |
| 4270 | return; |
| 4271 | } |
| 4272 | final long origId = Binder.clearCallingIdentity(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4273 | 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] | 4274 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 4275 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 4276 | Binder.restoreCallingIdentity(origId); |
| 4277 | } |
| 4278 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4279 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4280 | public void removeAppToken(IBinder token) { |
| 4281 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4282 | "removeAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4283 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4284 | } |
| 4285 | |
| 4286 | AppWindowToken wtoken = null; |
| 4287 | AppWindowToken startingToken = null; |
| 4288 | boolean delayed = false; |
| 4289 | |
| 4290 | final long origId = Binder.clearCallingIdentity(); |
| 4291 | synchronized(mWindowMap) { |
| 4292 | WindowToken basewtoken = mTokenMap.remove(token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4293 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4294 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4295 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4296 | wtoken.inPendingTransaction = false; |
| 4297 | mOpeningApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4298 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4299 | if (mClosingApps.contains(wtoken)) { |
| 4300 | delayed = true; |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4301 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4302 | mClosingApps.add(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4303 | wtoken.waitingToHide = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4304 | delayed = true; |
| 4305 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4306 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4307 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 4308 | + " animation=" + wtoken.animation |
| 4309 | + " animating=" + wtoken.animating); |
| 4310 | if (delayed) { |
| 4311 | // 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] | 4312 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4313 | "removeAppToken make exiting: " + wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4314 | mExitingAppTokens.add(wtoken); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 4315 | } else { |
| 4316 | // Make sure there is no animation running on this token, |
| 4317 | // so any windows associated with it will be removed as |
| 4318 | // soon as their animations are complete |
| 4319 | wtoken.animation = null; |
| 4320 | wtoken.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4321 | } |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4322 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4323 | "removeAppToken: " + wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4324 | mAppTokens.remove(wtoken); |
| 4325 | wtoken.removed = true; |
| 4326 | if (wtoken.startingData != null) { |
| 4327 | startingToken = wtoken; |
| 4328 | } |
| 4329 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 4330 | if (mFocusedApp == wtoken) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4331 | 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] | 4332 | mFocusedApp = null; |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4333 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4334 | mInputMonitor.setFocusedAppLw(null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4335 | } |
| 4336 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4337 | 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] | 4338 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4339 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4340 | if (!delayed && wtoken != null) { |
| 4341 | wtoken.updateReportedVisibilityLocked(); |
| 4342 | } |
| 4343 | } |
| 4344 | Binder.restoreCallingIdentity(origId); |
| 4345 | |
| 4346 | if (startingToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4347 | 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] | 4348 | + startingToken + ": app token removed"); |
| 4349 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 4350 | mH.sendMessage(m); |
| 4351 | } |
| 4352 | } |
| 4353 | |
| 4354 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 4355 | final int NW = token.windows.size(); |
| 4356 | for (int i=0; i<NW; i++) { |
| 4357 | WindowState win = token.windows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4358 | 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] | 4359 | mWindows.remove(win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4360 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4361 | int j = win.mChildWindows.size(); |
| 4362 | while (j > 0) { |
| 4363 | j--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4364 | WindowState cwin = win.mChildWindows.get(j); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4365 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4366 | "Tmp removing child window " + cwin); |
| 4367 | mWindows.remove(cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4368 | } |
| 4369 | } |
| 4370 | return NW > 0; |
| 4371 | } |
| 4372 | |
| 4373 | void dumpAppTokensLocked() { |
| 4374 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4375 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4376 | } |
| 4377 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4378 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4379 | void dumpWindowsLocked() { |
| 4380 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4381 | Slog.v(TAG, " #" + i + ": " + mWindows.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4382 | } |
| 4383 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4384 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4385 | private int findWindowOffsetLocked(int tokenPos) { |
| 4386 | final int NW = mWindows.size(); |
| 4387 | |
| 4388 | if (tokenPos >= mAppTokens.size()) { |
| 4389 | int i = NW; |
| 4390 | while (i > 0) { |
| 4391 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4392 | WindowState win = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4393 | if (win.getAppToken() != null) { |
| 4394 | return i+1; |
| 4395 | } |
| 4396 | } |
| 4397 | } |
| 4398 | |
| 4399 | while (tokenPos > 0) { |
| 4400 | // Find the first app token below the new position that has |
| 4401 | // a window displayed. |
| 4402 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4403 | 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] | 4404 | + tokenPos + " -- " + wtoken.token); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4405 | if (wtoken.sendingToBottom) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4406 | if (DEBUG_REORDER) Slog.v(TAG, |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4407 | "Skipping token -- currently sending to bottom"); |
| 4408 | tokenPos--; |
| 4409 | continue; |
| 4410 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4411 | int i = wtoken.windows.size(); |
| 4412 | while (i > 0) { |
| 4413 | i--; |
| 4414 | WindowState win = wtoken.windows.get(i); |
| 4415 | int j = win.mChildWindows.size(); |
| 4416 | while (j > 0) { |
| 4417 | j--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4418 | WindowState cwin = win.mChildWindows.get(j); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4419 | if (cwin.mSubLayer >= 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4420 | for (int pos=NW-1; pos>=0; pos--) { |
| 4421 | if (mWindows.get(pos) == cwin) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4422 | if (DEBUG_REORDER) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4423 | "Found child win @" + (pos+1)); |
| 4424 | return pos+1; |
| 4425 | } |
| 4426 | } |
| 4427 | } |
| 4428 | } |
| 4429 | for (int pos=NW-1; pos>=0; pos--) { |
| 4430 | if (mWindows.get(pos) == win) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4431 | 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] | 4432 | return pos+1; |
| 4433 | } |
| 4434 | } |
| 4435 | } |
| 4436 | tokenPos--; |
| 4437 | } |
| 4438 | |
| 4439 | return 0; |
| 4440 | } |
| 4441 | |
| 4442 | private final int reAddWindowLocked(int index, WindowState win) { |
| 4443 | final int NCW = win.mChildWindows.size(); |
| 4444 | boolean added = false; |
| 4445 | for (int j=0; j<NCW; j++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4446 | WindowState cwin = win.mChildWindows.get(j); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4447 | if (!added && cwin.mSubLayer >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4448 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4449 | + index + ": " + cwin); |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4450 | win.mRebuilding = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4451 | mWindows.add(index, win); |
| 4452 | index++; |
| 4453 | added = true; |
| 4454 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4455 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4456 | + index + ": " + cwin); |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4457 | cwin.mRebuilding = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4458 | mWindows.add(index, cwin); |
| 4459 | index++; |
| 4460 | } |
| 4461 | if (!added) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4462 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4463 | + index + ": " + win); |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4464 | win.mRebuilding = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4465 | mWindows.add(index, win); |
| 4466 | index++; |
| 4467 | } |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4468 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4469 | return index; |
| 4470 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4471 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4472 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 4473 | final int NW = token.windows.size(); |
| 4474 | for (int i=0; i<NW; i++) { |
| 4475 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 4476 | } |
| 4477 | return index; |
| 4478 | } |
| 4479 | |
| 4480 | public void moveAppToken(int index, IBinder token) { |
| 4481 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4482 | "moveAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4483 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4484 | } |
| 4485 | |
| 4486 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4487 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4488 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 4489 | final AppWindowToken wtoken = findAppWindowToken(token); |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4490 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG, |
| 4491 | "Start moving token " + wtoken + " initially at " |
| 4492 | + mAppTokens.indexOf(wtoken)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4493 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4494 | 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] | 4495 | + token + " (" + wtoken + ")"); |
| 4496 | return; |
| 4497 | } |
| 4498 | mAppTokens.add(index, wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4499 | if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":"); |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4500 | 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] | 4501 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4502 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4503 | final long origId = Binder.clearCallingIdentity(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4504 | 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] | 4505 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4506 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4507 | 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] | 4508 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4509 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4510 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4511 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4512 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4513 | false /*updateInputWindows*/); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4514 | mLayoutNeeded = true; |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4515 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4516 | performLayoutAndPlaceSurfacesLocked(); |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4517 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4518 | } |
| 4519 | Binder.restoreCallingIdentity(origId); |
| 4520 | } |
| 4521 | } |
| 4522 | |
| 4523 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 4524 | // XXX This should be done more efficiently! |
| 4525 | // (take advantage of the fact that both lists should be |
| 4526 | // ordered in the same way.) |
| 4527 | int N = tokens.size(); |
| 4528 | for (int i=0; i<N; i++) { |
| 4529 | IBinder token = tokens.get(i); |
| 4530 | final AppWindowToken wtoken = findAppWindowToken(token); |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4531 | if (DEBUG_REORDER || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4532 | "Temporarily removing " + wtoken + " from " + mAppTokens.indexOf(wtoken)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4533 | if (!mAppTokens.remove(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4534 | 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] | 4535 | + token + " (" + wtoken + ")"); |
| 4536 | i--; |
| 4537 | N--; |
| 4538 | } |
| 4539 | } |
| 4540 | } |
| 4541 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4542 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 4543 | boolean updateFocusAndLayout) { |
| 4544 | // First remove all of the windows from the list. |
| 4545 | tmpRemoveAppWindowsLocked(wtoken); |
| 4546 | |
| 4547 | // Where to start adding? |
| 4548 | int pos = findWindowOffsetLocked(tokenPos); |
| 4549 | |
| 4550 | // And now add them back at the correct place. |
| 4551 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 4552 | |
| 4553 | if (updateFocusAndLayout) { |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4554 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4555 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4556 | false /*updateInputWindows*/)) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4557 | assignLayersLocked(); |
| 4558 | } |
| 4559 | mLayoutNeeded = true; |
| 4560 | performLayoutAndPlaceSurfacesLocked(); |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4561 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4562 | } |
| 4563 | } |
| 4564 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4565 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 4566 | // First remove all of the windows from the list. |
| 4567 | final int N = tokens.size(); |
| 4568 | int i; |
| 4569 | for (i=0; i<N; i++) { |
| 4570 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4571 | if (token != null) { |
| 4572 | tmpRemoveAppWindowsLocked(token); |
| 4573 | } |
| 4574 | } |
| 4575 | |
| 4576 | // Where to start adding? |
| 4577 | int pos = findWindowOffsetLocked(tokenPos); |
| 4578 | |
| 4579 | // And now add them back at the correct place. |
| 4580 | for (i=0; i<N; i++) { |
| 4581 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4582 | if (token != null) { |
| 4583 | pos = reAddAppWindowsLocked(pos, token); |
| 4584 | } |
| 4585 | } |
| 4586 | |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4587 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4588 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4589 | false /*updateInputWindows*/)) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4590 | assignLayersLocked(); |
| 4591 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4592 | mLayoutNeeded = true; |
| 4593 | performLayoutAndPlaceSurfacesLocked(); |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4594 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4595 | |
| 4596 | //dump(); |
| 4597 | } |
| 4598 | |
| 4599 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4600 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4601 | "moveAppTokensToTop()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4602 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4603 | } |
| 4604 | |
| 4605 | final long origId = Binder.clearCallingIdentity(); |
| 4606 | synchronized(mWindowMap) { |
| 4607 | removeAppTokensLocked(tokens); |
| 4608 | final int N = tokens.size(); |
| 4609 | for (int i=0; i<N; i++) { |
| 4610 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4611 | if (wt != null) { |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4612 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG, |
| 4613 | "Adding next to top: " + wt); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4614 | mAppTokens.add(wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4615 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4616 | mToTopApps.remove(wt); |
| 4617 | mToBottomApps.remove(wt); |
| 4618 | mToTopApps.add(wt); |
| 4619 | wt.sendingToBottom = false; |
| 4620 | wt.sendingToTop = true; |
| 4621 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4622 | } |
| 4623 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4624 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4625 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4626 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4627 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4628 | } |
| 4629 | Binder.restoreCallingIdentity(origId); |
| 4630 | } |
| 4631 | |
| 4632 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4633 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4634 | "moveAppTokensToBottom()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4635 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4636 | } |
| 4637 | |
| 4638 | final long origId = Binder.clearCallingIdentity(); |
| 4639 | synchronized(mWindowMap) { |
| 4640 | removeAppTokensLocked(tokens); |
| 4641 | final int N = tokens.size(); |
| 4642 | int pos = 0; |
| 4643 | for (int i=0; i<N; i++) { |
| 4644 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4645 | if (wt != null) { |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4646 | if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4647 | "Adding next to bottom: " + wt + " at " + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4648 | mAppTokens.add(pos, wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4649 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4650 | mToTopApps.remove(wt); |
| 4651 | mToBottomApps.remove(wt); |
| 4652 | mToBottomApps.add(i, wt); |
| 4653 | wt.sendingToTop = false; |
| 4654 | wt.sendingToBottom = true; |
| 4655 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4656 | pos++; |
| 4657 | } |
| 4658 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4659 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4660 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4661 | moveAppWindowsLocked(tokens, 0); |
| 4662 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4663 | } |
| 4664 | Binder.restoreCallingIdentity(origId); |
| 4665 | } |
| 4666 | |
| 4667 | // ------------------------------------------------------------- |
| 4668 | // Misc IWindowSession methods |
| 4669 | // ------------------------------------------------------------- |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4670 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4671 | private boolean shouldAllowDisableKeyguard() |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4672 | { |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4673 | // We fail safe and prevent disabling keyguard in the unlikely event this gets |
| 4674 | // called before DevicePolicyManagerService has started. |
| 4675 | if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { |
| 4676 | DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( |
| 4677 | Context.DEVICE_POLICY_SERVICE); |
| 4678 | if (dpm != null) { |
| 4679 | mAllowDisableKeyguard = dpm.getPasswordQuality(null) |
| 4680 | == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? |
| 4681 | ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; |
| 4682 | } |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4683 | } |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4684 | return mAllowDisableKeyguard == ALLOW_DISABLE_YES; |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4685 | } |
| 4686 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4687 | public void disableKeyguard(IBinder token, String tag) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4688 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4689 | != PackageManager.PERMISSION_GRANTED) { |
| 4690 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4691 | } |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4692 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4693 | synchronized (mKeyguardTokenWatcher) { |
| 4694 | mKeyguardTokenWatcher.acquire(token, tag); |
| Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4695 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4696 | } |
| 4697 | |
| 4698 | public void reenableKeyguard(IBinder token) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4699 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4700 | != PackageManager.PERMISSION_GRANTED) { |
| 4701 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4702 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4703 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4704 | synchronized (mKeyguardTokenWatcher) { |
| 4705 | mKeyguardTokenWatcher.release(token); |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4706 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4707 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4708 | // If we are the last one to reenable the keyguard wait until |
| 4709 | // we have actually finished reenabling until returning. |
| 4710 | // It is possible that reenableKeyguard() can be called before |
| 4711 | // the previous disableKeyguard() is handled, in which case |
| 4712 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4713 | // be called. In that case mKeyguardDisabled will be false here |
| 4714 | // and we have nothing to wait for. |
| 4715 | while (mKeyguardDisabled) { |
| 4716 | try { |
| 4717 | mKeyguardTokenWatcher.wait(); |
| 4718 | } catch (InterruptedException e) { |
| 4719 | Thread.currentThread().interrupt(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4720 | } |
| 4721 | } |
| 4722 | } |
| 4723 | } |
| 4724 | } |
| 4725 | |
| 4726 | /** |
| 4727 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4728 | */ |
| 4729 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4730 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4731 | != PackageManager.PERMISSION_GRANTED) { |
| 4732 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4733 | } |
| 4734 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4735 | public void onKeyguardExitResult(boolean success) { |
| 4736 | try { |
| 4737 | callback.onKeyguardExitResult(success); |
| 4738 | } catch (RemoteException e) { |
| 4739 | // Client has died, we don't care. |
| 4740 | } |
| 4741 | } |
| 4742 | }); |
| 4743 | } |
| 4744 | |
| 4745 | public boolean inKeyguardRestrictedInputMode() { |
| 4746 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4747 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4748 | |
| Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4749 | public void closeSystemDialogs(String reason) { |
| 4750 | synchronized(mWindowMap) { |
| 4751 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4752 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4753 | if (w.mSurface != null) { |
| 4754 | try { |
| 4755 | w.mClient.closeSystemDialogs(reason); |
| 4756 | } catch (RemoteException e) { |
| 4757 | } |
| 4758 | } |
| 4759 | } |
| 4760 | } |
| 4761 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4762 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4763 | static float fixScale(float scale) { |
| 4764 | if (scale < 0) scale = 0; |
| 4765 | else if (scale > 20) scale = 20; |
| 4766 | return Math.abs(scale); |
| 4767 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4768 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4769 | public void setAnimationScale(int which, float scale) { |
| 4770 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4771 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4772 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4773 | } |
| 4774 | |
| 4775 | if (scale < 0) scale = 0; |
| 4776 | else if (scale > 20) scale = 20; |
| 4777 | scale = Math.abs(scale); |
| 4778 | switch (which) { |
| 4779 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4780 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4781 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4782 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4783 | // Persist setting |
| 4784 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4785 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4786 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4787 | public void setAnimationScales(float[] scales) { |
| 4788 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4789 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4790 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4791 | } |
| 4792 | |
| 4793 | if (scales != null) { |
| 4794 | if (scales.length >= 1) { |
| 4795 | mWindowAnimationScale = fixScale(scales[0]); |
| 4796 | } |
| 4797 | if (scales.length >= 2) { |
| 4798 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4799 | } |
| 4800 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4801 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4802 | // Persist setting |
| 4803 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 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 float getAnimationScale(int which) { |
| 4807 | switch (which) { |
| 4808 | case 0: return mWindowAnimationScale; |
| 4809 | case 1: return mTransitionAnimationScale; |
| 4810 | } |
| 4811 | return 0; |
| 4812 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4813 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4814 | public float[] getAnimationScales() { |
| 4815 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4816 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4817 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4818 | public int getSwitchState(int sw) { |
| 4819 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4820 | "getSwitchState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4821 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4822 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4823 | return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4824 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4825 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4826 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4827 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4828 | "getSwitchStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4829 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4830 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4831 | return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4832 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4833 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4834 | public int getScancodeState(int sw) { |
| 4835 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4836 | "getScancodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4837 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4838 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4839 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4840 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4841 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4842 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4843 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4844 | "getScancodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4845 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4846 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4847 | return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4848 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4849 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4850 | public int getTrackballScancodeState(int sw) { |
| 4851 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4852 | "getTrackballScancodeState()")) { |
| 4853 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4854 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4855 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4856 | } |
| 4857 | |
| 4858 | public int getDPadScancodeState(int sw) { |
| 4859 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4860 | "getDPadScancodeState()")) { |
| 4861 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4862 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4863 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4864 | } |
| 4865 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4866 | public int getKeycodeState(int sw) { |
| 4867 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4868 | "getKeycodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4869 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4870 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4871 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4872 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4873 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4874 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4875 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4876 | "getKeycodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4877 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4878 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4879 | return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4880 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4881 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4882 | public int getTrackballKeycodeState(int sw) { |
| 4883 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4884 | "getTrackballKeycodeState()")) { |
| 4885 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4886 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4887 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4888 | } |
| 4889 | |
| 4890 | public int getDPadKeycodeState(int sw) { |
| 4891 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4892 | "getDPadKeycodeState()")) { |
| 4893 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4894 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4895 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4896 | } |
| Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4897 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4898 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4899 | return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4900 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4901 | |
| Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4902 | public InputChannel monitorInput(String inputChannelName) { |
| 4903 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4904 | "monitorInput()")) { |
| 4905 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4906 | } |
| 4907 | return mInputManager.monitorInput(inputChannelName); |
| 4908 | } |
| 4909 | |
| Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 4910 | public InputDevice getInputDevice(int deviceId) { |
| 4911 | return mInputManager.getInputDevice(deviceId); |
| 4912 | } |
| 4913 | |
| 4914 | public int[] getInputDeviceIds() { |
| 4915 | return mInputManager.getInputDeviceIds(); |
| 4916 | } |
| 4917 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4918 | public void enableScreenAfterBoot() { |
| 4919 | synchronized(mWindowMap) { |
| 4920 | if (mSystemBooted) { |
| 4921 | return; |
| 4922 | } |
| 4923 | mSystemBooted = true; |
| 4924 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4925 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4926 | performEnableScreen(); |
| 4927 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4928 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4929 | public void enableScreenIfNeededLocked() { |
| 4930 | if (mDisplayEnabled) { |
| 4931 | return; |
| 4932 | } |
| 4933 | if (!mSystemBooted) { |
| 4934 | return; |
| 4935 | } |
| 4936 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4937 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4938 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4939 | public void performEnableScreen() { |
| 4940 | synchronized(mWindowMap) { |
| 4941 | if (mDisplayEnabled) { |
| 4942 | return; |
| 4943 | } |
| 4944 | if (!mSystemBooted) { |
| 4945 | return; |
| 4946 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4947 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4948 | // Don't enable the screen until all existing windows |
| 4949 | // have been drawn. |
| 4950 | final int N = mWindows.size(); |
| 4951 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4952 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 4953 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4954 | return; |
| 4955 | } |
| 4956 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4957 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4958 | mDisplayEnabled = true; |
| 4959 | if (false) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4960 | Slog.i(TAG, "ENABLING SCREEN!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4961 | StringWriter sw = new StringWriter(); |
| 4962 | PrintWriter pw = new PrintWriter(sw); |
| 4963 | this.dump(null, pw, null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4964 | Slog.i(TAG, sw.toString()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4965 | } |
| 4966 | try { |
| 4967 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4968 | if (surfaceFlinger != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4969 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4970 | Parcel data = Parcel.obtain(); |
| 4971 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4972 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4973 | data, null, 0); |
| 4974 | data.recycle(); |
| 4975 | } |
| 4976 | } catch (RemoteException ex) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4977 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4978 | } |
| 4979 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4980 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4981 | mPolicy.enableScreenAfterBoot(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4982 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4983 | // Make sure the last requested orientation has been applied. |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4984 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4985 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4986 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4987 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4988 | public void setInTouchMode(boolean mode) { |
| 4989 | synchronized(mWindowMap) { |
| 4990 | mInTouchMode = mode; |
| 4991 | } |
| 4992 | } |
| 4993 | |
| Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 4994 | // TODO: more accounting of which pid(s) turned it on, keep count, |
| 4995 | // only allow disables from pids which have count on, etc. |
| 4996 | public void showStrictModeViolation(boolean on) { |
| 4997 | int pid = Binder.getCallingPid(); |
| 4998 | synchronized(mWindowMap) { |
| 4999 | // Ignoring requests to enable the red border from clients |
| 5000 | // which aren't on screen. (e.g. Broadcast Receivers in |
| 5001 | // the background..) |
| 5002 | if (on) { |
| 5003 | boolean isVisible = false; |
| 5004 | for (WindowState ws : mWindows) { |
| 5005 | if (ws.mSession.mPid == pid && ws.isVisibleLw()) { |
| 5006 | isVisible = true; |
| 5007 | break; |
| 5008 | } |
| 5009 | } |
| 5010 | if (!isVisible) { |
| 5011 | return; |
| 5012 | } |
| 5013 | } |
| 5014 | |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5015 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION showStrictModeViolation"); |
| Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5016 | Surface.openTransaction(); |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5017 | try { |
| 5018 | if (mStrictModeFlash == null) { |
| 5019 | mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession); |
| 5020 | } |
| 5021 | mStrictModeFlash.setVisibility(on); |
| 5022 | } finally { |
| 5023 | Surface.closeTransaction(); |
| 5024 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION showStrictModeViolation"); |
| Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5025 | } |
| Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5026 | } |
| 5027 | } |
| 5028 | |
| Brad Fitzpatrick | c1a968a | 2010-11-24 08:56:40 -0800 | [diff] [blame] | 5029 | public void setStrictModeVisualIndicatorPreference(String value) { |
| 5030 | SystemProperties.set(StrictMode.VISUAL_PROPERTY, value); |
| 5031 | } |
| 5032 | |
| Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5033 | public Bitmap screenshotApplications(IBinder appToken, int maxWidth, int maxHeight) { |
| Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5034 | if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER, |
| 5035 | "screenshotApplications()")) { |
| 5036 | throw new SecurityException("Requires READ_FRAME_BUFFER permission"); |
| 5037 | } |
| 5038 | |
| 5039 | Bitmap rawss; |
| 5040 | |
| Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5041 | int maxLayer = 0; |
| Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5042 | final Rect frame = new Rect(); |
| 5043 | |
| 5044 | float scale; |
| 5045 | int sw, sh, dw, dh; |
| 5046 | int rot; |
| 5047 | |
| 5048 | synchronized(mWindowMap) { |
| 5049 | long ident = Binder.clearCallingIdentity(); |
| 5050 | |
| Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 5051 | dw = mDisplay.getWidth(); |
| 5052 | dh = mDisplay.getHeight(); |
| 5053 | |
| Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5054 | int aboveAppLayer = mPolicy.windowTypeToLayerLw( |
| 5055 | WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER |
| 5056 | + TYPE_LAYER_OFFSET; |
| 5057 | aboveAppLayer += TYPE_LAYER_MULTIPLIER; |
| 5058 | |
| Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 5059 | boolean isImeTarget = mInputMethodTarget != null |
| 5060 | && mInputMethodTarget.mAppToken != null |
| 5061 | && mInputMethodTarget.mAppToken.appToken != null |
| 5062 | && mInputMethodTarget.mAppToken.appToken.asBinder() == appToken; |
| 5063 | |
| Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5064 | // Figure out the part of the screen that is actually the app. |
| Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 5065 | boolean including = false; |
| 5066 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5067 | WindowState ws = mWindows.get(i); |
| 5068 | if (ws.mSurface == null) { |
| 5069 | continue; |
| 5070 | } |
| 5071 | if (ws.mLayer >= aboveAppLayer) { |
| Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5072 | continue; |
| 5073 | } |
| Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 5074 | // When we will skip windows: when we are not including |
| 5075 | // ones behind a window we didn't skip, and we are actually |
| 5076 | // taking a screenshot of a specific app. |
| 5077 | if (!including && appToken != null) { |
| 5078 | // Also, we can possibly skip this window if it is not |
| 5079 | // an IME target or the application for the screenshot |
| 5080 | // is not the current IME target. |
| 5081 | if (!ws.mIsImWindow || !isImeTarget) { |
| 5082 | // And finally, this window is of no interest if it |
| 5083 | // is not associated with the screenshot app. |
| 5084 | if (ws.mAppToken == null || ws.mAppToken.token != appToken) { |
| 5085 | continue; |
| 5086 | } |
| 5087 | } |
| 5088 | } |
| 5089 | |
| 5090 | // We keep on including windows until we go past a full-screen |
| 5091 | // window. |
| 5092 | including = !ws.mIsImWindow && !ws.isFullscreen(dw, dh); |
| 5093 | |
| Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5094 | if (maxLayer < ws.mAnimLayer) { |
| 5095 | maxLayer = ws.mAnimLayer; |
| 5096 | } |
| Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5097 | final Rect wf = ws.mFrame; |
| 5098 | final Rect cr = ws.mContentInsets; |
| 5099 | int left = wf.left + cr.left; |
| 5100 | int top = wf.top + cr.top; |
| 5101 | int right = wf.right - cr.right; |
| 5102 | int bottom = wf.bottom - cr.bottom; |
| 5103 | frame.union(left, top, right, bottom); |
| 5104 | } |
| 5105 | Binder.restoreCallingIdentity(ident); |
| 5106 | |
| Dianne Hackborn | dd962ee | 2011-02-02 11:11:50 -0800 | [diff] [blame] | 5107 | // Constrain frame to the screen size. |
| 5108 | frame.intersect(0, 0, dw, dh); |
| 5109 | |
| Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5110 | if (frame.isEmpty() || maxLayer == 0) { |
| Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5111 | return null; |
| 5112 | } |
| 5113 | |
| 5114 | // The screenshot API does not apply the current screen rotation. |
| 5115 | rot = mDisplay.getRotation(); |
| 5116 | int fw = frame.width(); |
| 5117 | int fh = frame.height(); |
| 5118 | |
| 5119 | // First try reducing to fit in x dimension. |
| 5120 | scale = maxWidth/(float)fw; |
| 5121 | sw = maxWidth; |
| 5122 | sh = (int)(fh*scale); |
| 5123 | if (sh > maxHeight) { |
| 5124 | // y dimension became too long; constrain by that. |
| 5125 | scale = maxHeight/(float)fh; |
| 5126 | sw = (int)(fw*scale); |
| 5127 | sh = maxHeight; |
| 5128 | } |
| 5129 | |
| 5130 | // The screen shot will contain the entire screen. |
| Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 5131 | dw = (int)(dw*scale); |
| 5132 | dh = (int)(dh*scale); |
| Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5133 | if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) { |
| 5134 | int tmp = dw; |
| 5135 | dw = dh; |
| 5136 | dh = tmp; |
| 5137 | rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90; |
| 5138 | } |
| Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5139 | rawss = Surface.screenshot(dw, dh, 0, maxLayer); |
| Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5140 | } |
| 5141 | |
| Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5142 | if (rawss == null) { |
| Dianne Hackborn | 88b03bd | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5143 | Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh |
| 5144 | + ") to layer " + maxLayer); |
| Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5145 | return null; |
| 5146 | } |
| 5147 | |
| Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5148 | Bitmap bm = Bitmap.createBitmap(sw, sh, rawss.getConfig()); |
| 5149 | Matrix matrix = new Matrix(); |
| 5150 | ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix); |
| 5151 | matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale)); |
| 5152 | Canvas canvas = new Canvas(bm); |
| 5153 | canvas.drawBitmap(rawss, matrix, null); |
| 5154 | |
| 5155 | rawss.recycle(); |
| 5156 | return bm; |
| 5157 | } |
| 5158 | |
| Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5159 | public void freezeRotation() { |
| 5160 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| 5161 | "setRotation()")) { |
| 5162 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 5163 | } |
| 5164 | |
| 5165 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation); |
| 5166 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0); |
| 5167 | } |
| 5168 | |
| 5169 | public void thawRotation() { |
| 5170 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| 5171 | "setRotation()")) { |
| 5172 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 5173 | } |
| 5174 | |
| 5175 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0); |
| 5176 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0); |
| 5177 | } |
| 5178 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5179 | public void setRotation(int rotation, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 5180 | boolean alwaysSendConfiguration, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5181 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 5182 | "setRotation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5183 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5184 | } |
| 5185 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 5186 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5187 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5188 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 5189 | public void setRotationUnchecked(int rotation, |
| 5190 | boolean alwaysSendConfiguration, int animFlags) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5191 | if(DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5192 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5193 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5194 | long origId = Binder.clearCallingIdentity(); |
| 5195 | boolean changed; |
| 5196 | synchronized(mWindowMap) { |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5197 | changed = setRotationUncheckedLocked(rotation, animFlags, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5198 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5199 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5200 | if (changed || alwaysSendConfiguration) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5201 | sendNewConfiguration(); |
| 5202 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5203 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5204 | Binder.restoreCallingIdentity(origId); |
| 5205 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5206 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5207 | /** |
| 5208 | * Apply a new rotation to the screen, respecting the requests of |
| 5209 | * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply |
| 5210 | * re-evaluate the desired rotation. |
| 5211 | * |
| 5212 | * Returns null if the rotation has been changed. In this case YOU |
| 5213 | * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN. |
| 5214 | */ |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5215 | public boolean setRotationUncheckedLocked(int rotation, int animFlags, boolean inTransaction) { |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 5216 | if (mDragState != null || mScreenRotationAnimation != null) { |
| Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 5217 | // Potential rotation during a drag. Don't do the rotation now, but make |
| 5218 | // a note to perform the rotation later. |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 5219 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation."); |
| 5220 | if (rotation != WindowManagerPolicy.USE_LAST_ROTATION) { |
| 5221 | mDeferredRotation = rotation; |
| 5222 | mDeferredRotationAnimFlags = animFlags; |
| 5223 | } |
| Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 5224 | return false; |
| 5225 | } |
| 5226 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5227 | boolean changed; |
| 5228 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 5229 | if (mDeferredRotation != WindowManagerPolicy.USE_LAST_ROTATION) { |
| 5230 | rotation = mDeferredRotation; |
| 5231 | mRequestedRotation = rotation; |
| 5232 | mLastRotationFlags = mDeferredRotationAnimFlags; |
| 5233 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5234 | rotation = mRequestedRotation; |
| 5235 | } else { |
| 5236 | mRequestedRotation = rotation; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 5237 | mLastRotationFlags = animFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5238 | } |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 5239 | mDeferredRotation = WindowManagerPolicy.USE_LAST_ROTATION; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5240 | 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] | 5241 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5242 | mRotation, mDisplayEnabled); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5243 | 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] | 5244 | changed = mDisplayEnabled && mRotation != rotation; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5245 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5246 | if (changed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5247 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5248 | "Rotation changed to " + rotation |
| 5249 | + " from " + mRotation |
| 5250 | + " (forceApp=" + mForcedAppOrientation |
| 5251 | + ", req=" + mRequestedRotation + ")"); |
| 5252 | mRotation = rotation; |
| 5253 | mWindowsFreezingScreen = true; |
| 5254 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 5255 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 5256 | 2000); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5257 | mWaitingForConfig = true; |
| 5258 | mLayoutNeeded = true; |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5259 | startFreezingDisplayLocked(inTransaction); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5260 | Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5261 | mInputManager.setDisplayOrientation(0, rotation); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5262 | if (mDisplayEnabled) { |
| Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 5263 | if (CUSTOM_SCREEN_ROTATION) { |
| 5264 | Surface.freezeDisplay(0); |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5265 | if (!inTransaction) { |
| 5266 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 5267 | ">>> OPEN TRANSACTION setRotationUnchecked"); |
| 5268 | Surface.openTransaction(); |
| Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 5269 | } |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5270 | try { |
| 5271 | if (mScreenRotationAnimation != null) { |
| 5272 | mScreenRotationAnimation.setRotation(rotation); |
| 5273 | } |
| 5274 | } finally { |
| 5275 | if (!inTransaction) { |
| 5276 | Surface.closeTransaction(); |
| 5277 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 5278 | "<<< CLOSE TRANSACTION setRotationUnchecked"); |
| 5279 | } |
| 5280 | } |
| Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 5281 | Surface.setOrientation(0, rotation, animFlags); |
| 5282 | Surface.unfreezeDisplay(0); |
| 5283 | } else { |
| 5284 | Surface.setOrientation(0, rotation, animFlags); |
| 5285 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5286 | } |
| 5287 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5288 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5289 | if (w.mSurface != null) { |
| 5290 | w.mOrientationChanging = true; |
| 5291 | } |
| 5292 | } |
| 5293 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 5294 | try { |
| 5295 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 5296 | } catch (RemoteException e) { |
| 5297 | } |
| 5298 | } |
| 5299 | } //end if changed |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5300 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5301 | return changed; |
| 5302 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5303 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5304 | public int getRotation() { |
| 5305 | return mRotation; |
| 5306 | } |
| 5307 | |
| 5308 | public int watchRotation(IRotationWatcher watcher) { |
| 5309 | final IBinder watcherBinder = watcher.asBinder(); |
| 5310 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 5311 | public void binderDied() { |
| 5312 | synchronized (mWindowMap) { |
| 5313 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 5314 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 5315 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 5316 | if (removed != null) { |
| 5317 | removed.asBinder().unlinkToDeath(this, 0); |
| 5318 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5319 | i--; |
| 5320 | } |
| 5321 | } |
| 5322 | } |
| 5323 | } |
| 5324 | }; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5325 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5326 | synchronized (mWindowMap) { |
| 5327 | try { |
| 5328 | watcher.asBinder().linkToDeath(dr, 0); |
| 5329 | mRotationWatchers.add(watcher); |
| 5330 | } catch (RemoteException e) { |
| 5331 | // Client died, no cleanup needed. |
| 5332 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5333 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5334 | return mRotation; |
| 5335 | } |
| 5336 | } |
| 5337 | |
| 5338 | /** |
| 5339 | * Starts the view server on the specified port. |
| 5340 | * |
| 5341 | * @param port The port to listener to. |
| 5342 | * |
| 5343 | * @return True if the server was successfully started, false otherwise. |
| 5344 | * |
| 5345 | * @see com.android.server.ViewServer |
| 5346 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 5347 | */ |
| 5348 | public boolean startViewServer(int port) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5349 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5350 | return false; |
| 5351 | } |
| 5352 | |
| 5353 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 5354 | return false; |
| 5355 | } |
| 5356 | |
| 5357 | if (port < 1024) { |
| 5358 | return false; |
| 5359 | } |
| 5360 | |
| 5361 | if (mViewServer != null) { |
| 5362 | if (!mViewServer.isRunning()) { |
| 5363 | try { |
| 5364 | return mViewServer.start(); |
| 5365 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5366 | Slog.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5367 | } |
| 5368 | } |
| 5369 | return false; |
| 5370 | } |
| 5371 | |
| 5372 | try { |
| 5373 | mViewServer = new ViewServer(this, port); |
| 5374 | return mViewServer.start(); |
| 5375 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5376 | Slog.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5377 | } |
| 5378 | return false; |
| 5379 | } |
| 5380 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5381 | private boolean isSystemSecure() { |
| 5382 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 5383 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 5384 | } |
| 5385 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5386 | /** |
| 5387 | * Stops the view server if it exists. |
| 5388 | * |
| 5389 | * @return True if the server stopped, false if it wasn't started or |
| 5390 | * couldn't be stopped. |
| 5391 | * |
| 5392 | * @see com.android.server.ViewServer |
| 5393 | */ |
| 5394 | public boolean stopViewServer() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5395 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5396 | return false; |
| 5397 | } |
| 5398 | |
| 5399 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 5400 | return false; |
| 5401 | } |
| 5402 | |
| 5403 | if (mViewServer != null) { |
| 5404 | return mViewServer.stop(); |
| 5405 | } |
| 5406 | return false; |
| 5407 | } |
| 5408 | |
| 5409 | /** |
| 5410 | * Indicates whether the view server is running. |
| 5411 | * |
| 5412 | * @return True if the server is running, false otherwise. |
| 5413 | * |
| 5414 | * @see com.android.server.ViewServer |
| 5415 | */ |
| 5416 | public boolean isViewServerRunning() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5417 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5418 | return false; |
| 5419 | } |
| 5420 | |
| 5421 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 5422 | return false; |
| 5423 | } |
| 5424 | |
| 5425 | return mViewServer != null && mViewServer.isRunning(); |
| 5426 | } |
| 5427 | |
| 5428 | /** |
| 5429 | * Lists all availble windows in the system. The listing is written in the |
| 5430 | * specified Socket's output stream with the following syntax: |
| 5431 | * windowHashCodeInHexadecimal windowName |
| 5432 | * Each line of the ouput represents a different window. |
| 5433 | * |
| 5434 | * @param client The remote client to send the listing to. |
| 5435 | * @return False if an error occured, true otherwise. |
| 5436 | */ |
| 5437 | boolean viewServerListWindows(Socket client) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5438 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5439 | return false; |
| 5440 | } |
| 5441 | |
| 5442 | boolean result = true; |
| 5443 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5444 | WindowState[] windows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5445 | synchronized (mWindowMap) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5446 | //noinspection unchecked |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5447 | windows = mWindows.toArray(new WindowState[mWindows.size()]); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5448 | } |
| 5449 | |
| 5450 | BufferedWriter out = null; |
| 5451 | |
| 5452 | // Any uncaught exception will crash the system process |
| 5453 | try { |
| 5454 | OutputStream clientStream = client.getOutputStream(); |
| 5455 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5456 | |
| 5457 | final int count = windows.length; |
| 5458 | for (int i = 0; i < count; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5459 | final WindowState w = windows[i]; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5460 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 5461 | out.write(' '); |
| 5462 | out.append(w.mAttrs.getTitle()); |
| 5463 | out.write('\n'); |
| 5464 | } |
| 5465 | |
| 5466 | out.write("DONE.\n"); |
| 5467 | out.flush(); |
| 5468 | } catch (Exception e) { |
| 5469 | result = false; |
| 5470 | } finally { |
| 5471 | if (out != null) { |
| 5472 | try { |
| 5473 | out.close(); |
| 5474 | } catch (IOException e) { |
| 5475 | result = false; |
| 5476 | } |
| 5477 | } |
| 5478 | } |
| 5479 | |
| 5480 | return result; |
| 5481 | } |
| 5482 | |
| 5483 | /** |
| Konstantin Lopyrev | f962476 | 2010-07-14 17:02:37 -0700 | [diff] [blame] | 5484 | * Returns the focused window in the following format: |
| 5485 | * windowHashCodeInHexadecimal windowName |
| 5486 | * |
| 5487 | * @param client The remote client to send the listing to. |
| 5488 | * @return False if an error occurred, true otherwise. |
| 5489 | */ |
| 5490 | boolean viewServerGetFocusedWindow(Socket client) { |
| 5491 | if (isSystemSecure()) { |
| 5492 | return false; |
| 5493 | } |
| 5494 | |
| 5495 | boolean result = true; |
| 5496 | |
| 5497 | WindowState focusedWindow = getFocusedWindow(); |
| 5498 | |
| 5499 | BufferedWriter out = null; |
| 5500 | |
| 5501 | // Any uncaught exception will crash the system process |
| 5502 | try { |
| 5503 | OutputStream clientStream = client.getOutputStream(); |
| 5504 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5505 | |
| 5506 | if(focusedWindow != null) { |
| 5507 | out.write(Integer.toHexString(System.identityHashCode(focusedWindow))); |
| 5508 | out.write(' '); |
| 5509 | out.append(focusedWindow.mAttrs.getTitle()); |
| 5510 | } |
| 5511 | out.write('\n'); |
| 5512 | out.flush(); |
| 5513 | } catch (Exception e) { |
| 5514 | result = false; |
| 5515 | } finally { |
| 5516 | if (out != null) { |
| 5517 | try { |
| 5518 | out.close(); |
| 5519 | } catch (IOException e) { |
| 5520 | result = false; |
| 5521 | } |
| 5522 | } |
| 5523 | } |
| 5524 | |
| 5525 | return result; |
| 5526 | } |
| 5527 | |
| 5528 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5529 | * Sends a command to a target window. The result of the command, if any, will be |
| 5530 | * written in the output stream of the specified socket. |
| 5531 | * |
| 5532 | * The parameters must follow this syntax: |
| 5533 | * windowHashcode extra |
| 5534 | * |
| 5535 | * Where XX is the length in characeters of the windowTitle. |
| 5536 | * |
| 5537 | * The first parameter is the target window. The window with the specified hashcode |
| 5538 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 5539 | * will be delivered to the target window and as parameters to the command itself. |
| 5540 | * |
| 5541 | * @param client The remote client to sent the result, if any, to. |
| 5542 | * @param command The command to execute. |
| 5543 | * @param parameters The command parameters. |
| 5544 | * |
| 5545 | * @return True if the command was successfully delivered, false otherwise. This does |
| 5546 | * not indicate whether the command itself was successful. |
| 5547 | */ |
| 5548 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5549 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5550 | return false; |
| 5551 | } |
| 5552 | |
| 5553 | boolean success = true; |
| 5554 | Parcel data = null; |
| 5555 | Parcel reply = null; |
| 5556 | |
| Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5557 | BufferedWriter out = null; |
| 5558 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5559 | // Any uncaught exception will crash the system process |
| 5560 | try { |
| 5561 | // Find the hashcode of the window |
| 5562 | int index = parameters.indexOf(' '); |
| 5563 | if (index == -1) { |
| 5564 | index = parameters.length(); |
| 5565 | } |
| 5566 | final String code = parameters.substring(0, index); |
| Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 5567 | int hashCode = (int) Long.parseLong(code, 16); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5568 | |
| 5569 | // Extract the command's parameter after the window description |
| 5570 | if (index < parameters.length()) { |
| 5571 | parameters = parameters.substring(index + 1); |
| 5572 | } else { |
| 5573 | parameters = ""; |
| 5574 | } |
| 5575 | |
| 5576 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 5577 | if (window == null) { |
| 5578 | return false; |
| 5579 | } |
| 5580 | |
| 5581 | data = Parcel.obtain(); |
| 5582 | data.writeInterfaceToken("android.view.IWindow"); |
| 5583 | data.writeString(command); |
| 5584 | data.writeString(parameters); |
| 5585 | data.writeInt(1); |
| 5586 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 5587 | |
| 5588 | reply = Parcel.obtain(); |
| 5589 | |
| 5590 | final IBinder binder = window.mClient.asBinder(); |
| 5591 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 5592 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 5593 | |
| 5594 | reply.readException(); |
| 5595 | |
| Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5596 | if (!client.isOutputShutdown()) { |
| 5597 | out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream())); |
| 5598 | out.write("DONE\n"); |
| 5599 | out.flush(); |
| 5600 | } |
| 5601 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5602 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5603 | 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] | 5604 | success = false; |
| 5605 | } finally { |
| 5606 | if (data != null) { |
| 5607 | data.recycle(); |
| 5608 | } |
| 5609 | if (reply != null) { |
| 5610 | reply.recycle(); |
| 5611 | } |
| Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5612 | if (out != null) { |
| 5613 | try { |
| 5614 | out.close(); |
| 5615 | } catch (IOException e) { |
| 5616 | |
| 5617 | } |
| 5618 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5619 | } |
| 5620 | |
| 5621 | return success; |
| 5622 | } |
| 5623 | |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 5624 | public void addWindowChangeListener(WindowChangeListener listener) { |
| 5625 | synchronized(mWindowMap) { |
| 5626 | mWindowChangeListeners.add(listener); |
| 5627 | } |
| 5628 | } |
| 5629 | |
| 5630 | public void removeWindowChangeListener(WindowChangeListener listener) { |
| 5631 | synchronized(mWindowMap) { |
| 5632 | mWindowChangeListeners.remove(listener); |
| 5633 | } |
| 5634 | } |
| 5635 | |
| 5636 | private void notifyWindowsChanged() { |
| 5637 | WindowChangeListener[] windowChangeListeners; |
| 5638 | synchronized(mWindowMap) { |
| 5639 | if(mWindowChangeListeners.isEmpty()) { |
| 5640 | return; |
| 5641 | } |
| 5642 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5643 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5644 | } |
| 5645 | int N = windowChangeListeners.length; |
| 5646 | for(int i = 0; i < N; i++) { |
| 5647 | windowChangeListeners[i].windowsChanged(); |
| 5648 | } |
| 5649 | } |
| 5650 | |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 5651 | private void notifyFocusChanged() { |
| 5652 | WindowChangeListener[] windowChangeListeners; |
| 5653 | synchronized(mWindowMap) { |
| 5654 | if(mWindowChangeListeners.isEmpty()) { |
| 5655 | return; |
| 5656 | } |
| 5657 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5658 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5659 | } |
| 5660 | int N = windowChangeListeners.length; |
| 5661 | for(int i = 0; i < N; i++) { |
| 5662 | windowChangeListeners[i].focusChanged(); |
| 5663 | } |
| 5664 | } |
| 5665 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5666 | private WindowState findWindow(int hashCode) { |
| 5667 | if (hashCode == -1) { |
| 5668 | return getFocusedWindow(); |
| 5669 | } |
| 5670 | |
| 5671 | synchronized (mWindowMap) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5672 | final ArrayList<WindowState> windows = mWindows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5673 | final int count = windows.size(); |
| 5674 | |
| 5675 | for (int i = 0; i < count; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5676 | WindowState w = windows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5677 | if (System.identityHashCode(w) == hashCode) { |
| 5678 | return w; |
| 5679 | } |
| 5680 | } |
| 5681 | } |
| 5682 | |
| 5683 | return null; |
| 5684 | } |
| 5685 | |
| 5686 | /* |
| 5687 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 5688 | * that to config-changed listeners if appropriate. |
| 5689 | */ |
| 5690 | void sendNewConfiguration() { |
| 5691 | try { |
| 5692 | mActivityManager.updateConfiguration(null); |
| 5693 | } catch (RemoteException e) { |
| 5694 | } |
| 5695 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5696 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5697 | public Configuration computeNewConfiguration() { |
| 5698 | synchronized (mWindowMap) { |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5699 | Configuration config = computeNewConfigurationLocked(); |
| 5700 | if (config == null && mWaitingForConfig) { |
| 5701 | // Nothing changed but we are waiting for something... stop that! |
| 5702 | mWaitingForConfig = false; |
| 5703 | performLayoutAndPlaceSurfacesLocked(); |
| 5704 | } |
| 5705 | return config; |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5706 | } |
| 5707 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5708 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5709 | Configuration computeNewConfigurationLocked() { |
| 5710 | Configuration config = new Configuration(); |
| 5711 | if (!computeNewConfigurationLocked(config)) { |
| 5712 | return null; |
| 5713 | } |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5714 | return config; |
| 5715 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5716 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5717 | boolean computeNewConfigurationLocked(Configuration config) { |
| 5718 | if (mDisplay == null) { |
| 5719 | return false; |
| 5720 | } |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5721 | |
| 5722 | mInputManager.getInputConfiguration(config); |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 5723 | |
| 5724 | // Use the effective "visual" dimensions based on current rotation |
| 5725 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 5726 | || mRotation == Surface.ROTATION_270); |
| 5727 | final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; |
| 5728 | final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; |
| 5729 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5730 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 5731 | if (dw < dh) { |
| 5732 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 5733 | } else if (dw > dh) { |
| 5734 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 5735 | } |
| 5736 | config.orientation = orientation; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5737 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5738 | DisplayMetrics dm = new DisplayMetrics(); |
| 5739 | mDisplay.getMetrics(dm); |
| 5740 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 5741 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5742 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5743 | // Note we only do this once because at this point we don't |
| 5744 | // expect the screen to change in this way at runtime, and want |
| 5745 | // to avoid all of this computation for every config change. |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5746 | int longSize = dw; |
| 5747 | int shortSize = dh; |
| 5748 | if (longSize < shortSize) { |
| 5749 | int tmp = longSize; |
| 5750 | longSize = shortSize; |
| 5751 | shortSize = tmp; |
| 5752 | } |
| 5753 | longSize = (int)(longSize/dm.density); |
| 5754 | shortSize = (int)(shortSize/dm.density); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5755 | |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5756 | // These semi-magic numbers define our compatibility modes for |
| 5757 | // applications with different screens. Don't change unless you |
| 5758 | // make sure to test lots and lots of apps! |
| 5759 | if (longSize < 470) { |
| 5760 | // This is shorter than an HVGA normal density screen (which |
| 5761 | // is 480 pixels on its long side). |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5762 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 5763 | | Configuration.SCREENLAYOUT_LONG_NO; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5764 | } else { |
| Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 5765 | // What size is this screen screen? |
| 5766 | if (longSize >= 800 && shortSize >= 600) { |
| 5767 | // SVGA or larger screens at medium density are the point |
| 5768 | // at which we consider it to be an extra large screen. |
| 5769 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE; |
| Dianne Hackborn | b51dc0f | 2010-10-21 15:34:47 -0700 | [diff] [blame] | 5770 | } else if (longSize >= 530 && shortSize >= 400) { |
| 5771 | // SVGA or larger screens at high density are the point |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5772 | // at which we consider it to be a large screen. |
| 5773 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 5774 | } else { |
| 5775 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
| Dianne Hackborn | e97a12e | 2011-01-29 13:22:02 -0800 | [diff] [blame] | 5776 | } |
| 5777 | |
| 5778 | // If this screen is wider than normal HVGA, or taller |
| 5779 | // than FWVGA, then for old apps we want to run in size |
| 5780 | // compatibility mode. |
| 5781 | if (shortSize > 321 || longSize > 570) { |
| 5782 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5783 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5784 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5785 | // Is this a long screen? |
| 5786 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 5787 | // Anything wider than WVGA (5:3) is considering to be long. |
| 5788 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 5789 | } else { |
| 5790 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 5791 | } |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5792 | } |
| 5793 | } |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5794 | config.screenLayout = mScreenLayout; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5795 | |
| Jeff Brown | 597eec8 | 2011-01-31 17:12:25 -0800 | [diff] [blame] | 5796 | // Determine whether a hard keyboard is available and enabled. |
| Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 5797 | boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS; |
| 5798 | if (hardKeyboardAvailable != mHardKeyboardAvailable) { |
| 5799 | mHardKeyboardAvailable = hardKeyboardAvailable; |
| 5800 | mHardKeyboardEnabled = hardKeyboardAvailable; |
| 5801 | |
| 5802 | mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
| 5803 | mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
| 5804 | } |
| 5805 | if (!mHardKeyboardEnabled) { |
| 5806 | config.keyboard = Configuration.KEYBOARD_NOKEYS; |
| Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 5807 | } |
| Jeff Brown | 597eec8 | 2011-01-31 17:12:25 -0800 | [diff] [blame] | 5808 | |
| 5809 | // Update value of keyboardHidden, hardKeyboardHidden and navigationHidden |
| 5810 | // based on whether a hard or soft keyboard is present, whether navigation keys |
| 5811 | // are present and the lid switch state. |
| 5812 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 5813 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 5814 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO; |
| 5815 | mPolicy.adjustConfigurationLw(config); |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5816 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5817 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5818 | |
| Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 5819 | public boolean isHardKeyboardAvailable() { |
| 5820 | synchronized (mWindowMap) { |
| 5821 | return mHardKeyboardAvailable; |
| 5822 | } |
| 5823 | } |
| 5824 | |
| 5825 | public boolean isHardKeyboardEnabled() { |
| 5826 | synchronized (mWindowMap) { |
| 5827 | return mHardKeyboardEnabled; |
| 5828 | } |
| 5829 | } |
| 5830 | |
| 5831 | public void setHardKeyboardEnabled(boolean enabled) { |
| 5832 | synchronized (mWindowMap) { |
| 5833 | if (mHardKeyboardEnabled != enabled) { |
| 5834 | mHardKeyboardEnabled = enabled; |
| 5835 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 5836 | } |
| 5837 | } |
| 5838 | } |
| 5839 | |
| 5840 | public void setOnHardKeyboardStatusChangeListener( |
| 5841 | OnHardKeyboardStatusChangeListener listener) { |
| 5842 | synchronized (mWindowMap) { |
| 5843 | mHardKeyboardStatusChangeListener = listener; |
| 5844 | } |
| 5845 | } |
| 5846 | |
| 5847 | void notifyHardKeyboardStatusChange() { |
| 5848 | final boolean available, enabled; |
| 5849 | final OnHardKeyboardStatusChangeListener listener; |
| 5850 | synchronized (mWindowMap) { |
| 5851 | listener = mHardKeyboardStatusChangeListener; |
| 5852 | available = mHardKeyboardAvailable; |
| 5853 | enabled = mHardKeyboardEnabled; |
| 5854 | } |
| 5855 | if (listener != null) { |
| 5856 | listener.onHardKeyboardStatusChange(available, enabled); |
| 5857 | } |
| 5858 | } |
| 5859 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5860 | // ------------------------------------------------------------- |
| 5861 | // Drag and drop |
| 5862 | // ------------------------------------------------------------- |
| 5863 | |
| 5864 | IBinder prepareDragSurface(IWindow window, SurfaceSession session, |
| Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 5865 | int flags, int width, int height, Surface outSurface) { |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5866 | if (DEBUG_DRAG) { |
| 5867 | Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height |
| Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 5868 | + " flags=" + Integer.toHexString(flags) + " win=" + window |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5869 | + " asbinder=" + window.asBinder()); |
| 5870 | } |
| 5871 | |
| 5872 | final int callerPid = Binder.getCallingPid(); |
| 5873 | final long origId = Binder.clearCallingIdentity(); |
| 5874 | IBinder token = null; |
| 5875 | |
| 5876 | try { |
| 5877 | synchronized (mWindowMap) { |
| 5878 | try { |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5879 | if (mDragState == null) { |
| 5880 | Surface surface = new Surface(session, callerPid, "drag surface", 0, |
| 5881 | width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN); |
| Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 5882 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DRAG " |
| 5883 | + surface + ": CREATE"); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5884 | outSurface.copyFrom(surface); |
| Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 5885 | final IBinder winBinder = window.asBinder(); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5886 | token = new Binder(); |
| Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 5887 | // TODO: preserve flags param in DragState |
| 5888 | mDragState = new DragState(token, surface, 0, winBinder); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5889 | mDragState.mSurface = surface; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5890 | token = mDragState.mToken = new Binder(); |
| 5891 | |
| 5892 | // 5 second timeout for this window to actually begin the drag |
| Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 5893 | mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder); |
| 5894 | Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5895 | mH.sendMessageDelayed(msg, 5000); |
| 5896 | } else { |
| 5897 | Slog.w(TAG, "Drag already in progress"); |
| 5898 | } |
| 5899 | } catch (Surface.OutOfResourcesException e) { |
| 5900 | Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e); |
| 5901 | if (mDragState != null) { |
| 5902 | mDragState.reset(); |
| 5903 | mDragState = null; |
| 5904 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5905 | } |
| 5906 | } |
| 5907 | } finally { |
| 5908 | Binder.restoreCallingIdentity(origId); |
| 5909 | } |
| 5910 | |
| 5911 | return token; |
| 5912 | } |
| 5913 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5914 | // ------------------------------------------------------------- |
| 5915 | // Input Events and Focus Management |
| 5916 | // ------------------------------------------------------------- |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5917 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5918 | InputMonitor mInputMonitor = new InputMonitor(); |
| 5919 | |
| 5920 | /* Tracks the progress of input dispatch and ensures that input dispatch state |
| 5921 | * is kept in sync with changes in window focus, visibility, registration, and |
| 5922 | * other relevant Window Manager state transitions. */ |
| 5923 | final class InputMonitor { |
| 5924 | // Current window with input focus for keys and other non-touch events. May be null. |
| 5925 | private WindowState mInputFocus; |
| 5926 | |
| 5927 | // When true, prevents input dispatch from proceeding until set to false again. |
| 5928 | private boolean mInputDispatchFrozen; |
| 5929 | |
| 5930 | // When true, input dispatch proceeds normally. Otherwise all events are dropped. |
| 5931 | private boolean mInputDispatchEnabled = true; |
| 5932 | |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 5933 | // When true, need to call updateInputWindowsLw(). |
| 5934 | private boolean mUpdateInputWindowsNeeded = true; |
| 5935 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5936 | // Temporary list of windows information to provide to the input dispatcher. |
| 5937 | private InputWindowList mTempInputWindows = new InputWindowList(); |
| 5938 | |
| 5939 | // Temporary input application object to provide to the input dispatcher. |
| 5940 | private InputApplication mTempInputApplication = new InputApplication(); |
| 5941 | |
| Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 5942 | // Set to true when the first input device configuration change notification |
| 5943 | // is received to indicate that the input devices are ready. |
| 5944 | private final Object mInputDevicesReadyMonitor = new Object(); |
| 5945 | private boolean mInputDevicesReady; |
| 5946 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5947 | /* Notifies the window manager about a broken input channel. |
| 5948 | * |
| 5949 | * Called by the InputManager. |
| 5950 | */ |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5951 | public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) { |
| 5952 | if (inputWindowHandle == null) { |
| 5953 | return; |
| 5954 | } |
| 5955 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5956 | synchronized (mWindowMap) { |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5957 | WindowState windowState = (WindowState) inputWindowHandle.windowState; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5958 | Slog.i(TAG, "WINDOW DIED " + windowState); |
| 5959 | removeWindowLocked(windowState.mSession, windowState); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5960 | } |
| 5961 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5962 | |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5963 | /* Notifies the window manager about an application that is not responding. |
| Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5964 | * 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] | 5965 | * |
| 5966 | * Called by the InputManager. |
| 5967 | */ |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5968 | public long notifyANR(InputApplicationHandle inputApplicationHandle, |
| 5969 | InputWindowHandle inputWindowHandle) { |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5970 | AppWindowToken appWindowToken = null; |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5971 | if (inputWindowHandle != null) { |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5972 | synchronized (mWindowMap) { |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5973 | WindowState windowState = (WindowState) inputWindowHandle.windowState; |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5974 | if (windowState != null) { |
| 5975 | Slog.i(TAG, "Input event dispatching timed out sending to " |
| 5976 | + windowState.mAttrs.getTitle()); |
| 5977 | appWindowToken = windowState.mAppToken; |
| 5978 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5979 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5980 | } |
| 5981 | |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5982 | if (appWindowToken == null && inputApplicationHandle != null) { |
| 5983 | appWindowToken = inputApplicationHandle.appWindowToken; |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5984 | Slog.i(TAG, "Input event dispatching timed out sending to application " |
| 5985 | + appWindowToken.stringName); |
| 5986 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5987 | |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5988 | if (appWindowToken != null && appWindowToken.appToken != null) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5989 | try { |
| 5990 | // Notify the activity manager about the timeout and let it decide whether |
| 5991 | // to abort dispatching or keep waiting. |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5992 | boolean abort = appWindowToken.appToken.keyDispatchingTimedOut(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5993 | if (! abort) { |
| 5994 | // The activity manager declined to abort dispatching. |
| 5995 | // Wait a bit longer and timeout again later. |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5996 | return appWindowToken.inputDispatchingTimeoutNanos; |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5997 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5998 | } catch (RemoteException ex) { |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5999 | } |
| 6000 | } |
| Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 6001 | return 0; // abort dispatching |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6002 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6003 | |
| Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 6004 | private void addDragInputWindowLw(InputWindowList windowList) { |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6005 | final InputWindow inputWindow = windowList.add(); |
| 6006 | inputWindow.inputChannel = mDragState.mServerChannel; |
| 6007 | inputWindow.name = "drag"; |
| Christopher Tate | a159579 | 2011-01-19 17:26:50 -0800 | [diff] [blame] | 6008 | inputWindow.layoutParamsFlags = 0; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6009 | inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG; |
| 6010 | inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 6011 | inputWindow.visible = true; |
| 6012 | inputWindow.canReceiveKeys = false; |
| 6013 | inputWindow.hasFocus = true; |
| 6014 | inputWindow.hasWallpaper = false; |
| 6015 | inputWindow.paused = false; |
| Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 6016 | inputWindow.layer = mDragState.getDragLayerLw(); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6017 | inputWindow.ownerPid = Process.myPid(); |
| 6018 | inputWindow.ownerUid = Process.myUid(); |
| 6019 | |
| 6020 | // The drag window covers the entire display |
| 6021 | inputWindow.frameLeft = 0; |
| 6022 | inputWindow.frameTop = 0; |
| 6023 | inputWindow.frameRight = mDisplay.getWidth(); |
| 6024 | inputWindow.frameBottom = mDisplay.getHeight(); |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 6025 | |
| Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 6026 | // The drag window cannot receive new touches. |
| 6027 | inputWindow.touchableRegion.setEmpty(); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6028 | } |
| 6029 | |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6030 | public void setUpdateInputWindowsNeededLw() { |
| 6031 | mUpdateInputWindowsNeeded = true; |
| 6032 | } |
| 6033 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6034 | /* Updates the cached window information provided to the input dispatcher. */ |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 6035 | public void updateInputWindowsLw(boolean force) { |
| 6036 | if (!force && !mUpdateInputWindowsNeeded) { |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6037 | return; |
| 6038 | } |
| 6039 | mUpdateInputWindowsNeeded = false; |
| 6040 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6041 | // Populate the input window list with information about all of the windows that |
| 6042 | // could potentially receive input. |
| 6043 | // As an optimization, we could try to prune the list of windows but this turns |
| 6044 | // out to be difficult because only the native code knows for sure which window |
| 6045 | // currently has touch focus. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6046 | final ArrayList<WindowState> windows = mWindows; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6047 | |
| 6048 | // If there's a drag in flight, provide a pseudowindow to catch drag input |
| 6049 | final boolean inDrag = (mDragState != null); |
| 6050 | if (inDrag) { |
| 6051 | if (DEBUG_DRAG) { |
| 6052 | Log.d(TAG, "Inserting drag window"); |
| 6053 | } |
| Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 6054 | addDragInputWindowLw(mTempInputWindows); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6055 | } |
| 6056 | |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6057 | final int N = windows.size(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6058 | for (int i = N - 1; i >= 0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6059 | final WindowState child = windows.get(i); |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6060 | if (child.mInputChannel == null || child.mRemoved) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6061 | // Skip this window because it cannot possibly receive input. |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6062 | continue; |
| 6063 | } |
| 6064 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6065 | final int flags = child.mAttrs.flags; |
| 6066 | final int type = child.mAttrs.type; |
| 6067 | |
| 6068 | final boolean hasFocus = (child == mInputFocus); |
| 6069 | final boolean isVisible = child.isVisibleLw(); |
| 6070 | final boolean hasWallpaper = (child == mWallpaperTarget) |
| 6071 | && (type != WindowManager.LayoutParams.TYPE_KEYGUARD); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6072 | |
| 6073 | // If there's a drag in progress and 'child' is a potential drop target, |
| 6074 | // make sure it's been told about the drag |
| 6075 | if (inDrag && isVisible) { |
| 6076 | mDragState.sendDragStartedIfNeededLw(child); |
| 6077 | } |
| 6078 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6079 | // Add a window to our list of input windows. |
| 6080 | final InputWindow inputWindow = mTempInputWindows.add(); |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6081 | inputWindow.inputWindowHandle = child.mInputWindowHandle; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6082 | inputWindow.inputChannel = child.mInputChannel; |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 6083 | inputWindow.name = child.toString(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6084 | inputWindow.layoutParamsFlags = flags; |
| 6085 | inputWindow.layoutParamsType = type; |
| 6086 | inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos(); |
| 6087 | inputWindow.visible = isVisible; |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 6088 | inputWindow.canReceiveKeys = child.canReceiveKeys(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6089 | inputWindow.hasFocus = hasFocus; |
| 6090 | inputWindow.hasWallpaper = hasWallpaper; |
| 6091 | inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false; |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 6092 | inputWindow.layer = child.mLayer; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6093 | inputWindow.ownerPid = child.mSession.mPid; |
| 6094 | inputWindow.ownerUid = child.mSession.mUid; |
| 6095 | |
| 6096 | final Rect frame = child.mFrame; |
| 6097 | inputWindow.frameLeft = frame.left; |
| 6098 | inputWindow.frameTop = frame.top; |
| Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 6099 | inputWindow.frameRight = frame.right; |
| 6100 | inputWindow.frameBottom = frame.bottom; |
| Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 6101 | |
| 6102 | child.getTouchableRegion(inputWindow.touchableRegion); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6103 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6104 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6105 | // Send windows to native code. |
| 6106 | mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray()); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6107 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6108 | // Clear the list in preparation for the next round. |
| 6109 | // Also avoids keeping InputChannel objects referenced unnecessarily. |
| 6110 | mTempInputWindows.clear(); |
| 6111 | } |
| Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 6112 | |
| 6113 | /* Notifies that the input device configuration has changed. */ |
| 6114 | public void notifyConfigurationChanged() { |
| 6115 | sendNewConfiguration(); |
| 6116 | |
| 6117 | synchronized (mInputDevicesReadyMonitor) { |
| 6118 | if (!mInputDevicesReady) { |
| 6119 | mInputDevicesReady = true; |
| 6120 | mInputDevicesReadyMonitor.notifyAll(); |
| 6121 | } |
| 6122 | } |
| 6123 | } |
| 6124 | |
| 6125 | /* Waits until the built-in input devices have been configured. */ |
| 6126 | public boolean waitForInputDevicesReady(long timeoutMillis) { |
| 6127 | synchronized (mInputDevicesReadyMonitor) { |
| 6128 | if (!mInputDevicesReady) { |
| 6129 | try { |
| 6130 | mInputDevicesReadyMonitor.wait(timeoutMillis); |
| 6131 | } catch (InterruptedException ex) { |
| 6132 | } |
| 6133 | } |
| 6134 | return mInputDevicesReady; |
| 6135 | } |
| 6136 | } |
| 6137 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6138 | /* Notifies that the lid switch changed state. */ |
| 6139 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 6140 | mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen); |
| 6141 | } |
| 6142 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6143 | /* Provides an opportunity for the window manager policy to intercept early key |
| 6144 | * processing as soon as the key has been read from the device. */ |
| Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 6145 | public int interceptKeyBeforeQueueing( |
| 6146 | KeyEvent event, int policyFlags, boolean isScreenOn) { |
| 6147 | return mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6148 | } |
| 6149 | |
| 6150 | /* Provides an opportunity for the window manager policy to process a key before |
| 6151 | * ordinary dispatch. */ |
| Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 6152 | public boolean interceptKeyBeforeDispatching( |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6153 | InputWindowHandle focus, KeyEvent event, int policyFlags) { |
| Jeff Brown | 00ae87d | 2011-01-13 19:58:24 -0800 | [diff] [blame] | 6154 | WindowState windowState = focus != null ? (WindowState) focus.windowState : null; |
| Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 6155 | return mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6156 | } |
| 6157 | |
| Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 6158 | /* Provides an opportunity for the window manager policy to process a key that |
| 6159 | * the application did not handle. */ |
| Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 6160 | public KeyEvent dispatchUnhandledKey( |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6161 | InputWindowHandle focus, KeyEvent event, int policyFlags) { |
| Jeff Brown | 00ae87d | 2011-01-13 19:58:24 -0800 | [diff] [blame] | 6162 | WindowState windowState = focus != null ? (WindowState) focus.windowState : null; |
| Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 6163 | return mPolicy.dispatchUnhandledKey(windowState, event, policyFlags); |
| Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 6164 | } |
| 6165 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6166 | /* Called when the current input focus changes. |
| 6167 | * Layer assignment is assumed to be complete by the time this is called. |
| 6168 | */ |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6169 | public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6170 | if (DEBUG_INPUT) { |
| 6171 | Slog.d(TAG, "Input focus has changed to " + newWindow); |
| 6172 | } |
| 6173 | |
| 6174 | if (newWindow != mInputFocus) { |
| 6175 | if (newWindow != null && newWindow.canReceiveKeys()) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6176 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 6177 | // This is to protect against bugs if someone pauses dispatching but |
| 6178 | // forgets to resume. |
| 6179 | newWindow.mToken.paused = false; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6180 | } |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6181 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6182 | mInputFocus = newWindow; |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6183 | setUpdateInputWindowsNeededLw(); |
| 6184 | |
| 6185 | if (updateInputWindows) { |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 6186 | updateInputWindowsLw(false /*force*/); |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6187 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6188 | } |
| 6189 | } |
| 6190 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6191 | public void setFocusedAppLw(AppWindowToken newApp) { |
| 6192 | // Focused app has changed. |
| 6193 | if (newApp == null) { |
| 6194 | mInputManager.setFocusedApplication(null); |
| 6195 | } else { |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6196 | mTempInputApplication.inputApplicationHandle = newApp.mInputApplicationHandle; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6197 | mTempInputApplication.name = newApp.toString(); |
| 6198 | mTempInputApplication.dispatchingTimeoutNanos = |
| 6199 | newApp.inputDispatchingTimeoutNanos; |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6200 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6201 | mInputManager.setFocusedApplication(mTempInputApplication); |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6202 | |
| 6203 | mTempInputApplication.recycle(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6204 | } |
| 6205 | } |
| 6206 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6207 | public void pauseDispatchingLw(WindowToken window) { |
| 6208 | if (! window.paused) { |
| 6209 | if (DEBUG_INPUT) { |
| 6210 | Slog.v(TAG, "Pausing WindowToken " + window); |
| 6211 | } |
| 6212 | |
| 6213 | window.paused = true; |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 6214 | updateInputWindowsLw(true /*force*/); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6215 | } |
| 6216 | } |
| 6217 | |
| 6218 | public void resumeDispatchingLw(WindowToken window) { |
| 6219 | if (window.paused) { |
| 6220 | if (DEBUG_INPUT) { |
| 6221 | Slog.v(TAG, "Resuming WindowToken " + window); |
| 6222 | } |
| 6223 | |
| 6224 | window.paused = false; |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 6225 | updateInputWindowsLw(true /*force*/); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6226 | } |
| 6227 | } |
| 6228 | |
| 6229 | public void freezeInputDispatchingLw() { |
| 6230 | if (! mInputDispatchFrozen) { |
| 6231 | if (DEBUG_INPUT) { |
| 6232 | Slog.v(TAG, "Freezing input dispatching"); |
| 6233 | } |
| 6234 | |
| 6235 | mInputDispatchFrozen = true; |
| 6236 | updateInputDispatchModeLw(); |
| 6237 | } |
| 6238 | } |
| 6239 | |
| 6240 | public void thawInputDispatchingLw() { |
| 6241 | if (mInputDispatchFrozen) { |
| 6242 | if (DEBUG_INPUT) { |
| 6243 | Slog.v(TAG, "Thawing input dispatching"); |
| 6244 | } |
| 6245 | |
| 6246 | mInputDispatchFrozen = false; |
| 6247 | updateInputDispatchModeLw(); |
| 6248 | } |
| 6249 | } |
| 6250 | |
| 6251 | public void setEventDispatchingLw(boolean enabled) { |
| 6252 | if (mInputDispatchEnabled != enabled) { |
| 6253 | if (DEBUG_INPUT) { |
| 6254 | Slog.v(TAG, "Setting event dispatching to " + enabled); |
| 6255 | } |
| 6256 | |
| 6257 | mInputDispatchEnabled = enabled; |
| 6258 | updateInputDispatchModeLw(); |
| 6259 | } |
| 6260 | } |
| 6261 | |
| 6262 | private void updateInputDispatchModeLw() { |
| 6263 | mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen); |
| 6264 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6265 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6266 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6267 | public void pauseKeyDispatching(IBinder _token) { |
| 6268 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 6269 | "pauseKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6270 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6271 | } |
| 6272 | |
| 6273 | synchronized (mWindowMap) { |
| 6274 | WindowToken token = mTokenMap.get(_token); |
| 6275 | if (token != null) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6276 | mInputMonitor.pauseDispatchingLw(token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6277 | } |
| 6278 | } |
| 6279 | } |
| 6280 | |
| 6281 | public void resumeKeyDispatching(IBinder _token) { |
| 6282 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 6283 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6284 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6285 | } |
| 6286 | |
| 6287 | synchronized (mWindowMap) { |
| 6288 | WindowToken token = mTokenMap.get(_token); |
| 6289 | if (token != null) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6290 | mInputMonitor.resumeDispatchingLw(token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6291 | } |
| 6292 | } |
| 6293 | } |
| 6294 | |
| 6295 | public void setEventDispatching(boolean enabled) { |
| 6296 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 6297 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6298 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6299 | } |
| 6300 | |
| 6301 | synchronized (mWindowMap) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6302 | mInputMonitor.setEventDispatchingLw(enabled); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6303 | } |
| 6304 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6305 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6306 | /** |
| 6307 | * Injects a keystroke event into the UI. |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6308 | * Even when sync is false, this method may block while waiting for current |
| 6309 | * input events to be dispatched. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6310 | * |
| 6311 | * @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] | 6312 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 6313 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 6314 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6315 | */ |
| 6316 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 6317 | long downTime = ev.getDownTime(); |
| 6318 | long eventTime = ev.getEventTime(); |
| 6319 | |
| 6320 | int action = ev.getAction(); |
| 6321 | int code = ev.getKeyCode(); |
| 6322 | int repeatCount = ev.getRepeatCount(); |
| 6323 | int metaState = ev.getMetaState(); |
| 6324 | int deviceId = ev.getDeviceId(); |
| 6325 | int scancode = ev.getScanCode(); |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6326 | int source = ev.getSource(); |
| Mike Playle | c6ded10 | 2010-11-29 16:01:03 +0000 | [diff] [blame] | 6327 | int flags = ev.getFlags(); |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6328 | |
| 6329 | if (source == InputDevice.SOURCE_UNKNOWN) { |
| 6330 | source = InputDevice.SOURCE_KEYBOARD; |
| 6331 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6332 | |
| 6333 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 6334 | if (downTime == 0) downTime = eventTime; |
| 6335 | |
| 6336 | KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, |
| Jean-Baptiste Queru | 4a88013 | 2010-12-02 15:16:53 -0800 | [diff] [blame] | 6337 | deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6338 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6339 | final int pid = Binder.getCallingPid(); |
| 6340 | final int uid = Binder.getCallingUid(); |
| 6341 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6342 | |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6343 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 6344 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 6345 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 6346 | INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6347 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6348 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6349 | return reportInjectionResult(result); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6350 | } |
| 6351 | |
| 6352 | /** |
| 6353 | * Inject a pointer (touch) event into the UI. |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6354 | * Even when sync is false, this method may block while waiting for current |
| 6355 | * input events to be dispatched. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6356 | * |
| 6357 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 6358 | * {@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] | 6359 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 6360 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 6361 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6362 | */ |
| 6363 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6364 | final int pid = Binder.getCallingPid(); |
| 6365 | final int uid = Binder.getCallingUid(); |
| 6366 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6367 | |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6368 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 6369 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) { |
| 6370 | newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 6371 | } |
| 6372 | |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6373 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 6374 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 6375 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 6376 | INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6377 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6378 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6379 | return reportInjectionResult(result); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6380 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6381 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6382 | /** |
| 6383 | * Inject a trackball (navigation device) event into the UI. |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6384 | * Even when sync is false, this method may block while waiting for current |
| 6385 | * input events to be dispatched. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6386 | * |
| 6387 | * @param ev A motion event describing the trackball action. (As noted in |
| 6388 | * {@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] | 6389 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 6390 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 6391 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6392 | */ |
| 6393 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6394 | final int pid = Binder.getCallingPid(); |
| 6395 | final int uid = Binder.getCallingUid(); |
| 6396 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6397 | |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6398 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 6399 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) { |
| 6400 | newEvent.setSource(InputDevice.SOURCE_TRACKBALL); |
| 6401 | } |
| 6402 | |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6403 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 6404 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 6405 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 6406 | INJECTION_TIMEOUT_MILLIS); |
| 6407 | |
| 6408 | Binder.restoreCallingIdentity(ident); |
| 6409 | return reportInjectionResult(result); |
| 6410 | } |
| 6411 | |
| 6412 | /** |
| 6413 | * Inject an input event into the UI without waiting for dispatch to commence. |
| 6414 | * This variant is useful for fire-and-forget input event injection. It does not |
| 6415 | * block any longer than it takes to enqueue the input event. |
| 6416 | * |
| 6417 | * @param ev An input event. (Be sure to set the input source correctly.) |
| 6418 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6419 | */ |
| 6420 | public boolean injectInputEventNoWait(InputEvent ev) { |
| 6421 | final int pid = Binder.getCallingPid(); |
| 6422 | final int uid = Binder.getCallingUid(); |
| 6423 | final long ident = Binder.clearCallingIdentity(); |
| 6424 | |
| 6425 | final int result = mInputManager.injectInputEvent(ev, pid, uid, |
| 6426 | InputManager.INPUT_EVENT_INJECTION_SYNC_NONE, |
| 6427 | INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6428 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6429 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6430 | return reportInjectionResult(result); |
| 6431 | } |
| 6432 | |
| 6433 | private boolean reportInjectionResult(int result) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6434 | switch (result) { |
| 6435 | case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED: |
| 6436 | Slog.w(TAG, "Input event injection permission denied."); |
| 6437 | throw new SecurityException( |
| 6438 | "Injecting to another application requires INJECT_EVENTS permission"); |
| 6439 | case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED: |
| Christopher Tate | 09e85dc | 2010-08-02 11:54:41 -0700 | [diff] [blame] | 6440 | //Slog.v(TAG, "Input event injection succeeded."); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6441 | return true; |
| 6442 | case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT: |
| 6443 | Slog.w(TAG, "Input event injection timed out."); |
| 6444 | return false; |
| 6445 | case InputManager.INPUT_EVENT_INJECTION_FAILED: |
| 6446 | default: |
| 6447 | Slog.w(TAG, "Input event injection failed."); |
| 6448 | return false; |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6449 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6450 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6451 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6452 | private WindowState getFocusedWindow() { |
| 6453 | synchronized (mWindowMap) { |
| 6454 | return getFocusedWindowLocked(); |
| 6455 | } |
| 6456 | } |
| 6457 | |
| 6458 | private WindowState getFocusedWindowLocked() { |
| 6459 | return mCurrentFocus; |
| 6460 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6461 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6462 | public boolean detectSafeMode() { |
| Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 6463 | if (!mInputMonitor.waitForInputDevicesReady( |
| 6464 | INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) { |
| 6465 | Slog.w(TAG, "Devices still not ready after waiting " |
| 6466 | + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS |
| 6467 | + " milliseconds before attempting to detect safe mode."); |
| 6468 | } |
| 6469 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6470 | mSafeMode = mPolicy.detectSafeMode(); |
| 6471 | return mSafeMode; |
| 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 systemReady() { |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6475 | synchronized(mWindowMap) { |
| 6476 | if (mDisplay != null) { |
| 6477 | throw new IllegalStateException("Display already initialized"); |
| 6478 | } |
| 6479 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 6480 | mDisplay = wm.getDefaultDisplay(); |
| 6481 | mInitialDisplayWidth = mDisplay.getWidth(); |
| 6482 | mInitialDisplayHeight = mDisplay.getHeight(); |
| Dianne Hackborn | 4c7cc34 | 2010-12-16 16:37:39 -0800 | [diff] [blame] | 6483 | mInputManager.setDisplaySize(0, Display.unmapDisplaySize(mInitialDisplayWidth), |
| 6484 | Display.unmapDisplaySize(mInitialDisplayHeight)); |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6485 | } |
| 6486 | |
| 6487 | try { |
| 6488 | mActivityManager.updateConfiguration(null); |
| 6489 | } catch (RemoteException e) { |
| 6490 | } |
| Dianne Hackborn | 154db5f | 2010-07-29 19:15:19 -0700 | [diff] [blame] | 6491 | |
| 6492 | mPolicy.systemReady(); |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6493 | } |
| 6494 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6495 | // ------------------------------------------------------------- |
| 6496 | // Client Session State |
| 6497 | // ------------------------------------------------------------- |
| 6498 | |
| 6499 | private final class Session extends IWindowSession.Stub |
| 6500 | implements IBinder.DeathRecipient { |
| 6501 | final IInputMethodClient mClient; |
| 6502 | final IInputContext mInputContext; |
| 6503 | final int mUid; |
| 6504 | final int mPid; |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6505 | final String mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6506 | SurfaceSession mSurfaceSession; |
| 6507 | int mNumWindow = 0; |
| 6508 | boolean mClientDead = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6509 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6510 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 6511 | mClient = client; |
| 6512 | mInputContext = inputContext; |
| 6513 | mUid = Binder.getCallingUid(); |
| 6514 | mPid = Binder.getCallingPid(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6515 | StringBuilder sb = new StringBuilder(); |
| 6516 | sb.append("Session{"); |
| 6517 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 6518 | sb.append(" uid "); |
| 6519 | sb.append(mUid); |
| 6520 | sb.append("}"); |
| 6521 | mStringName = sb.toString(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6522 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6523 | synchronized (mWindowMap) { |
| 6524 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 6525 | IBinder b = ServiceManager.getService( |
| 6526 | Context.INPUT_METHOD_SERVICE); |
| 6527 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 6528 | } |
| 6529 | } |
| 6530 | long ident = Binder.clearCallingIdentity(); |
| 6531 | try { |
| 6532 | // Note: it is safe to call in to the input method manager |
| 6533 | // here because we are not holding our lock. |
| 6534 | if (mInputMethodManager != null) { |
| 6535 | mInputMethodManager.addClient(client, inputContext, |
| 6536 | mUid, mPid); |
| 6537 | } else { |
| 6538 | client.setUsingInputMethod(false); |
| 6539 | } |
| 6540 | client.asBinder().linkToDeath(this, 0); |
| 6541 | } catch (RemoteException e) { |
| 6542 | // The caller has died, so we can just forget about this. |
| 6543 | try { |
| 6544 | if (mInputMethodManager != null) { |
| 6545 | mInputMethodManager.removeClient(client); |
| 6546 | } |
| 6547 | } catch (RemoteException ee) { |
| 6548 | } |
| 6549 | } finally { |
| 6550 | Binder.restoreCallingIdentity(ident); |
| 6551 | } |
| 6552 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6553 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6554 | @Override |
| 6555 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 6556 | throws RemoteException { |
| 6557 | try { |
| 6558 | return super.onTransact(code, data, reply, flags); |
| 6559 | } catch (RuntimeException e) { |
| 6560 | // Log all 'real' exceptions thrown to the caller |
| 6561 | if (!(e instanceof SecurityException)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6562 | Slog.e(TAG, "Window Session Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6563 | } |
| 6564 | throw e; |
| 6565 | } |
| 6566 | } |
| 6567 | |
| 6568 | public void binderDied() { |
| 6569 | // Note: it is safe to call in to the input method manager |
| 6570 | // here because we are not holding our lock. |
| 6571 | try { |
| 6572 | if (mInputMethodManager != null) { |
| 6573 | mInputMethodManager.removeClient(mClient); |
| 6574 | } |
| 6575 | } catch (RemoteException e) { |
| 6576 | } |
| 6577 | synchronized(mWindowMap) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 6578 | mClient.asBinder().unlinkToDeath(this, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6579 | mClientDead = true; |
| 6580 | killSessionLocked(); |
| 6581 | } |
| 6582 | } |
| 6583 | |
| 6584 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6585 | int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) { |
| 6586 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, |
| 6587 | outInputChannel); |
| 6588 | } |
| 6589 | |
| 6590 | public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6591 | int viewVisibility, Rect outContentInsets) { |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6592 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6593 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6594 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6595 | public void remove(IWindow window) { |
| 6596 | removeWindow(this, window); |
| 6597 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6598 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6599 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 6600 | int requestedWidth, int requestedHeight, int viewFlags, |
| 6601 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6602 | Rect outVisibleInsets, Configuration outConfig, Surface outSurface) { |
| Dianne Hackborn | f123e49 | 2010-09-24 11:16:23 -0700 | [diff] [blame] | 6603 | //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid()); |
| 6604 | int res = relayoutWindow(this, window, attrs, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6605 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6606 | outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface); |
| Dianne Hackborn | f123e49 | 2010-09-24 11:16:23 -0700 | [diff] [blame] | 6607 | //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid()); |
| 6608 | return res; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6609 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6610 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6611 | public void setTransparentRegion(IWindow window, Region region) { |
| 6612 | setTransparentRegionWindow(this, window, region); |
| 6613 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6614 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6615 | public void setInsets(IWindow window, int touchableInsets, |
| Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 6616 | Rect contentInsets, Rect visibleInsets, Region touchableArea) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6617 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 6618 | visibleInsets, touchableArea); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6619 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6620 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6621 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 6622 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 6623 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6624 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6625 | public void finishDrawing(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6626 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6627 | TAG, "IWindow finishDrawing called for " + window); |
| 6628 | finishDrawingWindow(this, window); |
| 6629 | } |
| 6630 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6631 | public void setInTouchMode(boolean mode) { |
| 6632 | synchronized(mWindowMap) { |
| 6633 | mInTouchMode = mode; |
| 6634 | } |
| 6635 | } |
| 6636 | |
| 6637 | public boolean getInTouchMode() { |
| 6638 | synchronized(mWindowMap) { |
| 6639 | return mInTouchMode; |
| 6640 | } |
| 6641 | } |
| 6642 | |
| 6643 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 6644 | boolean always) { |
| 6645 | synchronized(mWindowMap) { |
| 6646 | long ident = Binder.clearCallingIdentity(); |
| 6647 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6648 | return mPolicy.performHapticFeedbackLw( |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6649 | windowForClientLocked(this, window, true), |
| 6650 | effectId, always); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6651 | } finally { |
| 6652 | Binder.restoreCallingIdentity(ident); |
| 6653 | } |
| 6654 | } |
| 6655 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6656 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6657 | /* Drag/drop */ |
| Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 6658 | public IBinder prepareDrag(IWindow window, int flags, |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6659 | int width, int height, Surface outSurface) { |
| Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 6660 | return prepareDragSurface(window, mSurfaceSession, flags, |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6661 | width, height, outSurface); |
| 6662 | } |
| 6663 | |
| 6664 | public boolean performDrag(IWindow window, IBinder dragToken, |
| 6665 | float touchX, float touchY, float thumbCenterX, float thumbCenterY, |
| 6666 | ClipData data) { |
| 6667 | if (DEBUG_DRAG) { |
| 6668 | Slog.d(TAG, "perform drag: win=" + window + " data=" + data); |
| 6669 | } |
| 6670 | |
| 6671 | synchronized (mWindowMap) { |
| 6672 | if (mDragState == null) { |
| 6673 | Slog.w(TAG, "No drag prepared"); |
| 6674 | throw new IllegalStateException("performDrag() without prepareDrag()"); |
| 6675 | } |
| 6676 | |
| 6677 | if (dragToken != mDragState.mToken) { |
| 6678 | Slog.w(TAG, "Performing mismatched drag"); |
| 6679 | throw new IllegalStateException("performDrag() does not match prepareDrag()"); |
| 6680 | } |
| 6681 | |
| 6682 | WindowState callingWin = windowForClientLocked(null, window, false); |
| 6683 | if (callingWin == null) { |
| 6684 | Slog.w(TAG, "Bad requesting window " + window); |
| 6685 | return false; // !!! TODO: throw here? |
| 6686 | } |
| 6687 | |
| 6688 | // !!! TODO: if input is not still focused on the initiating window, fail |
| 6689 | // the drag initiation (e.g. an alarm window popped up just as the application |
| 6690 | // called performDrag() |
| 6691 | |
| 6692 | mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder()); |
| 6693 | |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 6694 | // !!! TODO: extract the current touch (x, y) in screen coordinates. That |
| 6695 | // will let us eliminate the (touchX,touchY) parameters from the API. |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6696 | |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6697 | // !!! FIXME: put all this heavy stuff onto the mH looper, as well as |
| 6698 | // the actual drag event dispatch stuff in the dragstate |
| 6699 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6700 | mDragState.register(); |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 6701 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
| Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 6702 | if (!mInputManager.transferTouchFocus(callingWin.mInputChannel, |
| 6703 | mDragState.mServerChannel)) { |
| 6704 | Slog.e(TAG, "Unable to transfer touch focus"); |
| 6705 | mDragState.unregister(); |
| 6706 | mDragState = null; |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 6707 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
| Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 6708 | return false; |
| 6709 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6710 | |
| 6711 | mDragState.mData = data; |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6712 | mDragState.mCurrentX = touchX; |
| 6713 | mDragState.mCurrentY = touchY; |
| Chris Tate | b8203e9 | 2010-10-12 14:23:21 -0700 | [diff] [blame] | 6714 | mDragState.broadcastDragStartedLw(touchX, touchY); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6715 | |
| 6716 | // remember the thumb offsets for later |
| 6717 | mDragState.mThumbOffsetX = thumbCenterX; |
| 6718 | mDragState.mThumbOffsetY = thumbCenterY; |
| 6719 | |
| 6720 | // Make the surface visible at the proper location |
| 6721 | final Surface surface = mDragState.mSurface; |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 6722 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performDrag"); |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6723 | Surface.openTransaction(); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6724 | try { |
| 6725 | surface.setPosition((int)(touchX - thumbCenterX), |
| 6726 | (int)(touchY - thumbCenterY)); |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6727 | surface.setAlpha(.7071f); |
| Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 6728 | surface.setLayer(mDragState.getDragLayerLw()); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6729 | surface.show(); |
| 6730 | } finally { |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6731 | Surface.closeTransaction(); |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 6732 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performDrag"); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6733 | } |
| 6734 | } |
| 6735 | |
| 6736 | return true; // success! |
| 6737 | } |
| 6738 | |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6739 | public void reportDropResult(IWindow window, boolean consumed) { |
| 6740 | IBinder token = window.asBinder(); |
| 6741 | if (DEBUG_DRAG) { |
| 6742 | Slog.d(TAG, "Drop result=" + consumed + " reported by " + token); |
| 6743 | } |
| 6744 | |
| 6745 | synchronized (mWindowMap) { |
| Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 6746 | long ident = Binder.clearCallingIdentity(); |
| 6747 | try { |
| Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 6748 | if (mDragState == null || mDragState.mToken != token) { |
| Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 6749 | Slog.w(TAG, "Invalid drop-result claim by " + window); |
| 6750 | throw new IllegalStateException("reportDropResult() by non-recipient"); |
| 6751 | } |
| 6752 | |
| 6753 | // The right window has responded, even if it's no longer around, |
| 6754 | // so be sure to halt the timeout even if the later WindowState |
| 6755 | // lookup fails. |
| 6756 | mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder()); |
| 6757 | WindowState callingWin = windowForClientLocked(null, window, false); |
| 6758 | if (callingWin == null) { |
| 6759 | Slog.w(TAG, "Bad result-reporting window " + window); |
| 6760 | return; // !!! TODO: throw here? |
| 6761 | } |
| 6762 | |
| 6763 | mDragState.mDragResult = consumed; |
| 6764 | mDragState.endDragLw(); |
| 6765 | } finally { |
| 6766 | Binder.restoreCallingIdentity(ident); |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6767 | } |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6768 | } |
| 6769 | } |
| 6770 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6771 | public void dragRecipientEntered(IWindow window) { |
| 6772 | if (DEBUG_DRAG) { |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6773 | Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder()); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6774 | } |
| 6775 | } |
| 6776 | |
| 6777 | public void dragRecipientExited(IWindow window) { |
| 6778 | if (DEBUG_DRAG) { |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6779 | Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder()); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6780 | } |
| 6781 | } |
| 6782 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6783 | 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] | 6784 | synchronized(mWindowMap) { |
| 6785 | long ident = Binder.clearCallingIdentity(); |
| 6786 | try { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6787 | setWindowWallpaperPositionLocked( |
| 6788 | windowForClientLocked(this, window, true), |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6789 | x, y, xStep, yStep); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6790 | } finally { |
| 6791 | Binder.restoreCallingIdentity(ident); |
| 6792 | } |
| 6793 | } |
| 6794 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6795 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6796 | public void wallpaperOffsetsComplete(IBinder window) { |
| 6797 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 6798 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6799 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6800 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 6801 | int z, Bundle extras, boolean sync) { |
| 6802 | synchronized(mWindowMap) { |
| 6803 | long ident = Binder.clearCallingIdentity(); |
| 6804 | try { |
| 6805 | return sendWindowWallpaperCommandLocked( |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6806 | windowForClientLocked(this, window, true), |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6807 | action, x, y, z, extras, sync); |
| 6808 | } finally { |
| 6809 | Binder.restoreCallingIdentity(ident); |
| 6810 | } |
| 6811 | } |
| 6812 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6813 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6814 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 6815 | WindowManagerService.this.wallpaperCommandComplete(window, result); |
| 6816 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6817 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6818 | void windowAddedLocked() { |
| 6819 | if (mSurfaceSession == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6820 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6821 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 6822 | mSurfaceSession = new SurfaceSession(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6823 | if (SHOW_TRANSACTIONS) Slog.i( |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6824 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6825 | mSessions.add(this); |
| 6826 | } |
| 6827 | mNumWindow++; |
| 6828 | } |
| 6829 | |
| 6830 | void windowRemovedLocked() { |
| 6831 | mNumWindow--; |
| 6832 | killSessionLocked(); |
| 6833 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6834 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6835 | void killSessionLocked() { |
| 6836 | if (mNumWindow <= 0 && mClientDead) { |
| 6837 | mSessions.remove(this); |
| 6838 | if (mSurfaceSession != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6839 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6840 | TAG, "Last window removed from " + this |
| 6841 | + ", destroying " + mSurfaceSession); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6842 | if (SHOW_TRANSACTIONS) Slog.i( |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6843 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6844 | try { |
| 6845 | mSurfaceSession.kill(); |
| 6846 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6847 | Slog.w(TAG, "Exception thrown when killing surface session " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6848 | + mSurfaceSession + " in session " + this |
| 6849 | + ": " + e.toString()); |
| 6850 | } |
| 6851 | mSurfaceSession = null; |
| 6852 | } |
| 6853 | } |
| 6854 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6855 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6856 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6857 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 6858 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 6859 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6860 | } |
| 6861 | |
| 6862 | @Override |
| 6863 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6864 | return mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6865 | } |
| 6866 | } |
| 6867 | |
| 6868 | // ------------------------------------------------------------- |
| 6869 | // Client Window State |
| 6870 | // ------------------------------------------------------------- |
| 6871 | |
| 6872 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 6873 | final Session mSession; |
| 6874 | final IWindow mClient; |
| 6875 | WindowToken mToken; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6876 | WindowToken mRootToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6877 | AppWindowToken mAppToken; |
| 6878 | AppWindowToken mTargetAppToken; |
| 6879 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 6880 | final DeathRecipient mDeathRecipient; |
| 6881 | final WindowState mAttachedWindow; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6882 | final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6883 | final int mBaseLayer; |
| 6884 | final int mSubLayer; |
| 6885 | final boolean mLayoutAttached; |
| 6886 | final boolean mIsImWindow; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6887 | final boolean mIsWallpaper; |
| 6888 | final boolean mIsFloatingLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6889 | int mViewVisibility; |
| 6890 | boolean mPolicyVisibility = true; |
| 6891 | boolean mPolicyVisibilityAfterAnim = true; |
| 6892 | boolean mAppFreezing; |
| 6893 | Surface mSurface; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6894 | boolean mReportDestroySurface; |
| 6895 | boolean mSurfacePendingDestroy; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6896 | boolean mAttachedHidden; // is our parent window hidden? |
| 6897 | boolean mLastHidden; // was this window last hidden? |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6898 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6899 | int mRequestedWidth; |
| 6900 | int mRequestedHeight; |
| 6901 | int mLastRequestedWidth; |
| 6902 | int mLastRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6903 | int mLayer; |
| 6904 | int mAnimLayer; |
| 6905 | int mLastLayer; |
| 6906 | boolean mHaveFrame; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6907 | boolean mObscured; |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 6908 | boolean mTurnOnScreen; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6909 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6910 | int mLayoutSeq = -1; |
| 6911 | |
| 6912 | Configuration mConfiguration = null; |
| 6913 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6914 | // Actual frame shown on-screen (may be modified by animation) |
| 6915 | final Rect mShownFrame = new Rect(); |
| 6916 | final Rect mLastShownFrame = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6917 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6918 | /** |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 6919 | * Set when we have changed the size of the surface, to know that |
| 6920 | * we must tell them application to resize (and thus redraw itself). |
| 6921 | */ |
| 6922 | boolean mSurfaceResized; |
| 6923 | |
| 6924 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6925 | * Insets that determine the actually visible area |
| 6926 | */ |
| 6927 | final Rect mVisibleInsets = new Rect(); |
| 6928 | final Rect mLastVisibleInsets = new Rect(); |
| 6929 | boolean mVisibleInsetsChanged; |
| 6930 | |
| 6931 | /** |
| 6932 | * Insets that are covered by system windows |
| 6933 | */ |
| 6934 | final Rect mContentInsets = new Rect(); |
| 6935 | final Rect mLastContentInsets = new Rect(); |
| 6936 | boolean mContentInsetsChanged; |
| 6937 | |
| 6938 | /** |
| 6939 | * Set to true if we are waiting for this window to receive its |
| 6940 | * given internal insets before laying out other windows based on it. |
| 6941 | */ |
| 6942 | boolean mGivenInsetsPending; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6943 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6944 | /** |
| 6945 | * These are the content insets that were given during layout for |
| 6946 | * this window, to be applied to windows behind it. |
| 6947 | */ |
| 6948 | final Rect mGivenContentInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6949 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6950 | /** |
| 6951 | * These are the visible insets that were given during layout for |
| 6952 | * this window, to be applied to windows behind it. |
| 6953 | */ |
| 6954 | final Rect mGivenVisibleInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6955 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6956 | /** |
| Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 6957 | * This is the given touchable area relative to the window frame, or null if none. |
| 6958 | */ |
| 6959 | final Region mGivenTouchableRegion = new Region(); |
| 6960 | |
| 6961 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6962 | * Flag indicating whether the touchable region should be adjusted by |
| 6963 | * the visible insets; if false the area outside the visible insets is |
| 6964 | * NOT touchable, so we must use those to adjust the frame during hit |
| 6965 | * tests. |
| 6966 | */ |
| 6967 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6968 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6969 | // Current transformation being applied. |
| Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 6970 | boolean mHaveMatrix; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6971 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 6972 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 6973 | float mHScale=1, mVScale=1; |
| 6974 | float mLastHScale=1, mLastVScale=1; |
| 6975 | final Matrix mTmpMatrix = new Matrix(); |
| 6976 | |
| 6977 | // "Real" frame that the application sees. |
| 6978 | final Rect mFrame = new Rect(); |
| 6979 | final Rect mLastFrame = new Rect(); |
| 6980 | |
| 6981 | final Rect mContainingFrame = new Rect(); |
| 6982 | final Rect mDisplayFrame = new Rect(); |
| 6983 | final Rect mContentFrame = new Rect(); |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 6984 | final Rect mParentFrame = new Rect(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6985 | final Rect mVisibleFrame = new Rect(); |
| 6986 | |
| Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6987 | boolean mContentChanged; |
| 6988 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6989 | float mShownAlpha = 1; |
| 6990 | float mAlpha = 1; |
| 6991 | float mLastAlpha = 1; |
| 6992 | |
| 6993 | // Set to true if, when the window gets displayed, it should perform |
| 6994 | // an enter animation. |
| 6995 | boolean mEnterAnimationPending; |
| 6996 | |
| 6997 | // Currently running animation. |
| 6998 | boolean mAnimating; |
| 6999 | boolean mLocalAnimating; |
| 7000 | Animation mAnimation; |
| 7001 | boolean mAnimationIsEntrance; |
| 7002 | boolean mHasTransformation; |
| 7003 | boolean mHasLocalTransformation; |
| 7004 | final Transformation mTransformation = new Transformation(); |
| 7005 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7006 | // If a window showing a wallpaper: the requested offset for the |
| 7007 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 7008 | float mWallpaperX = -1; |
| 7009 | float mWallpaperY = -1; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 7010 | |
| 7011 | // If a window showing a wallpaper: what fraction of the offset |
| 7012 | // range corresponds to a full virtual screen. |
| 7013 | float mWallpaperXStep = -1; |
| 7014 | float mWallpaperYStep = -1; |
| 7015 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7016 | // Wallpaper windows: pixels offset based on above variables. |
| 7017 | int mXOffset; |
| 7018 | int mYOffset; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7019 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7020 | // This is set after IWindowSession.relayout() has been called at |
| 7021 | // least once for the window. It allows us to detect the situation |
| 7022 | // where we don't yet have a surface, but should have one soon, so |
| 7023 | // we can give the window focus before waiting for the relayout. |
| 7024 | boolean mRelayoutCalled; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7025 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7026 | // This is set after the Surface has been created but before the |
| 7027 | // window has been drawn. During this time the surface is hidden. |
| 7028 | boolean mDrawPending; |
| 7029 | |
| 7030 | // This is set after the window has finished drawing for the first |
| 7031 | // time but before its surface is shown. The surface will be |
| 7032 | // displayed when the next layout is run. |
| 7033 | boolean mCommitDrawPending; |
| 7034 | |
| 7035 | // This is set during the time after the window's drawing has been |
| 7036 | // committed, and before its surface is actually shown. It is used |
| 7037 | // to delay showing the surface until all windows in a token are ready |
| 7038 | // to be shown. |
| 7039 | boolean mReadyToShow; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7040 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7041 | // Set when the window has been shown in the screen the first time. |
| 7042 | boolean mHasDrawn; |
| 7043 | |
| 7044 | // Currently running an exit animation? |
| 7045 | boolean mExiting; |
| 7046 | |
| 7047 | // Currently on the mDestroySurface list? |
| 7048 | boolean mDestroying; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7049 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7050 | // Completely remove from window manager after exit animation? |
| 7051 | boolean mRemoveOnExit; |
| 7052 | |
| 7053 | // Set when the orientation is changing and this window has not yet |
| 7054 | // been updated for the new orientation. |
| 7055 | boolean mOrientationChanging; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7056 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7057 | // Is this window now (or just being) removed? |
| 7058 | boolean mRemoved; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7059 | |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7060 | // Temp for keeping track of windows that have been removed when |
| 7061 | // rebuilding window list. |
| 7062 | boolean mRebuilding; |
| 7063 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7064 | // For debugging, this is the last information given to the surface flinger. |
| 7065 | boolean mSurfaceShown; |
| 7066 | int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH; |
| 7067 | int mSurfaceLayer; |
| 7068 | float mSurfaceAlpha; |
| 7069 | |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 7070 | // Input channel and input window handle used by the input dispatcher. |
| 7071 | InputWindowHandle mInputWindowHandle; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7072 | InputChannel mInputChannel; |
| 7073 | |
| Mattias Petersson | 1622eee | 2010-12-21 10:15:11 +0100 | [diff] [blame] | 7074 | // Used to improve performance of toString() |
| 7075 | String mStringNameCache; |
| 7076 | CharSequence mLastTitle; |
| 7077 | boolean mWasPaused; |
| 7078 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7079 | WindowState(Session s, IWindow c, WindowToken token, |
| 7080 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 7081 | int viewVisibility) { |
| 7082 | mSession = s; |
| 7083 | mClient = c; |
| 7084 | mToken = token; |
| 7085 | mAttrs.copyFrom(a); |
| 7086 | mViewVisibility = viewVisibility; |
| 7087 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 7088 | mAlpha = a.alpha; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7089 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7090 | TAG, "Window " + this + " client=" + c.asBinder() |
| 7091 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 7092 | try { |
| 7093 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 7094 | } catch (RemoteException e) { |
| 7095 | mDeathRecipient = null; |
| 7096 | mAttachedWindow = null; |
| 7097 | mLayoutAttached = false; |
| 7098 | mIsImWindow = false; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7099 | mIsWallpaper = false; |
| 7100 | mIsFloatingLayer = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7101 | mBaseLayer = 0; |
| 7102 | mSubLayer = 0; |
| 7103 | return; |
| 7104 | } |
| 7105 | mDeathRecipient = deathRecipient; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7106 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7107 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 7108 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 7109 | // The multiplier here is to reserve space for multiple |
| 7110 | // windows in the same type layer. |
| 7111 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 7112 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 7113 | + TYPE_LAYER_OFFSET; |
| 7114 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 7115 | mAttachedWindow = attachedWindow; |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7116 | 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] | 7117 | mAttachedWindow.mChildWindows.add(this); |
| 7118 | mLayoutAttached = mAttrs.type != |
| 7119 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 7120 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 7121 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7122 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 7123 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7124 | } else { |
| 7125 | // The multiplier here is to reserve space for multiple |
| 7126 | // windows in the same type layer. |
| 7127 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 7128 | * TYPE_LAYER_MULTIPLIER |
| 7129 | + TYPE_LAYER_OFFSET; |
| 7130 | mSubLayer = 0; |
| 7131 | mAttachedWindow = null; |
| 7132 | mLayoutAttached = false; |
| 7133 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 7134 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7135 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 7136 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7137 | } |
| 7138 | |
| 7139 | WindowState appWin = this; |
| 7140 | while (appWin.mAttachedWindow != null) { |
| 7141 | appWin = mAttachedWindow; |
| 7142 | } |
| 7143 | WindowToken appToken = appWin.mToken; |
| 7144 | while (appToken.appWindowToken == null) { |
| 7145 | WindowToken parent = mTokenMap.get(appToken.token); |
| 7146 | if (parent == null || appToken == parent) { |
| 7147 | break; |
| 7148 | } |
| 7149 | appToken = parent; |
| 7150 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7151 | mRootToken = appToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7152 | mAppToken = appToken.appWindowToken; |
| 7153 | |
| 7154 | mSurface = null; |
| 7155 | mRequestedWidth = 0; |
| 7156 | mRequestedHeight = 0; |
| 7157 | mLastRequestedWidth = 0; |
| 7158 | mLastRequestedHeight = 0; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7159 | mXOffset = 0; |
| 7160 | mYOffset = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7161 | mLayer = 0; |
| 7162 | mAnimLayer = 0; |
| 7163 | mLastLayer = 0; |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 7164 | mInputWindowHandle = new InputWindowHandle( |
| 7165 | mAppToken != null ? mAppToken.mInputApplicationHandle : null, this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7166 | } |
| 7167 | |
| 7168 | void attach() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7169 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7170 | TAG, "Attaching " + this + " token=" + mToken |
| 7171 | + ", list=" + mToken.windows); |
| 7172 | mSession.windowAddedLocked(); |
| 7173 | } |
| 7174 | |
| 7175 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 7176 | mHaveFrame = true; |
| 7177 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7178 | final Rect container = mContainingFrame; |
| 7179 | container.set(pf); |
| 7180 | |
| 7181 | final Rect display = mDisplayFrame; |
| 7182 | display.set(df); |
| 7183 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7184 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7185 | container.intersect(mCompatibleScreenFrame); |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7186 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 7187 | display.intersect(mCompatibleScreenFrame); |
| 7188 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7189 | } |
| 7190 | |
| 7191 | final int pw = container.right - container.left; |
| 7192 | final int ph = container.bottom - container.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7193 | |
| 7194 | int w,h; |
| 7195 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 7196 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 7197 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 7198 | } else { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 7199 | w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth; |
| 7200 | h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7201 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7202 | |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 7203 | if (!mParentFrame.equals(pf)) { |
| Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 7204 | //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame |
| 7205 | // + " to " + pf); |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 7206 | mParentFrame.set(pf); |
| 7207 | mContentChanged = true; |
| 7208 | } |
| 7209 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7210 | final Rect content = mContentFrame; |
| 7211 | content.set(cf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7212 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7213 | final Rect visible = mVisibleFrame; |
| 7214 | visible.set(vf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7215 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7216 | final Rect frame = mFrame; |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7217 | final int fw = frame.width(); |
| 7218 | final int fh = frame.height(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7219 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7220 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 7221 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 7222 | |
| 7223 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 7224 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 7225 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 7226 | |
| 7227 | //System.out.println("Out: " + mFrame); |
| 7228 | |
| 7229 | // Now make sure the window fits in the overall display. |
| 7230 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7231 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7232 | // Make sure the content and visible frames are inside of the |
| 7233 | // final window frame. |
| 7234 | if (content.left < frame.left) content.left = frame.left; |
| 7235 | if (content.top < frame.top) content.top = frame.top; |
| 7236 | if (content.right > frame.right) content.right = frame.right; |
| 7237 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 7238 | if (visible.left < frame.left) visible.left = frame.left; |
| 7239 | if (visible.top < frame.top) visible.top = frame.top; |
| 7240 | if (visible.right > frame.right) visible.right = frame.right; |
| 7241 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7242 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7243 | final Rect contentInsets = mContentInsets; |
| 7244 | contentInsets.left = content.left-frame.left; |
| 7245 | contentInsets.top = content.top-frame.top; |
| 7246 | contentInsets.right = frame.right-content.right; |
| 7247 | contentInsets.bottom = frame.bottom-content.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7248 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7249 | final Rect visibleInsets = mVisibleInsets; |
| 7250 | visibleInsets.left = visible.left-frame.left; |
| 7251 | visibleInsets.top = visible.top-frame.top; |
| 7252 | visibleInsets.right = frame.right-visible.right; |
| 7253 | visibleInsets.bottom = frame.bottom-visible.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7254 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 7255 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 7256 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 7257 | mDisplay.getHeight(), false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7258 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7259 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7260 | if (localLOGV) { |
| 7261 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 7262 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7263 | Slog.v(TAG, "Resolving (mRequestedWidth=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7264 | + mRequestedWidth + ", mRequestedheight=" |
| 7265 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 7266 | + "): frame=" + mFrame.toShortString() |
| 7267 | + " ci=" + contentInsets.toShortString() |
| 7268 | + " vi=" + visibleInsets.toShortString()); |
| 7269 | //} |
| 7270 | } |
| 7271 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7272 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7273 | public Rect getFrameLw() { |
| 7274 | return mFrame; |
| 7275 | } |
| 7276 | |
| 7277 | public Rect getShownFrameLw() { |
| 7278 | return mShownFrame; |
| 7279 | } |
| 7280 | |
| 7281 | public Rect getDisplayFrameLw() { |
| 7282 | return mDisplayFrame; |
| 7283 | } |
| 7284 | |
| 7285 | public Rect getContentFrameLw() { |
| 7286 | return mContentFrame; |
| 7287 | } |
| 7288 | |
| 7289 | public Rect getVisibleFrameLw() { |
| 7290 | return mVisibleFrame; |
| 7291 | } |
| 7292 | |
| 7293 | public boolean getGivenInsetsPendingLw() { |
| 7294 | return mGivenInsetsPending; |
| 7295 | } |
| 7296 | |
| 7297 | public Rect getGivenContentInsetsLw() { |
| 7298 | return mGivenContentInsets; |
| 7299 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7300 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7301 | public Rect getGivenVisibleInsetsLw() { |
| 7302 | return mGivenVisibleInsets; |
| 7303 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7304 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7305 | public WindowManager.LayoutParams getAttrs() { |
| 7306 | return mAttrs; |
| 7307 | } |
| 7308 | |
| 7309 | public int getSurfaceLayer() { |
| 7310 | return mLayer; |
| 7311 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7312 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7313 | public IApplicationToken getAppToken() { |
| 7314 | return mAppToken != null ? mAppToken.appToken : null; |
| 7315 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 7316 | |
| 7317 | public long getInputDispatchingTimeoutNanos() { |
| 7318 | return mAppToken != null |
| 7319 | ? mAppToken.inputDispatchingTimeoutNanos |
| 7320 | : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 7321 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7322 | |
| 7323 | public boolean hasAppShownWindows() { |
| 7324 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 7325 | } |
| 7326 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7327 | public void setAnimation(Animation anim) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7328 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7329 | TAG, "Setting animation in " + this + ": " + anim); |
| 7330 | mAnimating = false; |
| 7331 | mLocalAnimating = false; |
| 7332 | mAnimation = anim; |
| 7333 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 7334 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 7335 | } |
| 7336 | |
| 7337 | public void clearAnimation() { |
| 7338 | if (mAnimation != null) { |
| 7339 | mAnimating = true; |
| 7340 | mLocalAnimating = false; |
| Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7341 | mAnimation.cancel(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7342 | mAnimation = null; |
| 7343 | } |
| 7344 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7345 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7346 | Surface createSurfaceLocked() { |
| 7347 | if (mSurface == null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7348 | mReportDestroySurface = false; |
| 7349 | mSurfacePendingDestroy = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7350 | mDrawPending = true; |
| 7351 | mCommitDrawPending = false; |
| 7352 | mReadyToShow = false; |
| 7353 | if (mAppToken != null) { |
| 7354 | mAppToken.allDrawn = false; |
| 7355 | } |
| 7356 | |
| 7357 | int flags = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7358 | |
| 7359 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 7360 | flags |= Surface.SECURE; |
| 7361 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7362 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7363 | TAG, "Creating surface in session " |
| 7364 | + mSession.mSurfaceSession + " window " + this |
| 7365 | + " w=" + mFrame.width() |
| 7366 | + " h=" + mFrame.height() + " format=" |
| 7367 | + mAttrs.format + " flags=" + flags); |
| 7368 | |
| 7369 | int w = mFrame.width(); |
| 7370 | int h = mFrame.height(); |
| 7371 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 7372 | // for a scaled surface, we always want the requested |
| 7373 | // size. |
| 7374 | w = mRequestedWidth; |
| 7375 | h = mRequestedHeight; |
| 7376 | } |
| 7377 | |
| Romain Guy | 9825ec6 | 2009-10-01 00:58:09 -0700 | [diff] [blame] | 7378 | // Something is wrong and SurfaceFlinger will not like this, |
| 7379 | // try to revert to sane values |
| 7380 | if (w <= 0) w = 1; |
| 7381 | if (h <= 0) h = 1; |
| 7382 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7383 | mSurfaceShown = false; |
| 7384 | mSurfaceLayer = 0; |
| 7385 | mSurfaceAlpha = 1; |
| 7386 | mSurfaceX = 0; |
| 7387 | mSurfaceY = 0; |
| 7388 | mSurfaceW = w; |
| 7389 | mSurfaceH = h; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7390 | try { |
| Romain Guy | d10cd57 | 2010-10-10 13:33:22 -0700 | [diff] [blame] | 7391 | final boolean isHwAccelerated = (mAttrs.flags & |
| 7392 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0; |
| 7393 | final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format; |
| 7394 | if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) { |
| 7395 | flags |= Surface.OPAQUE; |
| 7396 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7397 | mSurface = new Surface( |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7398 | mSession.mSurfaceSession, mSession.mPid, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 7399 | mAttrs.getTitle().toString(), |
| Romain Guy | d10cd57 | 2010-10-10 13:33:22 -0700 | [diff] [blame] | 7400 | 0, w, h, format, flags); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7401 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE " |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7402 | + mSurface + " IN SESSION " |
| 7403 | + mSession.mSurfaceSession |
| 7404 | + ": pid=" + mSession.mPid + " format=" |
| 7405 | + mAttrs.format + " flags=0x" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7406 | + Integer.toHexString(flags) |
| 7407 | + " / " + this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7408 | } catch (Surface.OutOfResourcesException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7409 | Slog.w(TAG, "OutOfResourcesException creating surface"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7410 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 7411 | return null; |
| 7412 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7413 | Slog.e(TAG, "Exception creating surface", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7414 | return null; |
| 7415 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7416 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7417 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7418 | TAG, "Got surface: " + mSurface |
| 7419 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 7420 | + ", animLayer=" + mAnimLayer); |
| 7421 | if (SHOW_TRANSACTIONS) { |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 7422 | Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked"); |
| 7423 | logSurface(this, "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" + |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7424 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 7425 | mAnimLayer + " HIDE", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7426 | } |
| 7427 | Surface.openTransaction(); |
| 7428 | try { |
| 7429 | try { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7430 | mSurfaceX = mFrame.left + mXOffset; |
| Dianne Hackborn | 529bef6 | 2010-03-25 11:48:43 -0700 | [diff] [blame] | 7431 | mSurfaceY = mFrame.top + mYOffset; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7432 | mSurface.setPosition(mSurfaceX, mSurfaceY); |
| 7433 | mSurfaceLayer = mAnimLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7434 | mSurface.setLayer(mAnimLayer); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7435 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7436 | mSurface.hide(); |
| 7437 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7438 | if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7439 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 7440 | Surface.SURFACE_DITHER); |
| 7441 | } |
| 7442 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7443 | Slog.w(TAG, "Error creating surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7444 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 7445 | } |
| 7446 | mLastHidden = true; |
| 7447 | } finally { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7448 | Surface.closeTransaction(); |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 7449 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION createSurfaceLocked"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7450 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7451 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7452 | TAG, "Created surface " + this); |
| 7453 | } |
| 7454 | return mSurface; |
| 7455 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7456 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7457 | void destroySurfaceLocked() { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7458 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 7459 | mAppToken.startingDisplayed = false; |
| 7460 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7461 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7462 | if (mSurface != null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7463 | mDrawPending = false; |
| 7464 | mCommitDrawPending = false; |
| 7465 | mReadyToShow = false; |
| 7466 | |
| 7467 | int i = mChildWindows.size(); |
| 7468 | while (i > 0) { |
| 7469 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7470 | WindowState c = mChildWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7471 | c.mAttachedHidden = true; |
| 7472 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7473 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7474 | if (mReportDestroySurface) { |
| 7475 | mReportDestroySurface = false; |
| 7476 | mSurfacePendingDestroy = true; |
| 7477 | try { |
| 7478 | mClient.dispatchGetNewSurface(); |
| 7479 | // We'll really destroy on the next time around. |
| 7480 | return; |
| 7481 | } catch (RemoteException e) { |
| 7482 | } |
| 7483 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7484 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7485 | try { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7486 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7487 | RuntimeException e = null; |
| 7488 | if (!HIDE_STACK_CRAWLS) { |
| 7489 | e = new RuntimeException(); |
| 7490 | e.fillInStackTrace(); |
| 7491 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7492 | Slog.w(TAG, "Window " + this + " destroying surface " |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7493 | + mSurface + ", session " + mSession, e); |
| 7494 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7495 | if (SHOW_TRANSACTIONS) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7496 | RuntimeException e = null; |
| 7497 | if (!HIDE_STACK_CRAWLS) { |
| 7498 | e = new RuntimeException(); |
| 7499 | e.fillInStackTrace(); |
| 7500 | } |
| 7501 | if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7502 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7503 | mSurface.destroy(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7504 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7505 | Slog.w(TAG, "Exception thrown when destroying Window " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7506 | + " surface " + mSurface + " session " + mSession |
| 7507 | + ": " + e.toString()); |
| 7508 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7509 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7510 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7511 | mSurface = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7512 | } |
| 7513 | } |
| 7514 | |
| 7515 | boolean finishDrawingLocked() { |
| 7516 | if (mDrawPending) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7517 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7518 | TAG, "finishDrawingLocked: " + mSurface); |
| 7519 | mCommitDrawPending = true; |
| 7520 | mDrawPending = false; |
| 7521 | return true; |
| 7522 | } |
| 7523 | return false; |
| 7524 | } |
| 7525 | |
| 7526 | // This must be called while inside a transaction. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7527 | boolean commitFinishDrawingLocked(long currentTime) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7528 | //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7529 | if (!mCommitDrawPending) { |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7530 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7531 | } |
| 7532 | mCommitDrawPending = false; |
| 7533 | mReadyToShow = true; |
| 7534 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 7535 | final AppWindowToken atoken = mAppToken; |
| 7536 | if (atoken == null || atoken.allDrawn || starting) { |
| 7537 | performShowLocked(); |
| 7538 | } |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7539 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7540 | } |
| 7541 | |
| 7542 | // This must be called while inside a transaction. |
| 7543 | boolean performShowLocked() { |
| 7544 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7545 | RuntimeException e = null; |
| 7546 | if (!HIDE_STACK_CRAWLS) { |
| 7547 | e = new RuntimeException(); |
| 7548 | e.fillInStackTrace(); |
| 7549 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7550 | Slog.v(TAG, "performShow on " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7551 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 7552 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 7553 | } |
| 7554 | if (mReadyToShow && isReadyForDisplay()) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7555 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this, |
| 7556 | "SHOW (performShowLocked)", null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7557 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7558 | + " during animation: policyVis=" + mPolicyVisibility |
| 7559 | + " attHidden=" + mAttachedHidden |
| 7560 | + " tok.hiddenRequested=" |
| 7561 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7562 | + " tok.hidden=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7563 | + (mAppToken != null ? mAppToken.hidden : false) |
| 7564 | + " animating=" + mAnimating |
| 7565 | + " tok animating=" |
| 7566 | + (mAppToken != null ? mAppToken.animating : false)); |
| 7567 | if (!showSurfaceRobustlyLocked(this)) { |
| 7568 | return false; |
| 7569 | } |
| 7570 | mLastAlpha = -1; |
| 7571 | mHasDrawn = true; |
| 7572 | mLastHidden = false; |
| 7573 | mReadyToShow = false; |
| 7574 | enableScreenIfNeededLocked(); |
| 7575 | |
| 7576 | applyEnterAnimationLocked(this); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7577 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7578 | int i = mChildWindows.size(); |
| 7579 | while (i > 0) { |
| 7580 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7581 | WindowState c = mChildWindows.get(i); |
| Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7582 | if (c.mAttachedHidden) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7583 | c.mAttachedHidden = false; |
| Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7584 | if (c.mSurface != null) { |
| 7585 | c.performShowLocked(); |
| 7586 | // It hadn't been shown, which means layout not |
| 7587 | // performed on it, so now we want to make sure to |
| 7588 | // do a layout. If called from within the transaction |
| 7589 | // loop, this will cause it to restart with a new |
| 7590 | // layout. |
| 7591 | mLayoutNeeded = true; |
| 7592 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7593 | } |
| 7594 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7595 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7596 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 7597 | && mAppToken != null) { |
| 7598 | mAppToken.firstWindowDrawn = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7599 | |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7600 | if (mAppToken.startingData != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7601 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7602 | "Finish starting " + mToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7603 | + ": first real window is shown, no animation"); |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7604 | // If this initial window is animating, stop it -- we |
| 7605 | // will do an animation to reveal it from behind the |
| 7606 | // starting window, so there is no need for it to also |
| 7607 | // be doing its own stuff. |
| 7608 | if (mAnimation != null) { |
| Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7609 | mAnimation.cancel(); |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7610 | mAnimation = null; |
| 7611 | // Make sure we clean up the animation. |
| 7612 | mAnimating = true; |
| 7613 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7614 | mFinishedStarting.add(mAppToken); |
| 7615 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7616 | } |
| 7617 | mAppToken.updateReportedVisibilityLocked(); |
| 7618 | } |
| 7619 | } |
| 7620 | return true; |
| 7621 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7622 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7623 | // This must be called while inside a transaction. Returns true if |
| 7624 | // there is more animation to run. |
| 7625 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7626 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7627 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7628 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7629 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 7630 | mHasTransformation = true; |
| 7631 | mHasLocalTransformation = true; |
| 7632 | if (!mLocalAnimating) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7633 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7634 | TAG, "Starting animation in " + this + |
| 7635 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 7636 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 7637 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 7638 | mAnimation.setStartTime(currentTime); |
| 7639 | mLocalAnimating = true; |
| 7640 | mAnimating = true; |
| 7641 | } |
| 7642 | mTransformation.clear(); |
| 7643 | final boolean more = mAnimation.getTransformation( |
| 7644 | currentTime, mTransformation); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7645 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7646 | TAG, "Stepped animation in " + this + |
| 7647 | ": more=" + more + ", xform=" + mTransformation); |
| 7648 | if (more) { |
| 7649 | // we're not done! |
| 7650 | return true; |
| 7651 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7652 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7653 | TAG, "Finished animation in " + this + |
| 7654 | " @ " + currentTime); |
| Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7655 | |
| 7656 | if (mAnimation != null) { |
| 7657 | mAnimation.cancel(); |
| 7658 | mAnimation = null; |
| 7659 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7660 | //WindowManagerService.this.dump(); |
| 7661 | } |
| 7662 | mHasLocalTransformation = false; |
| 7663 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7664 | && mAppToken.animation != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7665 | // When our app token is animating, we kind-of pretend like |
| 7666 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 7667 | // part of this check means that we will only do this if |
| 7668 | // our window is not currently exiting, or it is not |
| 7669 | // locally animating itself. The idea being that one that |
| 7670 | // is exiting and doing a local animation should be removed |
| 7671 | // once that animation is done. |
| 7672 | mAnimating = true; |
| 7673 | mHasTransformation = true; |
| 7674 | mTransformation.clear(); |
| 7675 | return false; |
| 7676 | } else if (mHasTransformation) { |
| 7677 | // Little trick to get through the path below to act like |
| 7678 | // we have finished an animation. |
| 7679 | mAnimating = true; |
| 7680 | } else if (isAnimating()) { |
| 7681 | mAnimating = true; |
| 7682 | } |
| 7683 | } else if (mAnimation != null) { |
| 7684 | // If the display is frozen, and there is a pending animation, |
| 7685 | // clear it and make sure we run the cleanup code. |
| 7686 | mAnimating = true; |
| 7687 | mLocalAnimating = true; |
| Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7688 | mAnimation.cancel(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7689 | mAnimation = null; |
| 7690 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7691 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7692 | if (!mAnimating && !mLocalAnimating) { |
| 7693 | return false; |
| 7694 | } |
| 7695 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7696 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7697 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 7698 | + ", reportedVisible=" |
| 7699 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7700 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7701 | mAnimating = false; |
| 7702 | mLocalAnimating = false; |
| Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7703 | if (mAnimation != null) { |
| 7704 | mAnimation.cancel(); |
| 7705 | mAnimation = null; |
| 7706 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7707 | mAnimLayer = mLayer; |
| 7708 | if (mIsImWindow) { |
| 7709 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7710 | } else if (mIsWallpaper) { |
| 7711 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7712 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7713 | if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7714 | + " anim layer: " + mAnimLayer); |
| 7715 | mHasTransformation = false; |
| 7716 | mHasLocalTransformation = false; |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7717 | if (mPolicyVisibility != mPolicyVisibilityAfterAnim) { |
| 7718 | if (DEBUG_VISIBILITY) { |
| 7719 | Slog.v(TAG, "Policy visibility changing after anim in " + this + ": " |
| 7720 | + mPolicyVisibilityAfterAnim); |
| 7721 | } |
| 7722 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 7723 | if (!mPolicyVisibility) { |
| 7724 | if (mCurrentFocus == this) { |
| 7725 | mFocusMayChange = true; |
| 7726 | } |
| 7727 | // Window is no longer visible -- make sure if we were waiting |
| 7728 | // for it to be displayed before enabling the display, that |
| 7729 | // we allow the display to be enabled now. |
| 7730 | enableScreenIfNeededLocked(); |
| 7731 | } |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7732 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7733 | mTransformation.clear(); |
| 7734 | if (mHasDrawn |
| 7735 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 7736 | && mAppToken != null |
| 7737 | && mAppToken.firstWindowDrawn |
| 7738 | && mAppToken.startingData != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7739 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7740 | + mToken + ": first real window done animating"); |
| 7741 | mFinishedStarting.add(mAppToken); |
| 7742 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7743 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7744 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7745 | finishExit(); |
| 7746 | |
| 7747 | if (mAppToken != null) { |
| 7748 | mAppToken.updateReportedVisibilityLocked(); |
| 7749 | } |
| 7750 | |
| 7751 | return false; |
| 7752 | } |
| 7753 | |
| 7754 | void finishExit() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7755 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7756 | TAG, "finishExit in " + this |
| 7757 | + ": exiting=" + mExiting |
| 7758 | + " remove=" + mRemoveOnExit |
| 7759 | + " windowAnimating=" + isWindowAnimating()); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7760 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7761 | final int N = mChildWindows.size(); |
| 7762 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7763 | mChildWindows.get(i).finishExit(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7764 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7765 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7766 | if (!mExiting) { |
| 7767 | return; |
| 7768 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7769 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7770 | if (isWindowAnimating()) { |
| 7771 | return; |
| 7772 | } |
| 7773 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7774 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7775 | TAG, "Exit animation finished in " + this |
| 7776 | + ": remove=" + mRemoveOnExit); |
| 7777 | if (mSurface != null) { |
| 7778 | mDestroySurface.add(this); |
| 7779 | mDestroying = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7780 | if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7781 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7782 | try { |
| 7783 | mSurface.hide(); |
| 7784 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7785 | Slog.w(TAG, "Error hiding surface in " + this, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7786 | } |
| 7787 | mLastHidden = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7788 | } |
| 7789 | mExiting = false; |
| 7790 | if (mRemoveOnExit) { |
| 7791 | mPendingRemove.add(this); |
| 7792 | mRemoveOnExit = false; |
| 7793 | } |
| 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 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 7797 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 7798 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 7799 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 7800 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 7801 | return true; |
| 7802 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7803 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7804 | void computeShownFrameLocked() { |
| 7805 | final boolean selfTransformation = mHasLocalTransformation; |
| 7806 | Transformation attachedTransformation = |
| 7807 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 7808 | ? mAttachedWindow.mTransformation : null; |
| 7809 | Transformation appTransformation = |
| 7810 | (mAppToken != null && mAppToken.hasTransformation) |
| 7811 | ? mAppToken.transformation : null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7812 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7813 | // Wallpapers are animated based on the "real" window they |
| 7814 | // are currently targeting. |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7815 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7816 | && mWallpaperTarget != null) { |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7817 | if (mWallpaperTarget.mHasLocalTransformation && |
| 7818 | mWallpaperTarget.mAnimation != null && |
| 7819 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7820 | attachedTransformation = mWallpaperTarget.mTransformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7821 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7822 | Slog.v(TAG, "WP target attached xform: " + attachedTransformation); |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7823 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7824 | } |
| 7825 | if (mWallpaperTarget.mAppToken != null && |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7826 | mWallpaperTarget.mAppToken.hasTransformation && |
| 7827 | mWallpaperTarget.mAppToken.animation != null && |
| 7828 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7829 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7830 | if (DEBUG_WALLPAPER && appTransformation != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7831 | Slog.v(TAG, "WP target app xform: " + appTransformation); |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7832 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7833 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7834 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7835 | |
| Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7836 | final boolean screenAnimation = mScreenRotationAnimation != null |
| 7837 | && mScreenRotationAnimation.isAnimating(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7838 | if (selfTransformation || attachedTransformation != null |
| Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7839 | || appTransformation != null || screenAnimation) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7840 | // cache often used attributes locally |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7841 | final Rect frame = mFrame; |
| 7842 | final float tmpFloats[] = mTmpFloats; |
| 7843 | final Matrix tmpMatrix = mTmpMatrix; |
| 7844 | |
| 7845 | // Compute the desired transformation. |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7846 | tmpMatrix.setTranslate(0, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7847 | if (selfTransformation) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7848 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7849 | } |
| Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 7850 | tmpMatrix.postTranslate(frame.left + mXOffset, frame.top + mYOffset); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7851 | if (attachedTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7852 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7853 | } |
| 7854 | if (appTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7855 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7856 | } |
| Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7857 | if (screenAnimation) { |
| 7858 | tmpMatrix.postConcat( |
| 7859 | mScreenRotationAnimation.getEnterTransformation().getMatrix()); |
| 7860 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7861 | |
| 7862 | // "convert" it into SurfaceFlinger's format |
| 7863 | // (a 2x2 matrix + an offset) |
| 7864 | // Here we must not transform the position of the surface |
| 7865 | // since it is already included in the transformation. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7866 | //Slog.i(TAG, "Transform: " + matrix); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7867 | |
| Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 7868 | mHaveMatrix = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7869 | tmpMatrix.getValues(tmpFloats); |
| 7870 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7871 | mDtDx = tmpFloats[Matrix.MSKEW_Y]; |
| 7872 | mDsDy = tmpFloats[Matrix.MSKEW_X]; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7873 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
| Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 7874 | int x = (int)tmpFloats[Matrix.MTRANS_X]; |
| 7875 | int y = (int)tmpFloats[Matrix.MTRANS_Y]; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7876 | int w = frame.width(); |
| 7877 | int h = frame.height(); |
| 7878 | mShownFrame.set(x, y, x+w, y+h); |
| 7879 | |
| 7880 | // Now set the alpha... but because our current hardware |
| 7881 | // can't do alpha transformation on a non-opaque surface, |
| 7882 | // turn it off if we are running an animation that is also |
| 7883 | // transforming since it is more important to have that |
| 7884 | // animation be smooth. |
| 7885 | mShownAlpha = mAlpha; |
| 7886 | if (!mLimitedAlphaCompositing |
| 7887 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 7888 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 7889 | && x == frame.left && y == frame.top))) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7890 | //Slog.i(TAG, "Applying alpha transform"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7891 | if (selfTransformation) { |
| 7892 | mShownAlpha *= mTransformation.getAlpha(); |
| 7893 | } |
| 7894 | if (attachedTransformation != null) { |
| 7895 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 7896 | } |
| 7897 | if (appTransformation != null) { |
| 7898 | mShownAlpha *= appTransformation.getAlpha(); |
| 7899 | } |
| Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7900 | if (screenAnimation) { |
| 7901 | mShownAlpha *= |
| 7902 | mScreenRotationAnimation.getEnterTransformation().getAlpha(); |
| 7903 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7904 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7905 | //Slog.i(TAG, "Not applying alpha transform"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7906 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7907 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7908 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7909 | TAG, "Continuing animation in " + this + |
| 7910 | ": " + mShownFrame + |
| 7911 | ", alpha=" + mTransformation.getAlpha()); |
| 7912 | return; |
| 7913 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7914 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7915 | mShownFrame.set(mFrame); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7916 | if (mXOffset != 0 || mYOffset != 0) { |
| 7917 | mShownFrame.offset(mXOffset, mYOffset); |
| 7918 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7919 | mShownAlpha = mAlpha; |
| Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 7920 | mHaveMatrix = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7921 | mDsDx = 1; |
| 7922 | mDtDx = 0; |
| 7923 | mDsDy = 0; |
| 7924 | mDtDy = 1; |
| 7925 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7926 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7927 | /** |
| 7928 | * Is this window visible? It is not visible if there is no |
| 7929 | * surface, or we are in the process of running an exit animation |
| 7930 | * that will remove the surface, or its app token has been hidden. |
| 7931 | */ |
| 7932 | public boolean isVisibleLw() { |
| 7933 | final AppWindowToken atoken = mAppToken; |
| 7934 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7935 | && (atoken == null || !atoken.hiddenRequested) |
| 7936 | && !mExiting && !mDestroying; |
| 7937 | } |
| 7938 | |
| 7939 | /** |
| Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7940 | * Like {@link #isVisibleLw}, but also counts a window that is currently |
| 7941 | * "hidden" behind the keyguard as visible. This allows us to apply |
| 7942 | * things like window flags that impact the keyguard. |
| 7943 | * XXX I am starting to think we need to have ANOTHER visibility flag |
| 7944 | * for this "hidden behind keyguard" state rather than overloading |
| 7945 | * mPolicyVisibility. Ungh. |
| 7946 | */ |
| 7947 | public boolean isVisibleOrBehindKeyguardLw() { |
| 7948 | final AppWindowToken atoken = mAppToken; |
| 7949 | return mSurface != null && !mAttachedHidden |
| 7950 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7951 | && !mDrawPending && !mCommitDrawPending |
| Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7952 | && !mExiting && !mDestroying; |
| 7953 | } |
| 7954 | |
| 7955 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7956 | * Is this window visible, ignoring its app token? It is not visible |
| 7957 | * if there is no surface, or we are in the process of running an exit animation |
| 7958 | * that will remove the surface. |
| 7959 | */ |
| 7960 | public boolean isWinVisibleLw() { |
| 7961 | final AppWindowToken atoken = mAppToken; |
| 7962 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7963 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 7964 | && !mExiting && !mDestroying; |
| 7965 | } |
| 7966 | |
| 7967 | /** |
| 7968 | * The same as isVisible(), but follows the current hidden state of |
| 7969 | * the associated app token, not the pending requested hidden state. |
| 7970 | */ |
| 7971 | boolean isVisibleNow() { |
| 7972 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7973 | && !mRootToken.hidden && !mExiting && !mDestroying; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7974 | } |
| 7975 | |
| 7976 | /** |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7977 | * Can this window possibly be a drag/drop target? The test here is |
| 7978 | * a combination of the above "visible now" with the check that the |
| 7979 | * Input Manager uses when discarding windows from input consideration. |
| 7980 | */ |
| 7981 | boolean isPotentialDragTarget() { |
| 7982 | return isVisibleNow() && (mInputChannel != null) && !mRemoved; |
| 7983 | } |
| 7984 | |
| 7985 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7986 | * Same as isVisible(), but we also count it as visible between the |
| 7987 | * call to IWindowSession.add() and the first relayout(). |
| 7988 | */ |
| 7989 | boolean isVisibleOrAdding() { |
| 7990 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7991 | return ((mSurface != null && !mReportDestroySurface) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7992 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 7993 | && mPolicyVisibility && !mAttachedHidden |
| 7994 | && (atoken == null || !atoken.hiddenRequested) |
| 7995 | && !mExiting && !mDestroying; |
| 7996 | } |
| 7997 | |
| 7998 | /** |
| 7999 | * Is this window currently on-screen? It is on-screen either if it |
| 8000 | * is visible or it is currently running an animation before no longer |
| 8001 | * being visible. |
| 8002 | */ |
| 8003 | boolean isOnScreen() { |
| 8004 | final AppWindowToken atoken = mAppToken; |
| 8005 | if (atoken != null) { |
| 8006 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 8007 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 8008 | || mAnimation != null || atoken.animation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8009 | } else { |
| 8010 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 8011 | && (!mAttachedHidden || mAnimation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8012 | } |
| 8013 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8014 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8015 | /** |
| 8016 | * Like isOnScreen(), but we don't return true if the window is part |
| 8017 | * of a transition that has not yet been started. |
| 8018 | */ |
| 8019 | boolean isReadyForDisplay() { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8020 | if (mRootToken.waitingToShow && |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8021 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8022 | return false; |
| 8023 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8024 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 8025 | final boolean animating = atoken != null |
| 8026 | ? (atoken.animation != null) : false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8027 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8028 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 8029 | && !mRootToken.hidden) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 8030 | || mAnimation != null || animating); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8031 | } |
| 8032 | |
| 8033 | /** Is the window or its container currently animating? */ |
| 8034 | boolean isAnimating() { |
| 8035 | final WindowState attached = mAttachedWindow; |
| 8036 | final AppWindowToken atoken = mAppToken; |
| 8037 | return mAnimation != null |
| 8038 | || (attached != null && attached.mAnimation != null) |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8039 | || (atoken != null && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8040 | (atoken.animation != null |
| 8041 | || atoken.inPendingTransaction)); |
| 8042 | } |
| 8043 | |
| 8044 | /** Is this window currently animating? */ |
| 8045 | boolean isWindowAnimating() { |
| 8046 | return mAnimation != null; |
| 8047 | } |
| 8048 | |
| 8049 | /** |
| 8050 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 8051 | * been drawn. |
| 8052 | */ |
| 8053 | public boolean isDisplayedLw() { |
| 8054 | final AppWindowToken atoken = mAppToken; |
| 8055 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 8056 | && !mDrawPending && !mCommitDrawPending |
| 8057 | && ((!mAttachedHidden && |
| 8058 | (atoken == null || !atoken.hiddenRequested)) |
| 8059 | || mAnimating); |
| 8060 | } |
| 8061 | |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8062 | /** |
| 8063 | * Returns true if the window has a surface that it has drawn a |
| 8064 | * complete UI in to. |
| 8065 | */ |
| 8066 | public boolean isDrawnLw() { |
| 8067 | final AppWindowToken atoken = mAppToken; |
| 8068 | return mSurface != null && !mDestroying |
| 8069 | && !mDrawPending && !mCommitDrawPending; |
| 8070 | } |
| 8071 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8072 | /** |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8073 | * Return true if the window is opaque and fully drawn. This indicates |
| 8074 | * it may obscure windows behind it. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8075 | */ |
| 8076 | boolean isOpaqueDrawn() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8077 | return (mAttrs.format == PixelFormat.OPAQUE |
| 8078 | || mAttrs.type == TYPE_WALLPAPER) |
| 8079 | && mSurface != null && mAnimation == null |
| 8080 | && (mAppToken == null || mAppToken.animation == null) |
| 8081 | && !mDrawPending && !mCommitDrawPending; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8082 | } |
| 8083 | |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 8084 | /** |
| 8085 | * Return whether this window is wanting to have a translation |
| 8086 | * animation applied to it for an in-progress move. (Only makes |
| 8087 | * sense to call from performLayoutAndPlaceSurfacesLockedInner().) |
| 8088 | */ |
| 8089 | boolean shouldAnimateMove() { |
| Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 8090 | return mContentChanged && !mExiting && !mLastHidden && !mDisplayFrozen |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 8091 | && (mFrame.top != mLastFrame.top |
| 8092 | || mFrame.left != mLastFrame.left) |
| Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 8093 | && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove()) |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 8094 | && mPolicy.isScreenOn(); |
| 8095 | } |
| 8096 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8097 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 8098 | return |
| 8099 | // only if the application is requesting compatible window |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 8100 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 8101 | // only if it's visible |
| 8102 | mHasDrawn && mViewVisibility == View.VISIBLE && |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 8103 | // and only if the application fills the compatible screen |
| 8104 | mFrame.left <= mCompatibleScreenFrame.left && |
| 8105 | mFrame.top <= mCompatibleScreenFrame.top && |
| 8106 | mFrame.right >= mCompatibleScreenFrame.right && |
| Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 8107 | mFrame.bottom >= mCompatibleScreenFrame.bottom; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8108 | } |
| 8109 | |
| 8110 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 8111 | return mFrame.left <= 0 && mFrame.top <= 0 && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 8112 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8113 | } |
| 8114 | |
| 8115 | void removeLocked() { |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 8116 | disposeInputChannel(); |
| 8117 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8118 | if (mAttachedWindow != null) { |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8119 | 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] | 8120 | mAttachedWindow.mChildWindows.remove(this); |
| 8121 | } |
| 8122 | destroySurfaceLocked(); |
| 8123 | mSession.windowRemovedLocked(); |
| 8124 | try { |
| 8125 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 8126 | } catch (RuntimeException e) { |
| 8127 | // Ignore if it has already been removed (usually because |
| 8128 | // we are doing this as part of processing a death note.) |
| 8129 | } |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 8130 | } |
| 8131 | |
| 8132 | void disposeInputChannel() { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 8133 | if (mInputChannel != null) { |
| 8134 | mInputManager.unregisterInputChannel(mInputChannel); |
| 8135 | |
| 8136 | mInputChannel.dispose(); |
| 8137 | mInputChannel = null; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8138 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8139 | } |
| 8140 | |
| 8141 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 8142 | public void binderDied() { |
| 8143 | try { |
| 8144 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8145 | WindowState win = windowForClientLocked(mSession, mClient, false); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8146 | Slog.i(TAG, "WIN DEATH: " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8147 | if (win != null) { |
| 8148 | removeWindowLocked(mSession, win); |
| 8149 | } |
| 8150 | } |
| 8151 | } catch (IllegalArgumentException ex) { |
| 8152 | // This will happen if the window has already been |
| 8153 | // removed. |
| 8154 | } |
| 8155 | } |
| 8156 | } |
| 8157 | |
| 8158 | /** Returns true if this window desires key events. */ |
| 8159 | public final boolean canReceiveKeys() { |
| 8160 | return isVisibleOrAdding() |
| 8161 | && (mViewVisibility == View.VISIBLE) |
| 8162 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 8163 | } |
| 8164 | |
| 8165 | public boolean hasDrawnLw() { |
| 8166 | return mHasDrawn; |
| 8167 | } |
| 8168 | |
| 8169 | public boolean showLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8170 | return showLw(doAnimation, true); |
| 8171 | } |
| 8172 | |
| 8173 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 8174 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 8175 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8176 | } |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8177 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8178 | if (doAnimation) { |
| 8179 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
| 8180 | + mPolicyVisibility + " mAnimation=" + mAnimation); |
| 8181 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 8182 | doAnimation = false; |
| 8183 | } else if (mPolicyVisibility && mAnimation == null) { |
| 8184 | // Check for the case where we are currently visible and |
| 8185 | // not animating; we do not want to do animation at such a |
| 8186 | // point to become visible when we already are. |
| 8187 | doAnimation = false; |
| 8188 | } |
| 8189 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8190 | mPolicyVisibility = true; |
| 8191 | mPolicyVisibilityAfterAnim = true; |
| 8192 | if (doAnimation) { |
| 8193 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 8194 | } |
| 8195 | if (requestAnim) { |
| 8196 | requestAnimationLocked(0); |
| 8197 | } |
| 8198 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8199 | } |
| 8200 | |
| 8201 | public boolean hideLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8202 | return hideLw(doAnimation, true); |
| 8203 | } |
| 8204 | |
| 8205 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8206 | if (doAnimation) { |
| 8207 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 8208 | doAnimation = false; |
| 8209 | } |
| 8210 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8211 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 8212 | : mPolicyVisibility; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8213 | if (!current) { |
| 8214 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8215 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8216 | if (doAnimation) { |
| 8217 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 8218 | if (mAnimation == null) { |
| 8219 | doAnimation = false; |
| 8220 | } |
| 8221 | } |
| 8222 | if (doAnimation) { |
| 8223 | mPolicyVisibilityAfterAnim = false; |
| 8224 | } else { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8225 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8226 | mPolicyVisibilityAfterAnim = false; |
| 8227 | mPolicyVisibility = false; |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 8228 | // Window is no longer visible -- make sure if we were waiting |
| 8229 | // for it to be displayed before enabling the display, that |
| 8230 | // we allow the display to be enabled now. |
| 8231 | enableScreenIfNeededLocked(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8232 | if (mCurrentFocus == this) { |
| 8233 | mFocusMayChange = true; |
| 8234 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8235 | } |
| 8236 | if (requestAnim) { |
| 8237 | requestAnimationLocked(0); |
| 8238 | } |
| 8239 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8240 | } |
| 8241 | |
| Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 8242 | public void getTouchableRegion(Region outRegion) { |
| 8243 | final Rect frame = mFrame; |
| 8244 | switch (mTouchableInsets) { |
| 8245 | default: |
| 8246 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME: |
| 8247 | outRegion.set(frame); |
| 8248 | break; |
| 8249 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: { |
| 8250 | final Rect inset = mGivenContentInsets; |
| 8251 | outRegion.set( |
| 8252 | frame.left + inset.left, frame.top + inset.top, |
| 8253 | frame.right - inset.right, frame.bottom - inset.bottom); |
| 8254 | break; |
| 8255 | } |
| 8256 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: { |
| 8257 | final Rect inset = mGivenVisibleInsets; |
| 8258 | outRegion.set( |
| 8259 | frame.left + inset.left, frame.top + inset.top, |
| 8260 | frame.right - inset.right, frame.bottom - inset.bottom); |
| 8261 | break; |
| 8262 | } |
| 8263 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: { |
| 8264 | final Region givenTouchableRegion = mGivenTouchableRegion; |
| 8265 | outRegion.set(givenTouchableRegion); |
| 8266 | outRegion.translate(frame.left, frame.top); |
| 8267 | break; |
| 8268 | } |
| 8269 | } |
| 8270 | } |
| 8271 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8272 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8273 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 8274 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 8275 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 8276 | if (mAttachedWindow != null || mLayoutAttached) { |
| 8277 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 8278 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 8279 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 8280 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 8281 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 8282 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8283 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 8284 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8285 | } |
| 8286 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 8287 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 8288 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 8289 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 8290 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 8291 | pw.print("="); pw.print(mAnimLayer); |
| 8292 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 8293 | if (mSurface != null) { |
| 8294 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8295 | pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown); |
| 8296 | pw.print(" layer="); pw.print(mSurfaceLayer); |
| 8297 | pw.print(" alpha="); pw.print(mSurfaceAlpha); |
| 8298 | pw.print(" rect=("); pw.print(mSurfaceX); |
| 8299 | pw.print(","); pw.print(mSurfaceY); |
| 8300 | pw.print(") "); pw.print(mSurfaceW); |
| 8301 | pw.print(" x "); pw.println(mSurfaceH); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8302 | } |
| 8303 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 8304 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 8305 | if (mAppToken != null) { |
| 8306 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 8307 | } |
| 8308 | if (mTargetAppToken != null) { |
| 8309 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 8310 | } |
| 8311 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 8312 | pw.print(Integer.toHexString(mViewVisibility)); |
| 8313 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8314 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 8315 | pw.print(" mObscured="); pw.println(mObscured); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8316 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 8317 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 8318 | pw.print(mPolicyVisibility); |
| 8319 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 8320 | pw.print(mPolicyVisibilityAfterAnim); |
| 8321 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 8322 | } |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 8323 | if (!mRelayoutCalled) { |
| 8324 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled); |
| 8325 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8326 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8327 | pw.print(" h="); pw.print(mRequestedHeight); |
| 8328 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8329 | if (mXOffset != 0 || mYOffset != 0) { |
| 8330 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 8331 | pw.print(" y="); pw.println(mYOffset); |
| 8332 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8333 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 8334 | mGivenContentInsets.printShortString(pw); |
| 8335 | pw.print(" mGivenVisibleInsets="); |
| 8336 | mGivenVisibleInsets.printShortString(pw); |
| 8337 | pw.println(); |
| 8338 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 8339 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 8340 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 8341 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8342 | pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8343 | pw.print(prefix); pw.print("mShownFrame="); |
| 8344 | mShownFrame.printShortString(pw); |
| 8345 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 8346 | pw.println(); |
| 8347 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 8348 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 8349 | pw.println(); |
| 8350 | pw.print(prefix); pw.print("mContainingFrame="); |
| 8351 | mContainingFrame.printShortString(pw); |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 8352 | pw.print(" mParentFrame="); |
| 8353 | mParentFrame.printShortString(pw); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8354 | pw.print(" mDisplayFrame="); |
| 8355 | mDisplayFrame.printShortString(pw); |
| 8356 | pw.println(); |
| 8357 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 8358 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 8359 | pw.println(); |
| 8360 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 8361 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 8362 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 8363 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 8364 | pw.println(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8365 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 8366 | || mAnimation != null) { |
| 8367 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 8368 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 8369 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 8370 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 8371 | } |
| 8372 | if (mHasTransformation || mHasLocalTransformation) { |
| 8373 | pw.print(prefix); pw.print("XForm: has="); |
| 8374 | pw.print(mHasTransformation); |
| 8375 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 8376 | pw.print(" "); mTransformation.printShortString(pw); |
| 8377 | pw.println(); |
| 8378 | } |
| Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 8379 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 8380 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 8381 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 8382 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 8383 | } |
| 8384 | if (mHaveMatrix) { |
| 8385 | pw.print(prefix); pw.print("mDsDx="); pw.print(mDsDx); |
| 8386 | pw.print(" mDtDx="); pw.print(mDtDx); |
| 8387 | pw.print(" mDsDy="); pw.print(mDsDy); |
| 8388 | pw.print(" mDtDy="); pw.println(mDtDy); |
| 8389 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8390 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 8391 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 8392 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 8393 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 8394 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 8395 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 8396 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 8397 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 8398 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 8399 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8400 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8401 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 8402 | pw.print(mOrientationChanging); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8403 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 8404 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8405 | } |
| Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 8406 | if (mHScale != 1 || mVScale != 1) { |
| 8407 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 8408 | pw.print(" mVScale="); pw.println(mVScale); |
| 8409 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 8410 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8411 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 8412 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 8413 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 8414 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 8415 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 8416 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 8417 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8418 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8419 | |
| 8420 | String makeInputChannelName() { |
| 8421 | return Integer.toHexString(System.identityHashCode(this)) |
| 8422 | + " " + mAttrs.getTitle(); |
| 8423 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8424 | |
| 8425 | @Override |
| 8426 | public String toString() { |
| Mattias Petersson | 1622eee | 2010-12-21 10:15:11 +0100 | [diff] [blame] | 8427 | if (mStringNameCache == null || mLastTitle != mAttrs.getTitle() |
| 8428 | || mWasPaused != mToken.paused) { |
| 8429 | mLastTitle = mAttrs.getTitle(); |
| 8430 | mWasPaused = mToken.paused; |
| 8431 | mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this)) |
| 8432 | + " " + mLastTitle + " paused=" + mWasPaused + "}"; |
| 8433 | } |
| 8434 | return mStringNameCache; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8435 | } |
| 8436 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8437 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8438 | // ------------------------------------------------------------- |
| 8439 | // Window Token State |
| 8440 | // ------------------------------------------------------------- |
| 8441 | |
| 8442 | class WindowToken { |
| 8443 | // The actual token. |
| 8444 | final IBinder token; |
| 8445 | |
| 8446 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 8447 | final int windowType; |
| 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 | // Set if this token was explicitly added by a client, so should |
| 8450 | // not be removed when all windows are removed. |
| 8451 | final boolean explicit; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8452 | |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8453 | // For printing. |
| 8454 | String stringName; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8455 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8456 | // If this is an AppWindowToken, this is non-null. |
| 8457 | AppWindowToken appWindowToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8458 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8459 | // All of the windows associated with this token. |
| 8460 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 8461 | |
| 8462 | // Is key dispatching paused for this token? |
| 8463 | boolean paused = false; |
| 8464 | |
| 8465 | // Should this token's windows be hidden? |
| 8466 | boolean hidden; |
| 8467 | |
| 8468 | // Temporary for finding which tokens no longer have visible windows. |
| 8469 | boolean hasVisible; |
| 8470 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8471 | // Set to true when this token is in a pending transaction where it |
| 8472 | // will be shown. |
| 8473 | boolean waitingToShow; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8474 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8475 | // Set to true when this token is in a pending transaction where it |
| 8476 | // will be hidden. |
| 8477 | boolean waitingToHide; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8478 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8479 | // Set to true when this token is in a pending transaction where its |
| 8480 | // windows will be put to the bottom of the list. |
| 8481 | boolean sendingToBottom; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8482 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8483 | // Set to true when this token is in a pending transaction where its |
| 8484 | // windows will be put to the top of the list. |
| 8485 | boolean sendingToTop; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8486 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8487 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 8488 | token = _token; |
| 8489 | windowType = type; |
| 8490 | explicit = _explicit; |
| 8491 | } |
| 8492 | |
| 8493 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8494 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 8495 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 8496 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 8497 | pw.print(" hidden="); pw.print(hidden); |
| 8498 | pw.print(" hasVisible="); pw.println(hasVisible); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8499 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 8500 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 8501 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 8502 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 8503 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 8504 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8505 | } |
| 8506 | |
| 8507 | @Override |
| 8508 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8509 | if (stringName == null) { |
| 8510 | StringBuilder sb = new StringBuilder(); |
| 8511 | sb.append("WindowToken{"); |
| 8512 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8513 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8514 | stringName = sb.toString(); |
| 8515 | } |
| 8516 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8517 | } |
| 8518 | }; |
| 8519 | |
| 8520 | class AppWindowToken extends WindowToken { |
| 8521 | // Non-null only for application tokens. |
| 8522 | final IApplicationToken appToken; |
| 8523 | |
| 8524 | // All of the windows and child windows that are included in this |
| 8525 | // application token. Note this list is NOT sorted! |
| 8526 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 8527 | |
| 8528 | int groupId = -1; |
| 8529 | boolean appFullscreen; |
| 8530 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8531 | |
| 8532 | // The input dispatching timeout for this application token in nanoseconds. |
| 8533 | long inputDispatchingTimeoutNanos; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8534 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8535 | // These are used for determining when all windows associated with |
| 8536 | // an activity have been drawn, so they can be made visible together |
| 8537 | // at the same time. |
| 8538 | int lastTransactionSequence = mTransactionSequence-1; |
| 8539 | int numInterestingWindows; |
| 8540 | int numDrawnWindows; |
| 8541 | boolean inPendingTransaction; |
| 8542 | boolean allDrawn; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8543 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8544 | // Is this token going to be hidden in a little while? If so, it |
| 8545 | // won't be taken into account for setting the screen orientation. |
| 8546 | boolean willBeHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8547 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8548 | // Is this window's surface needed? This is almost like hidden, except |
| 8549 | // it will sometimes be true a little earlier: when the token has |
| 8550 | // been shown, but is still waiting for its app transition to execute |
| 8551 | // before making its windows shown. |
| 8552 | boolean hiddenRequested; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8553 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8554 | // Have we told the window clients to hide themselves? |
| 8555 | boolean clientHidden; |
| 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 | // Last visibility state we reported to the app token. |
| 8558 | boolean reportedVisible; |
| 8559 | |
| 8560 | // Set to true when the token has been removed from the window mgr. |
| 8561 | boolean removed; |
| 8562 | |
| 8563 | // Have we been asked to have this token keep the screen frozen? |
| 8564 | boolean freezingScreen; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8565 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8566 | boolean animating; |
| 8567 | Animation animation; |
| 8568 | boolean hasTransformation; |
| 8569 | final Transformation transformation = new Transformation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8570 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8571 | // Offset to the window of all layers in the token, for use by |
| 8572 | // AppWindowToken animations. |
| 8573 | int animLayerAdjustment; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8574 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8575 | // Information about an application starting window if displayed. |
| 8576 | StartingData startingData; |
| 8577 | WindowState startingWindow; |
| 8578 | View startingView; |
| 8579 | boolean startingDisplayed; |
| 8580 | boolean startingMoved; |
| 8581 | boolean firstWindowDrawn; |
| 8582 | |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 8583 | // Input application handle used by the input dispatcher. |
| 8584 | InputApplicationHandle mInputApplicationHandle; |
| 8585 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8586 | AppWindowToken(IApplicationToken _token) { |
| 8587 | super(_token.asBinder(), |
| 8588 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 8589 | appWindowToken = this; |
| 8590 | appToken = _token; |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 8591 | mInputApplicationHandle = new InputApplicationHandle(this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8592 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8593 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8594 | public void setAnimation(Animation anim) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8595 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8596 | TAG, "Setting animation in " + this + ": " + anim); |
| 8597 | animation = anim; |
| 8598 | animating = false; |
| 8599 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 8600 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 8601 | int zorder = anim.getZAdjustment(); |
| 8602 | int adj = 0; |
| 8603 | if (zorder == Animation.ZORDER_TOP) { |
| 8604 | adj = TYPE_LAYER_OFFSET; |
| 8605 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 8606 | adj = -TYPE_LAYER_OFFSET; |
| 8607 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8608 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8609 | if (animLayerAdjustment != adj) { |
| 8610 | animLayerAdjustment = adj; |
| 8611 | updateLayers(); |
| 8612 | } |
| 8613 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8614 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8615 | public void setDummyAnimation() { |
| 8616 | if (animation == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8617 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8618 | TAG, "Setting dummy animation in " + this); |
| 8619 | animation = sDummyAnimation; |
| 8620 | } |
| 8621 | } |
| 8622 | |
| 8623 | public void clearAnimation() { |
| 8624 | if (animation != null) { |
| 8625 | animation = null; |
| 8626 | animating = true; |
| 8627 | } |
| 8628 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8629 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8630 | void updateLayers() { |
| 8631 | final int N = allAppWindows.size(); |
| 8632 | final int adj = animLayerAdjustment; |
| 8633 | for (int i=0; i<N; i++) { |
| 8634 | WindowState w = allAppWindows.get(i); |
| 8635 | w.mAnimLayer = w.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8636 | if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8637 | + w.mAnimLayer); |
| Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 8638 | if (w == mInputMethodTarget && !mInputMethodTargetWaitingAnim) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8639 | setInputMethodAnimLayerAdjustment(adj); |
| 8640 | } |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8641 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8642 | setWallpaperAnimLayerAdjustmentLocked(adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8643 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8644 | } |
| 8645 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8646 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8647 | void sendAppVisibilityToClients() { |
| 8648 | final int N = allAppWindows.size(); |
| 8649 | for (int i=0; i<N; i++) { |
| 8650 | WindowState win = allAppWindows.get(i); |
| 8651 | if (win == startingWindow && clientHidden) { |
| 8652 | // Don't hide the starting window. |
| 8653 | continue; |
| 8654 | } |
| 8655 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8656 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8657 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 8658 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 8659 | } catch (RemoteException e) { |
| 8660 | } |
| 8661 | } |
| 8662 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8663 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8664 | void showAllWindowsLocked() { |
| 8665 | final int NW = allAppWindows.size(); |
| 8666 | for (int i=0; i<NW; i++) { |
| 8667 | WindowState w = allAppWindows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8668 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8669 | "performing show on: " + w); |
| 8670 | w.performShowLocked(); |
| 8671 | } |
| 8672 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8673 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8674 | // This must be called while inside a transaction. |
| 8675 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8676 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8677 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8678 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8679 | if (animation == sDummyAnimation) { |
| 8680 | // This guy is going to animate, but not yet. For now count |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8681 | // it as not animating for purposes of scheduling transactions; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8682 | // when it is really time to animate, this will be set to |
| 8683 | // a real animation and the next call will execute normally. |
| 8684 | return false; |
| 8685 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8686 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8687 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 8688 | if (!animating) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8689 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8690 | TAG, "Starting animation in " + this + |
| 8691 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 8692 | + " scale=" + mTransitionAnimationScale |
| 8693 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 8694 | animation.initialize(dw, dh, dw, dh); |
| 8695 | animation.setStartTime(currentTime); |
| 8696 | animating = true; |
| 8697 | } |
| 8698 | transformation.clear(); |
| 8699 | final boolean more = animation.getTransformation( |
| 8700 | currentTime, transformation); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8701 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8702 | TAG, "Stepped animation in " + this + |
| 8703 | ": more=" + more + ", xform=" + transformation); |
| 8704 | if (more) { |
| 8705 | // we're done! |
| 8706 | hasTransformation = true; |
| 8707 | return true; |
| 8708 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8709 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8710 | TAG, "Finished animation in " + this + |
| 8711 | " @ " + currentTime); |
| 8712 | animation = null; |
| 8713 | } |
| 8714 | } else if (animation != null) { |
| 8715 | // If the display is frozen, and there is a pending animation, |
| 8716 | // clear it and make sure we run the cleanup code. |
| 8717 | animating = true; |
| 8718 | animation = null; |
| 8719 | } |
| 8720 | |
| 8721 | hasTransformation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8722 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8723 | if (!animating) { |
| 8724 | return false; |
| 8725 | } |
| 8726 | |
| 8727 | clearAnimation(); |
| 8728 | animating = false; |
| Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 8729 | if (animLayerAdjustment != 0) { |
| 8730 | animLayerAdjustment = 0; |
| 8731 | updateLayers(); |
| 8732 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8733 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 8734 | moveInputMethodWindowsIfNeededLocked(true); |
| 8735 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8736 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8737 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8738 | TAG, "Animation done in " + this |
| 8739 | + ": reportedVisible=" + reportedVisible); |
| 8740 | |
| 8741 | transformation.clear(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8742 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8743 | final int N = windows.size(); |
| 8744 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8745 | windows.get(i).finishExit(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8746 | } |
| 8747 | updateReportedVisibilityLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8748 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8749 | return false; |
| 8750 | } |
| 8751 | |
| 8752 | void updateReportedVisibilityLocked() { |
| 8753 | if (appToken == null) { |
| 8754 | return; |
| 8755 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8756 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8757 | int numInteresting = 0; |
| 8758 | int numVisible = 0; |
| 8759 | boolean nowGone = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8760 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8761 | 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] | 8762 | final int N = allAppWindows.size(); |
| 8763 | for (int i=0; i<N; i++) { |
| 8764 | WindowState win = allAppWindows.get(i); |
| Dianne Hackborn | 6cf67fa | 2009-12-21 16:46:34 -0800 | [diff] [blame] | 8765 | if (win == startingWindow || win.mAppFreezing |
| The Android Open Source Project | 727cec0 | 2010-04-08 11:35:37 -0700 | [diff] [blame] | 8766 | || win.mViewVisibility != View.VISIBLE |
| Ulf Rosdahl | 3935770 | 2010-09-29 12:34:38 +0200 | [diff] [blame] | 8767 | || win.mAttrs.type == TYPE_APPLICATION_STARTING |
| 8768 | || win.mDestroying) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8769 | continue; |
| 8770 | } |
| 8771 | if (DEBUG_VISIBILITY) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8772 | Slog.v(TAG, "Win " + win + ": isDrawn=" |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8773 | + win.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8774 | + ", isAnimating=" + win.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8775 | if (!win.isDrawnLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8776 | Slog.v(TAG, "Not displayed: s=" + win.mSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8777 | + " pv=" + win.mPolicyVisibility |
| 8778 | + " dp=" + win.mDrawPending |
| 8779 | + " cdp=" + win.mCommitDrawPending |
| 8780 | + " ah=" + win.mAttachedHidden |
| 8781 | + " th=" |
| 8782 | + (win.mAppToken != null |
| 8783 | ? win.mAppToken.hiddenRequested : false) |
| 8784 | + " a=" + win.mAnimating); |
| 8785 | } |
| 8786 | } |
| 8787 | numInteresting++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8788 | if (win.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8789 | if (!win.isAnimating()) { |
| 8790 | numVisible++; |
| 8791 | } |
| 8792 | nowGone = false; |
| 8793 | } else if (win.isAnimating()) { |
| 8794 | nowGone = false; |
| 8795 | } |
| 8796 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8797 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8798 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8799 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8800 | + numInteresting + " visible=" + numVisible); |
| 8801 | if (nowVisible != reportedVisible) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8802 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8803 | TAG, "Visibility changed in " + this |
| 8804 | + ": vis=" + nowVisible); |
| 8805 | reportedVisible = nowVisible; |
| 8806 | Message m = mH.obtainMessage( |
| 8807 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 8808 | nowVisible ? 1 : 0, |
| 8809 | nowGone ? 1 : 0, |
| 8810 | this); |
| 8811 | mH.sendMessage(m); |
| 8812 | } |
| 8813 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8814 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8815 | WindowState findMainWindow() { |
| 8816 | int j = windows.size(); |
| 8817 | while (j > 0) { |
| 8818 | j--; |
| 8819 | WindowState win = windows.get(j); |
| 8820 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 8821 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 8822 | return win; |
| 8823 | } |
| 8824 | } |
| 8825 | return null; |
| 8826 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8827 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8828 | void dump(PrintWriter pw, String prefix) { |
| 8829 | super.dump(pw, prefix); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8830 | if (appToken != null) { |
| 8831 | pw.print(prefix); pw.println("app=true"); |
| 8832 | } |
| 8833 | if (allAppWindows.size() > 0) { |
| 8834 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 8835 | } |
| 8836 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8837 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8838 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 8839 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 8840 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 8841 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 8842 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 8843 | if (paused || freezingScreen) { |
| 8844 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 8845 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 8846 | } |
| 8847 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 8848 | || inPendingTransaction || allDrawn) { |
| 8849 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 8850 | pw.print(numInterestingWindows); |
| 8851 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 8852 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 8853 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 8854 | } |
| 8855 | if (animating || animation != null) { |
| 8856 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 8857 | pw.print(" animation="); pw.println(animation); |
| 8858 | } |
| Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 8859 | if (hasTransformation) { |
| 8860 | pw.print(prefix); pw.print("XForm: "); |
| 8861 | transformation.printShortString(pw); |
| 8862 | pw.println(); |
| 8863 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8864 | if (animLayerAdjustment != 0) { |
| 8865 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 8866 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8867 | if (startingData != null || removed || firstWindowDrawn) { |
| 8868 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 8869 | pw.print(" removed="); pw.print(removed); |
| 8870 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 8871 | } |
| 8872 | if (startingWindow != null || startingView != null |
| 8873 | || startingDisplayed || startingMoved) { |
| 8874 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 8875 | pw.print(" startingView="); pw.print(startingView); |
| 8876 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 8877 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 8878 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8879 | } |
| 8880 | |
| 8881 | @Override |
| 8882 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8883 | if (stringName == null) { |
| 8884 | StringBuilder sb = new StringBuilder(); |
| 8885 | sb.append("AppWindowToken{"); |
| 8886 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8887 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8888 | stringName = sb.toString(); |
| 8889 | } |
| 8890 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8891 | } |
| 8892 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8893 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8894 | // ------------------------------------------------------------- |
| 8895 | // DummyAnimation |
| 8896 | // ------------------------------------------------------------- |
| 8897 | |
| 8898 | // This is an animation that does nothing: it just immediately finishes |
| 8899 | // itself every time it is called. It is used as a stub animation in cases |
| 8900 | // where we want to synchronize multiple things that may be animating. |
| 8901 | static final class DummyAnimation extends Animation { |
| 8902 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 8903 | return false; |
| 8904 | } |
| 8905 | } |
| 8906 | static final Animation sDummyAnimation = new DummyAnimation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8907 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8908 | // ------------------------------------------------------------- |
| 8909 | // Async Handler |
| 8910 | // ------------------------------------------------------------- |
| 8911 | |
| 8912 | static final class StartingData { |
| 8913 | final String pkg; |
| 8914 | final int theme; |
| 8915 | final CharSequence nonLocalizedLabel; |
| 8916 | final int labelRes; |
| 8917 | final int icon; |
| Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 8918 | final int windowFlags; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8919 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8920 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 8921 | int _labelRes, int _icon, int _windowFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8922 | pkg = _pkg; |
| 8923 | theme = _theme; |
| 8924 | nonLocalizedLabel = _nonLocalizedLabel; |
| 8925 | labelRes = _labelRes; |
| 8926 | icon = _icon; |
| Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 8927 | windowFlags = _windowFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8928 | } |
| 8929 | } |
| 8930 | |
| 8931 | private final class H extends Handler { |
| 8932 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 8933 | public static final int REPORT_LOSING_FOCUS = 3; |
| 8934 | public static final int ANIMATE = 4; |
| 8935 | public static final int ADD_STARTING = 5; |
| 8936 | public static final int REMOVE_STARTING = 6; |
| 8937 | public static final int FINISHED_STARTING = 7; |
| 8938 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8939 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 8940 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 8941 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 8942 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 8943 | public static final int FORCE_GC = 15; |
| 8944 | public static final int ENABLE_SCREEN = 16; |
| 8945 | public static final int APP_FREEZE_TIMEOUT = 17; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8946 | public static final int SEND_NEW_CONFIGURATION = 18; |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8947 | public static final int REPORT_WINDOWS_CHANGE = 19; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8948 | public static final int DRAG_START_TIMEOUT = 20; |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 8949 | public static final int DRAG_END_TIMEOUT = 21; |
| Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 8950 | public static final int REPORT_HARD_KEYBOARD_STATUS_CHANGE = 22; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8951 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8952 | private Session mLastReportedHold; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8953 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8954 | public H() { |
| 8955 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8956 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8957 | @Override |
| 8958 | public void handleMessage(Message msg) { |
| 8959 | switch (msg.what) { |
| 8960 | case REPORT_FOCUS_CHANGE: { |
| 8961 | WindowState lastFocus; |
| 8962 | WindowState newFocus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8963 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8964 | synchronized(mWindowMap) { |
| 8965 | lastFocus = mLastFocus; |
| 8966 | newFocus = mCurrentFocus; |
| 8967 | if (lastFocus == newFocus) { |
| 8968 | // Focus is not changing, so nothing to do. |
| 8969 | return; |
| 8970 | } |
| 8971 | mLastFocus = newFocus; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8972 | //Slog.i(TAG, "Focus moving from " + lastFocus |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8973 | // + " to " + newFocus); |
| 8974 | if (newFocus != null && lastFocus != null |
| 8975 | && !newFocus.isDisplayedLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8976 | //Slog.i(TAG, "Delaying loss of focus..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8977 | mLosingFocus.add(lastFocus); |
| 8978 | lastFocus = null; |
| 8979 | } |
| 8980 | } |
| 8981 | |
| 8982 | if (lastFocus != newFocus) { |
| 8983 | //System.out.println("Changing focus from " + lastFocus |
| 8984 | // + " to " + newFocus); |
| 8985 | if (newFocus != null) { |
| 8986 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8987 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8988 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 8989 | } catch (RemoteException e) { |
| 8990 | // Ignore if process has died. |
| 8991 | } |
| Konstantin Lopyrev | 5e7833a | 2010-08-09 17:01:11 -0700 | [diff] [blame] | 8992 | notifyFocusChanged(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8993 | } |
| 8994 | |
| 8995 | if (lastFocus != null) { |
| 8996 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8997 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8998 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 8999 | } catch (RemoteException e) { |
| 9000 | // Ignore if process has died. |
| 9001 | } |
| 9002 | } |
| Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 9003 | |
| 9004 | mPolicy.focusChanged(lastFocus, newFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9005 | } |
| 9006 | } break; |
| 9007 | |
| 9008 | case REPORT_LOSING_FOCUS: { |
| 9009 | ArrayList<WindowState> losers; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9010 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9011 | synchronized(mWindowMap) { |
| 9012 | losers = mLosingFocus; |
| 9013 | mLosingFocus = new ArrayList<WindowState>(); |
| 9014 | } |
| 9015 | |
| 9016 | final int N = losers.size(); |
| 9017 | for (int i=0; i<N; i++) { |
| 9018 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9019 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9020 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 9021 | } catch (RemoteException e) { |
| 9022 | // Ignore if process has died. |
| 9023 | } |
| 9024 | } |
| 9025 | } break; |
| 9026 | |
| 9027 | case ANIMATE: { |
| 9028 | synchronized(mWindowMap) { |
| 9029 | mAnimationPending = false; |
| 9030 | performLayoutAndPlaceSurfacesLocked(); |
| 9031 | } |
| 9032 | } break; |
| 9033 | |
| 9034 | case ADD_STARTING: { |
| 9035 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 9036 | final StartingData sd = wtoken.startingData; |
| 9037 | |
| 9038 | if (sd == null) { |
| 9039 | // Animation has been canceled... do nothing. |
| 9040 | return; |
| 9041 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9042 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9043 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9044 | + wtoken + ": pkg=" + sd.pkg); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9045 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9046 | View view = null; |
| 9047 | try { |
| 9048 | view = mPolicy.addStartingWindow( |
| 9049 | wtoken.token, sd.pkg, |
| 9050 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 9051 | sd.icon, sd.windowFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9052 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9053 | Slog.w(TAG, "Exception when adding starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9054 | } |
| 9055 | |
| 9056 | if (view != null) { |
| 9057 | boolean abort = false; |
| 9058 | |
| 9059 | synchronized(mWindowMap) { |
| 9060 | if (wtoken.removed || wtoken.startingData == null) { |
| 9061 | // If the window was successfully added, then |
| 9062 | // we need to remove it. |
| 9063 | if (wtoken.startingWindow != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9064 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9065 | "Aborted starting " + wtoken |
| 9066 | + ": removed=" + wtoken.removed |
| 9067 | + " startingData=" + wtoken.startingData); |
| 9068 | wtoken.startingWindow = null; |
| 9069 | wtoken.startingData = null; |
| 9070 | abort = true; |
| 9071 | } |
| 9072 | } else { |
| 9073 | wtoken.startingView = view; |
| 9074 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9075 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9076 | "Added starting " + wtoken |
| 9077 | + ": startingWindow=" |
| 9078 | + wtoken.startingWindow + " startingView=" |
| 9079 | + wtoken.startingView); |
| 9080 | } |
| 9081 | |
| 9082 | if (abort) { |
| 9083 | try { |
| 9084 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 9085 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9086 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9087 | } |
| 9088 | } |
| 9089 | } |
| 9090 | } break; |
| 9091 | |
| 9092 | case REMOVE_STARTING: { |
| 9093 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 9094 | IBinder token = null; |
| 9095 | View view = null; |
| 9096 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9097 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9098 | + wtoken + ": startingWindow=" |
| 9099 | + wtoken.startingWindow + " startingView=" |
| 9100 | + wtoken.startingView); |
| 9101 | if (wtoken.startingWindow != null) { |
| 9102 | view = wtoken.startingView; |
| 9103 | token = wtoken.token; |
| 9104 | wtoken.startingData = null; |
| 9105 | wtoken.startingView = null; |
| 9106 | wtoken.startingWindow = null; |
| 9107 | } |
| 9108 | } |
| 9109 | if (view != null) { |
| 9110 | try { |
| 9111 | mPolicy.removeStartingWindow(token, view); |
| 9112 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9113 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9114 | } |
| 9115 | } |
| 9116 | } break; |
| 9117 | |
| 9118 | case FINISHED_STARTING: { |
| 9119 | IBinder token = null; |
| 9120 | View view = null; |
| 9121 | while (true) { |
| 9122 | synchronized (mWindowMap) { |
| 9123 | final int N = mFinishedStarting.size(); |
| 9124 | if (N <= 0) { |
| 9125 | break; |
| 9126 | } |
| 9127 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 9128 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9129 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9130 | "Finished starting " + wtoken |
| 9131 | + ": startingWindow=" + wtoken.startingWindow |
| 9132 | + " startingView=" + wtoken.startingView); |
| 9133 | |
| 9134 | if (wtoken.startingWindow == null) { |
| 9135 | continue; |
| 9136 | } |
| 9137 | |
| 9138 | view = wtoken.startingView; |
| 9139 | token = wtoken.token; |
| 9140 | wtoken.startingData = null; |
| 9141 | wtoken.startingView = null; |
| 9142 | wtoken.startingWindow = null; |
| 9143 | } |
| 9144 | |
| 9145 | try { |
| 9146 | mPolicy.removeStartingWindow(token, view); |
| 9147 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9148 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9149 | } |
| 9150 | } |
| 9151 | } break; |
| 9152 | |
| 9153 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 9154 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 9155 | |
| 9156 | boolean nowVisible = msg.arg1 != 0; |
| 9157 | boolean nowGone = msg.arg2 != 0; |
| 9158 | |
| 9159 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9160 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9161 | TAG, "Reporting visible in " + wtoken |
| 9162 | + " visible=" + nowVisible |
| 9163 | + " gone=" + nowGone); |
| 9164 | if (nowVisible) { |
| 9165 | wtoken.appToken.windowsVisible(); |
| 9166 | } else { |
| 9167 | wtoken.appToken.windowsGone(); |
| 9168 | } |
| 9169 | } catch (RemoteException ex) { |
| 9170 | } |
| 9171 | } break; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9172 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9173 | case WINDOW_FREEZE_TIMEOUT: { |
| 9174 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9175 | Slog.w(TAG, "Window freeze timeout expired."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9176 | int i = mWindows.size(); |
| 9177 | while (i > 0) { |
| 9178 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9179 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9180 | if (w.mOrientationChanging) { |
| 9181 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9182 | Slog.w(TAG, "Force clearing orientation change: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9183 | } |
| 9184 | } |
| 9185 | performLayoutAndPlaceSurfacesLocked(); |
| 9186 | } |
| 9187 | break; |
| 9188 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9189 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9190 | case HOLD_SCREEN_CHANGED: { |
| 9191 | Session oldHold; |
| 9192 | Session newHold; |
| 9193 | synchronized (mWindowMap) { |
| 9194 | oldHold = mLastReportedHold; |
| 9195 | newHold = (Session)msg.obj; |
| 9196 | mLastReportedHold = newHold; |
| 9197 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9198 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9199 | if (oldHold != newHold) { |
| 9200 | try { |
| 9201 | if (oldHold != null) { |
| Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9202 | mBatteryStats.noteStopWakelock(oldHold.mUid, -1, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9203 | "window", |
| 9204 | BatteryStats.WAKE_TYPE_WINDOW); |
| 9205 | } |
| 9206 | if (newHold != null) { |
| Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9207 | mBatteryStats.noteStartWakelock(newHold.mUid, -1, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9208 | "window", |
| 9209 | BatteryStats.WAKE_TYPE_WINDOW); |
| 9210 | } |
| 9211 | } catch (RemoteException e) { |
| 9212 | } |
| 9213 | } |
| 9214 | break; |
| 9215 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9216 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9217 | case APP_TRANSITION_TIMEOUT: { |
| 9218 | synchronized (mWindowMap) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9219 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9220 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9221 | "*** APP TRANSITION TIMEOUT"); |
| 9222 | mAppTransitionReady = true; |
| 9223 | mAppTransitionTimeout = true; |
| 9224 | performLayoutAndPlaceSurfacesLocked(); |
| 9225 | } |
| 9226 | } |
| 9227 | break; |
| 9228 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9229 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9230 | case PERSIST_ANIMATION_SCALE: { |
| 9231 | Settings.System.putFloat(mContext.getContentResolver(), |
| 9232 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 9233 | Settings.System.putFloat(mContext.getContentResolver(), |
| 9234 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 9235 | break; |
| 9236 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9237 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9238 | case FORCE_GC: { |
| 9239 | synchronized(mWindowMap) { |
| 9240 | if (mAnimationPending) { |
| 9241 | // If we are animating, don't do the gc now but |
| 9242 | // delay a bit so we don't interrupt the animation. |
| 9243 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 9244 | 2000); |
| 9245 | return; |
| 9246 | } |
| 9247 | // If we are currently rotating the display, it will |
| 9248 | // schedule a new message when done. |
| 9249 | if (mDisplayFrozen) { |
| 9250 | return; |
| 9251 | } |
| 9252 | mFreezeGcPending = 0; |
| 9253 | } |
| 9254 | Runtime.getRuntime().gc(); |
| 9255 | break; |
| 9256 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9257 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9258 | case ENABLE_SCREEN: { |
| 9259 | performEnableScreen(); |
| 9260 | break; |
| 9261 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9262 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9263 | case APP_FREEZE_TIMEOUT: { |
| 9264 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9265 | Slog.w(TAG, "App freeze timeout expired."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9266 | int i = mAppTokens.size(); |
| 9267 | while (i > 0) { |
| 9268 | i--; |
| 9269 | AppWindowToken tok = mAppTokens.get(i); |
| 9270 | if (tok.freezingScreen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9271 | Slog.w(TAG, "Force clearing freeze: " + tok); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9272 | unsetAppFreezingScreenLocked(tok, true, true); |
| 9273 | } |
| 9274 | } |
| 9275 | } |
| 9276 | break; |
| 9277 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9278 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9279 | case SEND_NEW_CONFIGURATION: { |
| 9280 | removeMessages(SEND_NEW_CONFIGURATION); |
| 9281 | sendNewConfiguration(); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 9282 | break; |
| 9283 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9284 | |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 9285 | case REPORT_WINDOWS_CHANGE: { |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 9286 | if (mWindowsChanged) { |
| 9287 | synchronized (mWindowMap) { |
| 9288 | mWindowsChanged = false; |
| 9289 | } |
| 9290 | notifyWindowsChanged(); |
| 9291 | } |
| 9292 | break; |
| 9293 | } |
| 9294 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 9295 | case DRAG_START_TIMEOUT: { |
| 9296 | IBinder win = (IBinder)msg.obj; |
| 9297 | if (DEBUG_DRAG) { |
| 9298 | Slog.w(TAG, "Timeout starting drag by win " + win); |
| 9299 | } |
| 9300 | synchronized (mWindowMap) { |
| 9301 | // !!! TODO: ANR the app that has failed to start the drag in time |
| 9302 | if (mDragState != null) { |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 9303 | mDragState.unregister(); |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 9304 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 9305 | mDragState.reset(); |
| 9306 | mDragState = null; |
| 9307 | } |
| 9308 | } |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 9309 | break; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 9310 | } |
| 9311 | |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 9312 | case DRAG_END_TIMEOUT: { |
| 9313 | IBinder win = (IBinder)msg.obj; |
| 9314 | if (DEBUG_DRAG) { |
| 9315 | Slog.w(TAG, "Timeout ending drag to win " + win); |
| 9316 | } |
| 9317 | synchronized (mWindowMap) { |
| 9318 | // !!! TODO: ANR the drag-receiving app |
| 9319 | mDragState.mDragResult = false; |
| 9320 | mDragState.endDragLw(); |
| 9321 | } |
| 9322 | break; |
| 9323 | } |
| Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 9324 | |
| 9325 | case REPORT_HARD_KEYBOARD_STATUS_CHANGE: { |
| 9326 | notifyHardKeyboardStatusChange(); |
| 9327 | break; |
| 9328 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9329 | } |
| 9330 | } |
| 9331 | } |
| 9332 | |
| 9333 | // ------------------------------------------------------------- |
| 9334 | // IWindowManager API |
| 9335 | // ------------------------------------------------------------- |
| 9336 | |
| 9337 | public IWindowSession openSession(IInputMethodClient client, |
| 9338 | IInputContext inputContext) { |
| 9339 | if (client == null) throw new IllegalArgumentException("null client"); |
| 9340 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 9341 | Session session = new Session(client, inputContext); |
| 9342 | return session; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9343 | } |
| 9344 | |
| 9345 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 9346 | synchronized (mWindowMap) { |
| 9347 | // The focus for the client is the window immediately below |
| 9348 | // where we would place the input method window. |
| 9349 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 9350 | WindowState imFocus; |
| 9351 | if (idx > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9352 | imFocus = mWindows.get(idx-1); |
| Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 9353 | //Log.i(TAG, "Desired input method target: " + imFocus); |
| 9354 | //Log.i(TAG, "Current focus: " + this.mCurrentFocus); |
| 9355 | //Log.i(TAG, "Last focus: " + this.mLastFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9356 | if (imFocus != null) { |
| Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 9357 | // This may be a starting window, in which case we still want |
| 9358 | // to count it as okay. |
| 9359 | if (imFocus.mAttrs.type == LayoutParams.TYPE_APPLICATION_STARTING |
| 9360 | && imFocus.mAppToken != null) { |
| 9361 | // The client has definitely started, so it really should |
| 9362 | // have a window in this app token. Let's look for it. |
| 9363 | for (int i=0; i<imFocus.mAppToken.windows.size(); i++) { |
| 9364 | WindowState w = imFocus.mAppToken.windows.get(i); |
| 9365 | if (w != imFocus) { |
| 9366 | //Log.i(TAG, "Switching to real app window: " + w); |
| 9367 | imFocus = w; |
| 9368 | break; |
| 9369 | } |
| 9370 | } |
| 9371 | } |
| 9372 | //Log.i(TAG, "IM target client: " + imFocus.mSession.mClient); |
| 9373 | //if (imFocus.mSession.mClient != null) { |
| 9374 | // Log.i(TAG, "IM target client binder: " + imFocus.mSession.mClient.asBinder()); |
| 9375 | // Log.i(TAG, "Requesting client binder: " + client.asBinder()); |
| 9376 | //} |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9377 | if (imFocus.mSession.mClient != null && |
| 9378 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 9379 | return true; |
| 9380 | } |
| Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 9381 | |
| 9382 | // Okay, how about this... what is the current focus? |
| 9383 | // It seems in some cases we may not have moved the IM |
| 9384 | // target window, such as when it was in a pop-up window, |
| 9385 | // so let's also look at the current focus. (An example: |
| 9386 | // go to Gmail, start searching so the keyboard goes up, |
| 9387 | // press home. Sometimes the IME won't go down.) |
| 9388 | // Would be nice to fix this more correctly, but it's |
| 9389 | // way at the end of a release, and this should be good enough. |
| 9390 | if (mCurrentFocus != null && mCurrentFocus.mSession.mClient != null && |
| 9391 | mCurrentFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 9392 | return true; |
| 9393 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9394 | } |
| 9395 | } |
| 9396 | } |
| 9397 | return false; |
| 9398 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9399 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9400 | // ------------------------------------------------------------- |
| 9401 | // Internals |
| 9402 | // ------------------------------------------------------------- |
| 9403 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9404 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 9405 | boolean throwOnError) { |
| 9406 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9407 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9408 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9409 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 9410 | boolean throwOnError) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9411 | WindowState win = mWindowMap.get(client); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9412 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9413 | TAG, "Looking up client " + client + ": " + win); |
| 9414 | if (win == null) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9415 | RuntimeException ex = new IllegalArgumentException( |
| 9416 | "Requested window " + client + " does not exist"); |
| 9417 | if (throwOnError) { |
| 9418 | throw ex; |
| 9419 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9420 | Slog.w(TAG, "Failed looking up window", ex); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9421 | return null; |
| 9422 | } |
| 9423 | if (session != null && win.mSession != session) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9424 | RuntimeException ex = new IllegalArgumentException( |
| 9425 | "Requested window " + client + " is in session " + |
| 9426 | win.mSession + ", not " + session); |
| 9427 | if (throwOnError) { |
| 9428 | throw ex; |
| 9429 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9430 | Slog.w(TAG, "Failed looking up window", ex); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9431 | return null; |
| 9432 | } |
| 9433 | |
| 9434 | return win; |
| 9435 | } |
| 9436 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9437 | final void rebuildAppWindowListLocked() { |
| 9438 | int NW = mWindows.size(); |
| 9439 | int i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9440 | int lastWallpaper = -1; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9441 | int numRemoved = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9442 | |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9443 | if (mRebuildTmp.length < NW) { |
| 9444 | mRebuildTmp = new WindowState[NW+10]; |
| 9445 | } |
| 9446 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9447 | // First remove all existing app windows. |
| 9448 | i=0; |
| 9449 | while (i < NW) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9450 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9451 | if (w.mAppToken != null) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9452 | WindowState win = mWindows.remove(i); |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9453 | win.mRebuilding = true; |
| 9454 | mRebuildTmp[numRemoved] = win; |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 9455 | mWindowsChanged = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9456 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9457 | "Rebuild removing window: " + win); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9458 | NW--; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9459 | numRemoved++; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9460 | continue; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9461 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 9462 | && lastWallpaper == i-1) { |
| 9463 | lastWallpaper = i; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9464 | } |
| 9465 | i++; |
| 9466 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9467 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9468 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 9469 | // so skip them before adding app tokens. |
| 9470 | lastWallpaper++; |
| 9471 | i = lastWallpaper; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9472 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9473 | // First add all of the exiting app tokens... these are no longer |
| 9474 | // in the main app list, but still have windows shown. We put them |
| 9475 | // in the back because now that the animation is over we no longer |
| 9476 | // will care about them. |
| 9477 | int NT = mExitingAppTokens.size(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9478 | for (int j=0; j<NT; j++) { |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9479 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 9480 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9481 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9482 | // And add in the still active app tokens in Z order. |
| 9483 | NT = mAppTokens.size(); |
| 9484 | for (int j=0; j<NT; j++) { |
| 9485 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9486 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9487 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9488 | i -= lastWallpaper; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9489 | if (i != numRemoved) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9490 | Slog.w(TAG, "Rebuild removed " + numRemoved |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9491 | + " windows but added " + i); |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9492 | for (i=0; i<numRemoved; i++) { |
| 9493 | WindowState ws = mRebuildTmp[i]; |
| 9494 | if (ws.mRebuilding) { |
| 9495 | StringWriter sw = new StringWriter(); |
| 9496 | PrintWriter pw = new PrintWriter(sw); |
| 9497 | ws.dump(pw, ""); |
| 9498 | pw.flush(); |
| 9499 | Slog.w(TAG, "This window was lost: " + ws); |
| 9500 | Slog.w(TAG, sw.toString()); |
| 9501 | } |
| 9502 | } |
| 9503 | Slog.w(TAG, "Current app token list:"); |
| 9504 | dumpAppTokensLocked(); |
| 9505 | Slog.w(TAG, "Final window list:"); |
| 9506 | dumpWindowsLocked(); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9507 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9508 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9509 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9510 | private final void assignLayersLocked() { |
| 9511 | int N = mWindows.size(); |
| 9512 | int curBaseLayer = 0; |
| 9513 | int curLayer = 0; |
| 9514 | int i; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9515 | |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9516 | if (DEBUG_LAYERS) { |
| 9517 | RuntimeException here = new RuntimeException("here"); |
| 9518 | here.fillInStackTrace(); |
| 9519 | Log.v(TAG, "Assigning layers", here); |
| 9520 | } |
| 9521 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9522 | for (i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9523 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9524 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 9525 | || (i > 0 && w.mIsWallpaper)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9526 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 9527 | w.mLayer = curLayer; |
| 9528 | } else { |
| 9529 | curBaseLayer = curLayer = w.mBaseLayer; |
| 9530 | w.mLayer = curLayer; |
| 9531 | } |
| 9532 | if (w.mTargetAppToken != null) { |
| 9533 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 9534 | } else if (w.mAppToken != null) { |
| 9535 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 9536 | } else { |
| 9537 | w.mAnimLayer = w.mLayer; |
| 9538 | } |
| 9539 | if (w.mIsImWindow) { |
| 9540 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 9541 | } else if (w.mIsWallpaper) { |
| 9542 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9543 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9544 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9545 | + w.mAnimLayer); |
| 9546 | //System.out.println( |
| 9547 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 9548 | } |
| 9549 | } |
| 9550 | |
| 9551 | private boolean mInLayout = false; |
| 9552 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 9553 | if (mInLayout) { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 9554 | if (DEBUG) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9555 | throw new RuntimeException("Recursive call!"); |
| 9556 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9557 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9558 | return; |
| 9559 | } |
| 9560 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9561 | if (mWaitingForConfig) { |
| 9562 | // Our configuration has changed (most likely rotation), but we |
| 9563 | // don't yet have the complete configuration to report to |
| 9564 | // applications. Don't do any window layout until we have it. |
| 9565 | return; |
| 9566 | } |
| 9567 | |
| Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9568 | if (mDisplay == null) { |
| 9569 | // Not yet initialized, nothing to do. |
| 9570 | return; |
| 9571 | } |
| 9572 | |
| Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 9573 | mInLayout = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9574 | boolean recoveringMemory = false; |
| Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 9575 | |
| 9576 | try { |
| 9577 | if (mForceRemoves != null) { |
| 9578 | recoveringMemory = true; |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9579 | // 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] | 9580 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 9581 | WindowState ws = mForceRemoves.get(i); |
| 9582 | Slog.i(TAG, "Force removing: " + ws); |
| 9583 | removeWindowInnerLocked(ws.mSession, ws); |
| 9584 | } |
| 9585 | mForceRemoves = null; |
| 9586 | Slog.w(TAG, "Due to memory failure, waiting a bit for next layout"); |
| 9587 | Object tmp = new Object(); |
| 9588 | synchronized (tmp) { |
| 9589 | try { |
| 9590 | tmp.wait(250); |
| 9591 | } catch (InterruptedException e) { |
| 9592 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9593 | } |
| 9594 | } |
| Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 9595 | } catch (RuntimeException e) { |
| 9596 | 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] | 9597 | } |
| Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 9598 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9599 | try { |
| 9600 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9601 | |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9602 | int N = mPendingRemove.size(); |
| 9603 | if (N > 0) { |
| 9604 | if (mPendingRemoveTmp.length < N) { |
| 9605 | mPendingRemoveTmp = new WindowState[N+10]; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9606 | } |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9607 | mPendingRemove.toArray(mPendingRemoveTmp); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9608 | mPendingRemove.clear(); |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9609 | for (int i=0; i<N; i++) { |
| 9610 | WindowState w = mPendingRemoveTmp[i]; |
| 9611 | removeWindowInnerLocked(w.mSession, w); |
| 9612 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9613 | |
| 9614 | mInLayout = false; |
| 9615 | assignLayersLocked(); |
| 9616 | mLayoutNeeded = true; |
| 9617 | performLayoutAndPlaceSurfacesLocked(); |
| 9618 | |
| 9619 | } else { |
| 9620 | mInLayout = false; |
| 9621 | if (mLayoutNeeded) { |
| 9622 | requestAnimationLocked(0); |
| 9623 | } |
| 9624 | } |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 9625 | if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) { |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 9626 | mH.removeMessages(H.REPORT_WINDOWS_CHANGE); |
| 9627 | mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE)); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 9628 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9629 | } catch (RuntimeException e) { |
| 9630 | mInLayout = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9631 | 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] | 9632 | } |
| 9633 | } |
| 9634 | |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9635 | private final int performLayoutLockedInner(boolean initial, boolean updateInputWindows) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9636 | if (!mLayoutNeeded) { |
| 9637 | return 0; |
| 9638 | } |
| 9639 | |
| 9640 | mLayoutNeeded = false; |
| 9641 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9642 | final int dw = mDisplay.getWidth(); |
| 9643 | final int dh = mDisplay.getHeight(); |
| 9644 | |
| 9645 | final int N = mWindows.size(); |
| 9646 | int i; |
| 9647 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9648 | if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed=" |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 9649 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 9650 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9651 | mPolicy.beginLayoutLw(dw, dh); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9652 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9653 | int seq = mLayoutSeq+1; |
| 9654 | if (seq < 0) seq = 0; |
| 9655 | mLayoutSeq = seq; |
| 9656 | |
| 9657 | // First perform layout of any root windows (not attached |
| 9658 | // to another window). |
| 9659 | int topAttached = -1; |
| 9660 | for (i = N-1; i >= 0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9661 | WindowState win = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9662 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9663 | // Don't do layout of a window if it is not visible, or |
| 9664 | // soon won't be visible, to avoid wasting time and funky |
| 9665 | // changes while a window is animating away. |
| 9666 | final AppWindowToken atoken = win.mAppToken; |
| 9667 | final boolean gone = win.mViewVisibility == View.GONE |
| 9668 | || !win.mRelayoutCalled |
| Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 9669 | || (atoken == null && win.mRootToken.hidden) |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9670 | || (atoken != null && atoken.hiddenRequested) |
| 9671 | || win.mAttachedHidden |
| 9672 | || win.mExiting || win.mDestroying; |
| 9673 | |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 9674 | if (DEBUG_LAYOUT && !win.mLayoutAttached) { |
| 9675 | Slog.v(TAG, "First pass " + win |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9676 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 9677 | + " mLayoutAttached=" + win.mLayoutAttached); |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 9678 | if (gone) Slog.v(TAG, " (mViewVisibility=" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9679 | + win.mViewVisibility + " mRelayoutCalled=" |
| 9680 | + win.mRelayoutCalled + " hidden=" |
| 9681 | + win.mRootToken.hidden + " hiddenRequested=" |
| 9682 | + (atoken != null && atoken.hiddenRequested) |
| 9683 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 9684 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9685 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9686 | // If this view is GONE, then skip it -- keep the current |
| 9687 | // frame, and let the caller know so they can ignore it |
| 9688 | // if they want. (We do the normal layout for INVISIBLE |
| 9689 | // windows, since that means "perform layout as normal, |
| 9690 | // just don't display"). |
| 9691 | if (!gone || !win.mHaveFrame) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9692 | if (!win.mLayoutAttached) { |
| Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9693 | if (initial) { |
| Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 9694 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
| Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9695 | win.mContentChanged = false; |
| 9696 | } |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9697 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 9698 | win.mLayoutSeq = seq; |
| 9699 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 9700 | + win.mFrame + " mContainingFrame=" |
| 9701 | + win.mContainingFrame + " mDisplayFrame=" |
| 9702 | + win.mDisplayFrame); |
| 9703 | } else { |
| 9704 | if (topAttached < 0) topAttached = i; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9705 | } |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9706 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9707 | } |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9708 | |
| 9709 | // Now perform layout of attached windows, which usually |
| 9710 | // depend on the position of the window they are attached to. |
| 9711 | // XXX does not deal with windows that are attached to windows |
| 9712 | // that are themselves attached. |
| 9713 | for (i = topAttached; i >= 0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9714 | WindowState win = mWindows.get(i); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9715 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9716 | if (win.mLayoutAttached) { |
| 9717 | if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win |
| 9718 | + " mHaveFrame=" + win.mHaveFrame |
| 9719 | + " mViewVisibility=" + win.mViewVisibility |
| 9720 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 9721 | // If this view is GONE, then skip it -- keep the current |
| 9722 | // frame, and let the caller know so they can ignore it |
| 9723 | // if they want. (We do the normal layout for INVISIBLE |
| 9724 | // windows, since that means "perform layout as normal, |
| 9725 | // just don't display"). |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9726 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 9727 | || !win.mHaveFrame) { |
| Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9728 | if (initial) { |
| Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 9729 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
| Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9730 | win.mContentChanged = false; |
| 9731 | } |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9732 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 9733 | win.mLayoutSeq = seq; |
| 9734 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 9735 | + win.mFrame + " mContainingFrame=" |
| 9736 | + win.mContainingFrame + " mDisplayFrame=" |
| 9737 | + win.mDisplayFrame); |
| 9738 | } |
| 9739 | } |
| 9740 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9741 | |
| 9742 | // Window frames may have changed. Tell the input dispatcher about it. |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9743 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 9744 | if (updateInputWindows) { |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 9745 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9746 | } |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9747 | |
| 9748 | return mPolicy.finishLayoutLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9749 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9750 | |
| Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 9751 | // "Something has changed! Let's make it correct now." |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9752 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 9753 | boolean recoveringMemory) { |
| Joe Onorato | 34bcebc | 2010-07-07 18:05:01 -0400 | [diff] [blame] | 9754 | if (mDisplay == null) { |
| 9755 | Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay"); |
| 9756 | return; |
| 9757 | } |
| 9758 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9759 | final long currentTime = SystemClock.uptimeMillis(); |
| 9760 | final int dw = mDisplay.getWidth(); |
| 9761 | final int dh = mDisplay.getHeight(); |
| 9762 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9763 | int i; |
| 9764 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9765 | if (mFocusMayChange) { |
| 9766 | mFocusMayChange = false; |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9767 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 9768 | false /*updateInputWindows*/); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9769 | } |
| 9770 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9771 | // Initialize state of exiting tokens. |
| 9772 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9773 | mExitingTokens.get(i).hasVisible = false; |
| 9774 | } |
| 9775 | |
| 9776 | // Initialize state of exiting applications. |
| 9777 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9778 | mExitingAppTokens.get(i).hasVisible = false; |
| 9779 | } |
| 9780 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9781 | boolean orientationChangeComplete = true; |
| 9782 | Session holdScreen = null; |
| 9783 | float screenBrightness = -1; |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9784 | float buttonBrightness = -1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9785 | boolean focusDisplayed = false; |
| 9786 | boolean animating = false; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9787 | boolean createWatermark = false; |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 9788 | boolean updateRotation = false; |
| Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 9789 | boolean screenRotationFinished = false; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9790 | |
| 9791 | if (mFxSession == null) { |
| 9792 | mFxSession = new SurfaceSession(); |
| 9793 | createWatermark = true; |
| 9794 | } |
| 9795 | |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 9796 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9797 | |
| 9798 | Surface.openTransaction(); |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9799 | |
| 9800 | if (createWatermark) { |
| 9801 | createWatermark(); |
| 9802 | } |
| 9803 | if (mWatermark != null) { |
| 9804 | mWatermark.positionSurface(dw, dh); |
| 9805 | } |
| Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 9806 | if (mStrictModeFlash != null) { |
| 9807 | mStrictModeFlash.positionSurface(dw, dh); |
| 9808 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9809 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9810 | try { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9811 | boolean wallpaperForceHidingChanged = false; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9812 | int repeats = 0; |
| 9813 | int changes = 0; |
| 9814 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9815 | do { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9816 | repeats++; |
| 9817 | if (repeats > 6) { |
| 9818 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 9819 | mLayoutNeeded = false; |
| 9820 | break; |
| 9821 | } |
| 9822 | |
| 9823 | if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER |
| 9824 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG |
| 9825 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) { |
| 9826 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 9827 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 9828 | assignLayersLocked(); |
| 9829 | mLayoutNeeded = true; |
| 9830 | } |
| 9831 | } |
| 9832 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 9833 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 9834 | if (updateOrientationFromAppTokensLocked(true)) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9835 | mLayoutNeeded = true; |
| 9836 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 9837 | } |
| 9838 | } |
| 9839 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 9840 | mLayoutNeeded = true; |
| 9841 | } |
| 9842 | } |
| 9843 | |
| 9844 | // FIRST LOOP: Perform a layout, if needed. |
| 9845 | if (repeats < 4) { |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9846 | changes = performLayoutLockedInner(repeats == 0, false /*updateInputWindows*/); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9847 | if (changes != 0) { |
| 9848 | continue; |
| 9849 | } |
| 9850 | } else { |
| 9851 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 9852 | changes = 0; |
| 9853 | } |
| 9854 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9855 | final int transactionSequence = ++mTransactionSequence; |
| 9856 | |
| 9857 | // Update animations of all applications, including those |
| 9858 | // associated with exiting/removed apps |
| 9859 | boolean tokensAnimating = false; |
| 9860 | final int NAT = mAppTokens.size(); |
| 9861 | for (i=0; i<NAT; i++) { |
| 9862 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9863 | tokensAnimating = true; |
| 9864 | } |
| 9865 | } |
| 9866 | final int NEAT = mExitingAppTokens.size(); |
| 9867 | for (i=0; i<NEAT; i++) { |
| 9868 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9869 | tokensAnimating = true; |
| 9870 | } |
| 9871 | } |
| 9872 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9873 | // SECOND LOOP: Execute animations and update visibility of windows. |
| 9874 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9875 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq=" |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9876 | + transactionSequence + " tokensAnimating=" |
| 9877 | + tokensAnimating); |
| 9878 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9879 | animating = tokensAnimating; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9880 | |
| Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 9881 | if (mScreenRotationAnimation != null) { |
| 9882 | if (mScreenRotationAnimation.isAnimating()) { |
| 9883 | if (mScreenRotationAnimation.stepAnimation(currentTime)) { |
| 9884 | animating = true; |
| 9885 | } else { |
| Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 9886 | screenRotationFinished = true; |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 9887 | updateRotation = true; |
| Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 9888 | } |
| 9889 | } |
| 9890 | } |
| 9891 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9892 | boolean tokenMayBeDrawn = false; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9893 | boolean wallpaperMayChange = false; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9894 | boolean forceHiding = false; |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9895 | WindowState windowDetachedWallpaper = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9896 | |
| 9897 | mPolicy.beginAnimationLw(dw, dh); |
| 9898 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9899 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9900 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9901 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9902 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9903 | |
| 9904 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9905 | |
| 9906 | if (w.mSurface != null) { |
| Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9907 | // Take care of the window being ready to display. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9908 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 9909 | if ((w.mAttrs.flags |
| 9910 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9911 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9912 | "First draw done in potential wallpaper target " + w); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9913 | wallpaperMayChange = true; |
| 9914 | } |
| 9915 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9916 | |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9917 | final boolean wasAnimating = w.mAnimating; |
| Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9918 | |
| 9919 | int animDw = dw; |
| 9920 | int animDh = dh; |
| 9921 | |
| 9922 | // If the window has moved due to its containing |
| 9923 | // content frame changing, then we'd like to animate |
| 9924 | // it. The checks here are ordered by what is least |
| Joe Onorato | 3fe7f2f | 2010-11-20 13:48:58 -0800 | [diff] [blame] | 9925 | // likely to be true first. |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 9926 | if (w.shouldAnimateMove()) { |
| Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9927 | // Frame has moved, containing content frame |
| 9928 | // has also moved, and we're not currently animating... |
| 9929 | // let's do something. |
| 9930 | Animation a = AnimationUtils.loadAnimation(mContext, |
| 9931 | com.android.internal.R.anim.window_move_from_decor); |
| 9932 | w.setAnimation(a); |
| 9933 | animDw = w.mLastFrame.left - w.mFrame.left; |
| 9934 | animDh = w.mLastFrame.top - w.mFrame.top; |
| 9935 | } |
| 9936 | |
| 9937 | // Execute animation. |
| 9938 | final boolean nowAnimating = w.stepAnimationLocked(currentTime, |
| 9939 | animDw, animDh); |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9940 | |
| 9941 | // If this window is animating, make a note that we have |
| 9942 | // an animating window and take care of a request to run |
| 9943 | // a detached wallpaper animation. |
| 9944 | if (nowAnimating) { |
| 9945 | if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) { |
| 9946 | windowDetachedWallpaper = w; |
| 9947 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9948 | animating = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9949 | } |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9950 | |
| 9951 | // If this window's app token is running a detached wallpaper |
| 9952 | // animation, make a note so we can ensure the wallpaper is |
| 9953 | // displayed behind it. |
| 9954 | if (w.mAppToken != null && w.mAppToken.animation != null |
| 9955 | && w.mAppToken.animation.getDetachWallpaper()) { |
| 9956 | windowDetachedWallpaper = w; |
| 9957 | } |
| 9958 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9959 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 9960 | wallpaperMayChange = true; |
| 9961 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9962 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9963 | if (mPolicy.doesForceHide(w, attrs)) { |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9964 | if (!wasAnimating && nowAnimating) { |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9965 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9966 | "Animation started that could impact force hide: " |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9967 | + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9968 | wallpaperForceHidingChanged = true; |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9969 | mFocusMayChange = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9970 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 9971 | forceHiding = true; |
| 9972 | } |
| 9973 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9974 | boolean changed; |
| 9975 | if (forceHiding) { |
| 9976 | changed = w.hideLw(false, false); |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9977 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9978 | "Now policy hidden: " + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9979 | } else { |
| 9980 | changed = w.showLw(false, false); |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9981 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9982 | "Now policy shown: " + w); |
| 9983 | if (changed) { |
| 9984 | if (wallpaperForceHidingChanged |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9985 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9986 | // Assume we will need to animate. If |
| 9987 | // we don't (because the wallpaper will |
| 9988 | // stay with the lock screen), then we will |
| 9989 | // clean up later. |
| 9990 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 9991 | if (a != null) { |
| 9992 | w.setAnimation(a); |
| 9993 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9994 | } |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9995 | if (mCurrentFocus == null || |
| 9996 | mCurrentFocus.mLayer < w.mLayer) { |
| 9997 | // We are showing on to of the current |
| 9998 | // focus, so re-evaluate focus to make |
| 9999 | // sure it is correct. |
| 10000 | mFocusMayChange = true; |
| 10001 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10002 | } |
| 10003 | } |
| 10004 | if (changed && (attrs.flags |
| 10005 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 10006 | wallpaperMayChange = true; |
| 10007 | } |
| 10008 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10009 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10010 | mPolicy.animatingWindowLw(w, attrs); |
| 10011 | } |
| 10012 | |
| 10013 | final AppWindowToken atoken = w.mAppToken; |
| 10014 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 10015 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 10016 | atoken.lastTransactionSequence = transactionSequence; |
| 10017 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 10018 | atoken.startingDisplayed = false; |
| 10019 | } |
| 10020 | if ((w.isOnScreen() || w.mAttrs.type |
| 10021 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 10022 | && !w.mExiting && !w.mDestroying) { |
| 10023 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10024 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 10025 | + w.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10026 | + ", isAnimating=" + w.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 10027 | if (!w.isDrawnLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10028 | Slog.v(TAG, "Not displayed: s=" + w.mSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10029 | + " pv=" + w.mPolicyVisibility |
| 10030 | + " dp=" + w.mDrawPending |
| 10031 | + " cdp=" + w.mCommitDrawPending |
| 10032 | + " ah=" + w.mAttachedHidden |
| 10033 | + " th=" + atoken.hiddenRequested |
| 10034 | + " a=" + w.mAnimating); |
| 10035 | } |
| 10036 | } |
| 10037 | if (w != atoken.startingWindow) { |
| 10038 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 10039 | atoken.numInterestingWindows++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 10040 | if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10041 | atoken.numDrawnWindows++; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10042 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10043 | "tokenMayBeDrawn: " + atoken |
| 10044 | + " freezingScreen=" + atoken.freezingScreen |
| 10045 | + " mAppFreezing=" + w.mAppFreezing); |
| 10046 | tokenMayBeDrawn = true; |
| 10047 | } |
| 10048 | } |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 10049 | } else if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10050 | atoken.startingDisplayed = true; |
| 10051 | } |
| 10052 | } |
| 10053 | } else if (w.mReadyToShow) { |
| 10054 | w.performShowLocked(); |
| 10055 | } |
| 10056 | } |
| 10057 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10058 | changes |= mPolicy.finishAnimationLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10059 | |
| 10060 | if (tokenMayBeDrawn) { |
| 10061 | // See if any windows have been drawn, so they (and others |
| 10062 | // associated with them) can now be shown. |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 10063 | final int NT = mAppTokens.size(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10064 | for (i=0; i<NT; i++) { |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 10065 | AppWindowToken wtoken = mAppTokens.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10066 | if (wtoken.freezingScreen) { |
| 10067 | int numInteresting = wtoken.numInterestingWindows; |
| 10068 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10069 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10070 | "allDrawn: " + wtoken |
| 10071 | + " interesting=" + numInteresting |
| 10072 | + " drawn=" + wtoken.numDrawnWindows); |
| 10073 | wtoken.showAllWindowsLocked(); |
| 10074 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 10075 | orientationChangeComplete = true; |
| 10076 | } |
| 10077 | } else if (!wtoken.allDrawn) { |
| 10078 | int numInteresting = wtoken.numInterestingWindows; |
| 10079 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10080 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10081 | "allDrawn: " + wtoken |
| 10082 | + " interesting=" + numInteresting |
| 10083 | + " drawn=" + wtoken.numDrawnWindows); |
| 10084 | wtoken.allDrawn = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10085 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10086 | |
| 10087 | // We can now show all of the drawn windows! |
| 10088 | if (!mOpeningApps.contains(wtoken)) { |
| 10089 | wtoken.showAllWindowsLocked(); |
| 10090 | } |
| 10091 | } |
| 10092 | } |
| 10093 | } |
| 10094 | } |
| 10095 | |
| 10096 | // If we are ready to perform an app transition, check through |
| 10097 | // all of the app tokens to be shown and see if they are ready |
| 10098 | // to go. |
| 10099 | if (mAppTransitionReady) { |
| 10100 | int NN = mOpeningApps.size(); |
| 10101 | boolean goodToGo = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10102 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10103 | "Checking " + NN + " opening apps (frozen=" |
| 10104 | + mDisplayFrozen + " timeout=" |
| 10105 | + mAppTransitionTimeout + ")..."); |
| 10106 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 10107 | // If the display isn't frozen, wait to do anything until |
| 10108 | // all of the apps are ready. Otherwise just go because |
| 10109 | // we'll unfreeze the display when everyone is ready. |
| 10110 | for (i=0; i<NN && goodToGo; i++) { |
| 10111 | AppWindowToken wtoken = mOpeningApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10112 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10113 | "Check opening app" + wtoken + ": allDrawn=" |
| 10114 | + wtoken.allDrawn + " startingDisplayed=" |
| 10115 | + wtoken.startingDisplayed); |
| 10116 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 10117 | && !wtoken.startingMoved) { |
| 10118 | goodToGo = false; |
| 10119 | } |
| 10120 | } |
| 10121 | } |
| 10122 | if (goodToGo) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10123 | 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] | 10124 | int transit = mNextAppTransition; |
| 10125 | if (mSkipAppTransitionAnimation) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 10126 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10127 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 10128 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10129 | mAppTransitionReady = false; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10130 | mAppTransitionRunning = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10131 | mAppTransitionTimeout = false; |
| 10132 | mStartingIconInTransition = false; |
| 10133 | mSkipAppTransitionAnimation = false; |
| 10134 | |
| 10135 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 10136 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10137 | // If there are applications waiting to come to the |
| 10138 | // top of the stack, now is the time to move their windows. |
| 10139 | // (Note that we don't do apps going to the bottom |
| 10140 | // here -- we want to keep their windows in the old |
| 10141 | // Z-order until the animation completes.) |
| 10142 | if (mToTopApps.size() > 0) { |
| 10143 | NN = mAppTokens.size(); |
| 10144 | for (i=0; i<NN; i++) { |
| 10145 | AppWindowToken wtoken = mAppTokens.get(i); |
| 10146 | if (wtoken.sendingToTop) { |
| 10147 | wtoken.sendingToTop = false; |
| 10148 | moveAppWindowsLocked(wtoken, NN, false); |
| 10149 | } |
| 10150 | } |
| 10151 | mToTopApps.clear(); |
| 10152 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10153 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10154 | WindowState oldWallpaper = mWallpaperTarget; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10155 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 10156 | adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10157 | wallpaperMayChange = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10158 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10159 | // The top-most window will supply the layout params, |
| 10160 | // and we will determine it below. |
| 10161 | LayoutParams animLp = null; |
| 10162 | int bestAnimLayer = -1; |
| Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 10163 | boolean fullscreenAnim = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10164 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10165 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 10166 | "New wallpaper target=" + mWallpaperTarget |
| 10167 | + ", lower target=" + mLowerWallpaperTarget |
| 10168 | + ", upper target=" + mUpperWallpaperTarget); |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10169 | int foundWallpapers = 0; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10170 | // Do a first pass through the tokens for two |
| 10171 | // things: |
| 10172 | // (1) Determine if both the closing and opening |
| 10173 | // app token sets are wallpaper targets, in which |
| 10174 | // case special animations are needed |
| 10175 | // (since the wallpaper needs to stay static |
| 10176 | // behind them). |
| 10177 | // (2) Find the layout params of the top-most |
| 10178 | // application window in the tokens, which is |
| 10179 | // what will control the animation theme. |
| 10180 | final int NC = mClosingApps.size(); |
| 10181 | NN = NC + mOpeningApps.size(); |
| 10182 | for (i=0; i<NN; i++) { |
| 10183 | AppWindowToken wtoken; |
| 10184 | int mode; |
| 10185 | if (i < NC) { |
| 10186 | wtoken = mClosingApps.get(i); |
| 10187 | mode = 1; |
| 10188 | } else { |
| 10189 | wtoken = mOpeningApps.get(i-NC); |
| 10190 | mode = 2; |
| 10191 | } |
| 10192 | if (mLowerWallpaperTarget != null) { |
| 10193 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 10194 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 10195 | foundWallpapers |= mode; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 10196 | } |
| 10197 | } |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10198 | if (wtoken.appFullscreen) { |
| 10199 | WindowState ws = wtoken.findMainWindow(); |
| 10200 | if (ws != null) { |
| 10201 | // If this is a compatibility mode |
| 10202 | // window, we will always use its anim. |
| 10203 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 10204 | animLp = ws.mAttrs; |
| 10205 | bestAnimLayer = Integer.MAX_VALUE; |
| Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 10206 | } else if (!fullscreenAnim || ws.mLayer > bestAnimLayer) { |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10207 | animLp = ws.mAttrs; |
| Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 10208 | bestAnimLayer = ws.mLayer; |
| 10209 | } |
| 10210 | fullscreenAnim = true; |
| 10211 | } |
| 10212 | } else if (!fullscreenAnim) { |
| 10213 | WindowState ws = wtoken.findMainWindow(); |
| 10214 | if (ws != null) { |
| 10215 | if (ws.mLayer > bestAnimLayer) { |
| 10216 | animLp = ws.mAttrs; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10217 | bestAnimLayer = ws.mLayer; |
| 10218 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10219 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 10220 | } |
| 10221 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10222 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10223 | if (foundWallpapers == 3) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10224 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10225 | "Wallpaper animation!"); |
| 10226 | switch (transit) { |
| 10227 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 10228 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 10229 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 10230 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 10231 | break; |
| 10232 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 10233 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 10234 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 10235 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 10236 | break; |
| 10237 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10238 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10239 | "New transit: " + transit); |
| 10240 | } else if (oldWallpaper != null) { |
| 10241 | // We are transitioning from an activity with |
| 10242 | // a wallpaper to one without. |
| 10243 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10244 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10245 | "New transit away from wallpaper: " + transit); |
| 10246 | } else if (mWallpaperTarget != null) { |
| 10247 | // We are transitioning from an activity without |
| 10248 | // a wallpaper to now showing the wallpaper |
| 10249 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10250 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10251 | "New transit into wallpaper: " + transit); |
| 10252 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10253 | |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10254 | // If all closing windows are obscured, then there is |
| 10255 | // no need to do an animation. This is the case, for |
| 10256 | // example, when this transition is being done behind |
| 10257 | // the lock screen. |
| 10258 | if (!mPolicy.allowAppAnimationsLw()) { |
| 10259 | animLp = null; |
| 10260 | } |
| 10261 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10262 | NN = mOpeningApps.size(); |
| 10263 | for (i=0; i<NN; i++) { |
| 10264 | AppWindowToken wtoken = mOpeningApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10265 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10266 | "Now opening app" + wtoken); |
| 10267 | wtoken.reportedVisible = false; |
| 10268 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 10269 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10270 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10271 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10272 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10273 | wtoken.showAllWindowsLocked(); |
| 10274 | } |
| 10275 | NN = mClosingApps.size(); |
| 10276 | for (i=0; i<NN; i++) { |
| 10277 | AppWindowToken wtoken = mClosingApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10278 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10279 | "Now closing app" + wtoken); |
| 10280 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 10281 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10282 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10283 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10284 | wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10285 | // Force the allDrawn flag, because we want to start |
| 10286 | // this guy's animations regardless of whether it's |
| 10287 | // gotten drawn. |
| 10288 | wtoken.allDrawn = true; |
| 10289 | } |
| 10290 | |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 10291 | mNextAppTransitionPackage = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10292 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10293 | mOpeningApps.clear(); |
| 10294 | mClosingApps.clear(); |
| 10295 | |
| 10296 | // This has changed the visibility of windows, so perform |
| 10297 | // a new layout to get them all up-to-date. |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 10298 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT |
| 10299 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10300 | mLayoutNeeded = true; |
| Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 10301 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 10302 | assignLayersLocked(); |
| 10303 | } |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 10304 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, |
| 10305 | false /*updateInputWindows*/); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10306 | mFocusMayChange = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10307 | } |
| 10308 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10309 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10310 | int adjResult = 0; |
| 10311 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10312 | if (!animating && mAppTransitionRunning) { |
| 10313 | // We have finished the animation of an app transition. To do |
| 10314 | // this, we have delayed a lot of operations like showing and |
| 10315 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10316 | // reflects the correct Z-order, but the window list may now |
| 10317 | // be out of sync with it. So here we will just rebuild the |
| 10318 | // entire app window list. Fun! |
| 10319 | mAppTransitionRunning = false; |
| 10320 | // Clear information about apps that were moving. |
| 10321 | mToBottomApps.clear(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10322 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10323 | rebuildAppWindowListLocked(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10324 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10325 | adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10326 | moveInputMethodWindowsIfNeededLocked(false); |
| 10327 | wallpaperMayChange = true; |
| Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 10328 | // Since the window list has been rebuilt, focus might |
| 10329 | // have to be recomputed since the actual order of windows |
| 10330 | // might have changed again. |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10331 | mFocusMayChange = true; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10332 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10333 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10334 | if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10335 | // At this point, there was a window with a wallpaper that |
| 10336 | // was force hiding other windows behind it, but now it |
| 10337 | // is going away. This may be simple -- just animate |
| 10338 | // away the wallpaper and its window -- or it may be |
| 10339 | // hard -- the wallpaper now needs to be shown behind |
| 10340 | // something that was hidden. |
| 10341 | WindowState oldWallpaper = mWallpaperTarget; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10342 | if (mLowerWallpaperTarget != null |
| 10343 | && mLowerWallpaperTarget.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10344 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10345 | "wallpaperForceHiding changed with lower=" |
| 10346 | + mLowerWallpaperTarget); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10347 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10348 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 10349 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 10350 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 10351 | // The lower target has become hidden before we |
| 10352 | // actually started the animation... let's completely |
| 10353 | // re-evaluate everything. |
| 10354 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10355 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10356 | } |
| 10357 | } |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10358 | adjResult |= adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10359 | wallpaperMayChange = false; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10360 | wallpaperForceHidingChanged = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10361 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10362 | + " NEW: " + mWallpaperTarget |
| 10363 | + " LOWER: " + mLowerWallpaperTarget); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10364 | if (mLowerWallpaperTarget == null) { |
| 10365 | // Whoops, we don't need a special wallpaper animation. |
| 10366 | // Clear them out. |
| 10367 | forceHiding = false; |
| 10368 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10369 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10370 | if (w.mSurface != null) { |
| 10371 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 10372 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10373 | if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10374 | forceHiding = true; |
| 10375 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 10376 | if (!w.mAnimating) { |
| 10377 | // We set the animation above so it |
| 10378 | // is not yet running. |
| 10379 | w.clearAnimation(); |
| 10380 | } |
| 10381 | } |
| 10382 | } |
| 10383 | } |
| 10384 | } |
| 10385 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10386 | |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 10387 | if (mWindowDetachedWallpaper != windowDetachedWallpaper) { |
| 10388 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 10389 | "Detached wallpaper changed from " + mWindowDetachedWallpaper |
| 10390 | + windowDetachedWallpaper); |
| 10391 | mWindowDetachedWallpaper = windowDetachedWallpaper; |
| 10392 | wallpaperMayChange = true; |
| 10393 | } |
| 10394 | |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10395 | if (wallpaperMayChange) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10396 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10397 | "Wallpaper may change! Adjusting"); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10398 | adjResult |= adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10399 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10400 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10401 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10402 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10403 | "Wallpaper layer changed: assigning layers + relayout"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10404 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10405 | assignLayersLocked(); |
| 10406 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10407 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10408 | "Wallpaper visibility changed: relayout"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10409 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10410 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10411 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10412 | if (mFocusMayChange) { |
| 10413 | mFocusMayChange = false; |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 10414 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, |
| 10415 | false /*updateInputWindows*/)) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10416 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10417 | adjResult = 0; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10418 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10419 | } |
| 10420 | |
| 10421 | if (mLayoutNeeded) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10422 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10423 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10424 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10425 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x" |
| 10426 | + Integer.toHexString(changes)); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10427 | } while (changes != 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10428 | |
| 10429 | // THIRD LOOP: Update the surfaces of all windows. |
| 10430 | |
| 10431 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 10432 | |
| 10433 | boolean obscured = false; |
| 10434 | boolean blurring = false; |
| 10435 | boolean dimming = false; |
| 10436 | boolean covered = false; |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10437 | boolean syswin = false; |
| Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 10438 | boolean backgroundFillerWasShown = mBackgroundFillerTarget != null; |
| 10439 | mBackgroundFillerTarget = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10440 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 10441 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10442 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10443 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10444 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10445 | |
| 10446 | boolean displayed = false; |
| 10447 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 10448 | final int attrFlags = attrs.flags; |
| 10449 | |
| 10450 | if (w.mSurface != null) { |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10451 | // XXX NOTE: The logic here could be improved. We have |
| 10452 | // the decision about whether to resize a window separated |
| 10453 | // from whether to hide the surface. This can cause us to |
| 10454 | // resize a surface even if we are going to hide it. You |
| 10455 | // can see this by (1) holding device in landscape mode on |
| 10456 | // home screen; (2) tapping browser icon (device will rotate |
| 10457 | // to landscape; (3) tap home. The wallpaper will be resized |
| 10458 | // in step 2 but then immediately hidden, causing us to |
| 10459 | // have to resize and then redraw it again in step 3. It |
| 10460 | // would be nice to figure out how to avoid this, but it is |
| 10461 | // difficult because we do need to resize surfaces in some |
| 10462 | // cases while they are hidden such as when first showing a |
| 10463 | // window. |
| 10464 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10465 | w.computeShownFrameLocked(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10466 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10467 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 10468 | + ": new=" + w.mShownFrame + ", old=" |
| 10469 | + w.mLastShownFrame); |
| 10470 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10471 | int width, height; |
| 10472 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10473 | // for a scaled surface, we just want to use |
| 10474 | // the requested size. |
| 10475 | width = w.mRequestedWidth; |
| 10476 | height = w.mRequestedHeight; |
| 10477 | w.mLastRequestedWidth = width; |
| 10478 | w.mLastRequestedHeight = height; |
| 10479 | w.mLastShownFrame.set(w.mShownFrame); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10480 | } else { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10481 | width = w.mShownFrame.width(); |
| 10482 | height = w.mShownFrame.height(); |
| 10483 | w.mLastShownFrame.set(w.mShownFrame); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10484 | } |
| 10485 | |
| Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 10486 | if (w.mSurface != null) { |
| 10487 | if (w.mSurfaceX != w.mShownFrame.left |
| 10488 | || w.mSurfaceY != w.mShownFrame.top) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10489 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10490 | if (SHOW_TRANSACTIONS) logSurface(w, |
| Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 10491 | "POS " + w.mShownFrame.left |
| 10492 | + ", " + w.mShownFrame.top, null); |
| 10493 | w.mSurfaceX = w.mShownFrame.left; |
| 10494 | w.mSurfaceY = w.mShownFrame.top; |
| 10495 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 10496 | } catch (RuntimeException e) { |
| 10497 | Slog.w(TAG, "Error positioning surface of " + w |
| 10498 | + " pos=(" + w.mShownFrame.left |
| 10499 | + "," + w.mShownFrame.top + ")", e); |
| 10500 | if (!recoveringMemory) { |
| 10501 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 10502 | } |
| 10503 | } |
| 10504 | } |
| 10505 | |
| 10506 | if (width < 1) { |
| 10507 | width = 1; |
| 10508 | } |
| 10509 | if (height < 1) { |
| 10510 | height = 1; |
| 10511 | } |
| 10512 | |
| 10513 | if (w.mSurfaceW != width || w.mSurfaceH != height) { |
| 10514 | try { |
| 10515 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10516 | "SIZE " + w.mShownFrame.width() + "x" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10517 | + w.mShownFrame.height(), null); |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10518 | w.mSurfaceResized = true; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10519 | w.mSurfaceW = width; |
| 10520 | w.mSurfaceH = height; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10521 | w.mSurface.setSize(width, height); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10522 | } catch (RuntimeException e) { |
| 10523 | // If something goes wrong with the surface (such |
| 10524 | // as running out of memory), don't take down the |
| 10525 | // entire system. |
| Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 10526 | Slog.e(TAG, "Error resizing surface of " + w |
| 10527 | + " size=(" + width + "x" + height + ")", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10528 | if (!recoveringMemory) { |
| 10529 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 10530 | } |
| 10531 | } |
| 10532 | } |
| 10533 | } |
| Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 10534 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10535 | if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10536 | w.mContentInsetsChanged = |
| 10537 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 10538 | w.mVisibleInsetsChanged = |
| 10539 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10540 | boolean configChanged = |
| 10541 | w.mConfiguration != mCurConfiguration |
| 10542 | && (w.mConfiguration == null |
| 10543 | || mCurConfiguration.diff(w.mConfiguration) != 0); |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10544 | if (DEBUG_CONFIGURATION && configChanged) { |
| 10545 | Slog.v(TAG, "Win " + w + " config changed: " |
| 10546 | + mCurConfiguration); |
| 10547 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10548 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10549 | + ": configChanged=" + configChanged |
| 10550 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
| Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 10551 | boolean frameChanged = !w.mLastFrame.equals(w.mFrame); |
| 10552 | if (frameChanged |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10553 | || w.mContentInsetsChanged |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10554 | || w.mVisibleInsetsChanged |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10555 | || w.mSurfaceResized |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10556 | || configChanged) { |
| Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 10557 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) { |
| 10558 | Slog.v(TAG, "Resize reasons: " |
| 10559 | + "frameChanged=" + frameChanged |
| 10560 | + " contentInsetsChanged=" + w.mContentInsetsChanged |
| 10561 | + " visibleInsetsChanged=" + w.mVisibleInsetsChanged |
| 10562 | + " surfaceResized=" + w.mSurfaceResized |
| 10563 | + " configChanged=" + configChanged); |
| 10564 | } |
| 10565 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10566 | w.mLastFrame.set(w.mFrame); |
| 10567 | w.mLastContentInsets.set(w.mContentInsets); |
| 10568 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10569 | // If the screen is currently frozen, then keep |
| 10570 | // it frozen until this window draws at its new |
| 10571 | // orientation. |
| 10572 | if (mDisplayFrozen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10573 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10574 | "Resizing while display frozen: " + w); |
| 10575 | w.mOrientationChanging = true; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10576 | if (!mWindowsFreezingScreen) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10577 | mWindowsFreezingScreen = true; |
| 10578 | // XXX should probably keep timeout from |
| 10579 | // when we first froze the display. |
| 10580 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10581 | mH.sendMessageDelayed(mH.obtainMessage( |
| 10582 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 10583 | } |
| 10584 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10585 | // If the orientation is changing, then we need to |
| 10586 | // hold off on unfreezing the display until this |
| 10587 | // window has been redrawn; to do that, we need |
| 10588 | // to go through the process of getting informed |
| 10589 | // by the application when it has finished drawing. |
| 10590 | if (w.mOrientationChanging) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10591 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10592 | "Orientation start waiting for draw in " |
| 10593 | + w + ", surface " + w.mSurface); |
| 10594 | w.mDrawPending = true; |
| 10595 | w.mCommitDrawPending = false; |
| 10596 | w.mReadyToShow = false; |
| 10597 | if (w.mAppToken != null) { |
| 10598 | w.mAppToken.allDrawn = false; |
| 10599 | } |
| 10600 | } |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10601 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10602 | "Resizing window " + w + " to " + w.mFrame); |
| 10603 | mResizingWindows.add(w); |
| 10604 | } else if (w.mOrientationChanging) { |
| 10605 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10606 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10607 | "Orientation not waiting for draw in " |
| 10608 | + w + ", surface " + w.mSurface); |
| 10609 | w.mOrientationChanging = false; |
| 10610 | } |
| 10611 | } |
| 10612 | } |
| 10613 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10614 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10615 | if (!w.mLastHidden) { |
| 10616 | //dump(); |
| 10617 | w.mLastHidden = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10618 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10619 | "HIDE (performLayout)", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10620 | if (w.mSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10621 | w.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10622 | try { |
| 10623 | w.mSurface.hide(); |
| 10624 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10625 | Slog.w(TAG, "Exception hiding surface in " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10626 | } |
| 10627 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10628 | } |
| 10629 | // If we are waiting for this window to handle an |
| 10630 | // orientation change, well, it is hidden, so |
| 10631 | // doesn't really matter. Note that this does |
| 10632 | // introduce a potential glitch if the window |
| 10633 | // becomes unhidden before it has drawn for the |
| 10634 | // new orientation. |
| 10635 | if (w.mOrientationChanging) { |
| 10636 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10637 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10638 | "Orientation change skips hidden " + w); |
| 10639 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10640 | } else if (w.mLastLayer != w.mAnimLayer |
| 10641 | || w.mLastAlpha != w.mShownAlpha |
| 10642 | || w.mLastDsDx != w.mDsDx |
| 10643 | || w.mLastDtDx != w.mDtDx |
| 10644 | || w.mLastDsDy != w.mDsDy |
| 10645 | || w.mLastDtDy != w.mDtDy |
| 10646 | || w.mLastHScale != w.mHScale |
| 10647 | || w.mLastVScale != w.mVScale |
| 10648 | || w.mLastHidden) { |
| 10649 | displayed = true; |
| 10650 | w.mLastAlpha = w.mShownAlpha; |
| 10651 | w.mLastLayer = w.mAnimLayer; |
| 10652 | w.mLastDsDx = w.mDsDx; |
| 10653 | w.mLastDtDx = w.mDtDx; |
| 10654 | w.mLastDsDy = w.mDsDy; |
| 10655 | w.mLastDtDy = w.mDtDy; |
| 10656 | w.mLastHScale = w.mHScale; |
| 10657 | w.mLastVScale = w.mVScale; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10658 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10659 | "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10660 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 10661 | + "," + (w.mDtDx*w.mVScale) |
| 10662 | + "][" + (w.mDsDy*w.mHScale) |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10663 | + "," + (w.mDtDy*w.mVScale) + "]", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10664 | if (w.mSurface != null) { |
| 10665 | try { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10666 | w.mSurfaceAlpha = w.mShownAlpha; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10667 | w.mSurface.setAlpha(w.mShownAlpha); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10668 | w.mSurfaceLayer = w.mAnimLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10669 | w.mSurface.setLayer(w.mAnimLayer); |
| 10670 | w.mSurface.setMatrix( |
| 10671 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 10672 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 10673 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10674 | Slog.w(TAG, "Error updating surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10675 | if (!recoveringMemory) { |
| 10676 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 10677 | } |
| 10678 | } |
| 10679 | } |
| 10680 | |
| 10681 | if (w.mLastHidden && !w.mDrawPending |
| 10682 | && !w.mCommitDrawPending |
| 10683 | && !w.mReadyToShow) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10684 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10685 | "SHOW (performLayout)", null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10686 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10687 | + " during relayout"); |
| 10688 | if (showSurfaceRobustlyLocked(w)) { |
| 10689 | w.mHasDrawn = true; |
| 10690 | w.mLastHidden = false; |
| 10691 | } else { |
| 10692 | w.mOrientationChanging = false; |
| 10693 | } |
| 10694 | } |
| 10695 | if (w.mSurface != null) { |
| 10696 | w.mToken.hasVisible = true; |
| 10697 | } |
| 10698 | } else { |
| 10699 | displayed = true; |
| 10700 | } |
| 10701 | |
| 10702 | if (displayed) { |
| 10703 | if (!covered) { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 10704 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 10705 | && attrs.height == LayoutParams.MATCH_PARENT) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10706 | covered = true; |
| 10707 | } |
| 10708 | } |
| 10709 | if (w.mOrientationChanging) { |
| 10710 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 10711 | orientationChangeComplete = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10712 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10713 | "Orientation continue waiting for draw in " + w); |
| 10714 | } else { |
| 10715 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10716 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10717 | "Orientation change complete in " + w); |
| 10718 | } |
| 10719 | } |
| 10720 | w.mToken.hasVisible = true; |
| 10721 | } |
| 10722 | } else if (w.mOrientationChanging) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10723 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10724 | "Orientation change skips hidden " + w); |
| 10725 | w.mOrientationChanging = false; |
| 10726 | } |
| 10727 | |
| Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 10728 | if (w.mContentChanged) { |
| 10729 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing"); |
| 10730 | w.mContentChanged = false; |
| 10731 | } |
| 10732 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10733 | final boolean canBeSeen = w.isDisplayedLw(); |
| 10734 | |
| 10735 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 10736 | focusDisplayed = true; |
| 10737 | } |
| 10738 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10739 | final boolean obscuredChanged = w.mObscured != obscured; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10740 | |
| Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 10741 | if (mBackgroundFillerTarget != null) { |
| 10742 | if (w.isAnimating()) { |
| 10743 | // Background filler is below all other windows that |
| 10744 | // are animating. |
| 10745 | mBackgroundFillerTarget = w; |
| 10746 | } else if (w.mIsWallpaper) { |
| 10747 | mBackgroundFillerTarget = w; |
| 10748 | } |
| 10749 | } |
| 10750 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10751 | // Update effect. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10752 | if (!(w.mObscured=obscured)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10753 | if (w.mSurface != null) { |
| 10754 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 10755 | holdScreen = w.mSession; |
| 10756 | } |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10757 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 10758 | && screenBrightness < 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10759 | screenBrightness = w.mAttrs.screenBrightness; |
| 10760 | } |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10761 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 10762 | && buttonBrightness < 0) { |
| 10763 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 10764 | } |
| Mike Lockwood | 46af6a8 | 2010-03-09 08:28:22 -0500 | [diff] [blame] | 10765 | if (canBeSeen |
| 10766 | && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 10767 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 10768 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) { |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10769 | syswin = true; |
| 10770 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10771 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10772 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10773 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 10774 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10775 | // This window completely covers everything behind it, |
| 10776 | // so we want to leave all of them as unblurred (for |
| 10777 | // performance reasons). |
| 10778 | obscured = true; |
| Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 10779 | } else if (w.needsBackgroundFiller(dw, dh) && (canBeSeen || w.isAnimating())) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10780 | // This window is in compatibility mode, and needs background filler. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10781 | obscured = true; |
| Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 10782 | mBackgroundFillerTarget = w; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10783 | } else if (canBeSeen && !obscured && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10784 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10785 | if (localLOGV) Slog.v(TAG, "Win " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10786 | + ": blurring=" + blurring |
| 10787 | + " obscured=" + obscured |
| 10788 | + " displayed=" + displayed); |
| 10789 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 10790 | if (!dimming) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10791 | //Slog.i(TAG, "DIM BEHIND: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10792 | dimming = true; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10793 | if (mDimAnimator == null) { |
| 10794 | mDimAnimator = new DimAnimator(mFxSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10795 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10796 | mDimAnimator.show(dw, dh); |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 10797 | mDimAnimator.updateParameters(mContext.getResources(), |
| 10798 | w, currentTime); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10799 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10800 | } |
| 10801 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 10802 | if (!blurring) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10803 | //Slog.i(TAG, "BLUR BEHIND: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10804 | blurring = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10805 | if (mBlurSurface == null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10806 | try { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10807 | mBlurSurface = new Surface(mFxSession, 0, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10808 | "BlurSurface", |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10809 | -1, 16, 16, |
| 10810 | PixelFormat.OPAQUE, |
| 10811 | Surface.FX_SURFACE_BLUR); |
| 10812 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10813 | Slog.e(TAG, "Exception creating Blur surface", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10814 | } |
| Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 10815 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10816 | + mBlurSurface + ": CREATE"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10817 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10818 | if (mBlurSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10819 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10820 | + mBlurSurface + ": pos=(0,0) (" + |
| 10821 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10822 | mBlurSurface.setPosition(0, 0); |
| 10823 | mBlurSurface.setSize(dw, dh); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10824 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 10825 | if (!mBlurShown) { |
| 10826 | try { |
| 10827 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10828 | + mBlurSurface + ": SHOW"); |
| 10829 | mBlurSurface.show(); |
| 10830 | } catch (RuntimeException e) { |
| 10831 | Slog.w(TAG, "Failure showing blur surface", e); |
| 10832 | } |
| 10833 | mBlurShown = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10834 | } |
| 10835 | } |
| 10836 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10837 | } |
| 10838 | } |
| 10839 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10840 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10841 | if (obscuredChanged && mWallpaperTarget == w) { |
| 10842 | // This is the wallpaper target and its obscured state |
| 10843 | // changed... make sure the current wallaper's visibility |
| 10844 | // has been updated accordingly. |
| 10845 | updateWallpaperVisibilityLocked(); |
| 10846 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10847 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10848 | |
| Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 10849 | if (mBackgroundFillerTarget != null) { |
| 10850 | if (mBackgroundFillerSurface == null) { |
| 10851 | try { |
| 10852 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
| 10853 | "BackGroundFiller", |
| 10854 | 0, dw, dh, |
| 10855 | PixelFormat.OPAQUE, |
| 10856 | Surface.FX_SURFACE_NORMAL); |
| 10857 | } catch (Exception e) { |
| 10858 | Slog.e(TAG, "Exception creating filler surface", e); |
| 10859 | } |
| 10860 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BG FILLER " |
| 10861 | + mBackgroundFillerSurface + ": CREATE"); |
| 10862 | } |
| 10863 | try { |
| 10864 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BG FILLER " |
| 10865 | + mBackgroundFillerSurface + " SHOW: pos=(0,0) (" |
| 10866 | + dw + "x" + dh + ") layer=" |
| 10867 | + (mBackgroundFillerTarget.mLayer - 1)); |
| 10868 | mBackgroundFillerSurface.setPosition(0, 0); |
| 10869 | mBackgroundFillerSurface.setSize(dw, dh); |
| 10870 | // Using the same layer as Dim because they will never be shown at the |
| 10871 | // same time. NOTE: we do NOT use mAnimLayer, because we don't |
| 10872 | // want this surface dragged up in front of stuff that is animating. |
| 10873 | mBackgroundFillerSurface.setLayer(mBackgroundFillerTarget.mLayer - 1); |
| 10874 | mBackgroundFillerSurface.show(); |
| 10875 | } catch (RuntimeException e) { |
| 10876 | Slog.e(TAG, "Exception showing filler surface"); |
| 10877 | } |
| 10878 | } else if (backgroundFillerWasShown) { |
| 10879 | mBackgroundFillerTarget = null; |
| 10880 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BG FILLER " |
| 10881 | + mBackgroundFillerSurface + " HIDE"); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10882 | try { |
| 10883 | mBackgroundFillerSurface.hide(); |
| 10884 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10885 | Slog.e(TAG, "Exception hiding filler surface", e); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10886 | } |
| 10887 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10888 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10889 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10890 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 10891 | mDisplayFrozen || !mPolicy.isScreenOn()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10892 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10893 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10894 | if (!blurring && mBlurShown) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10895 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10896 | + ": HIDE"); |
| 10897 | try { |
| 10898 | mBlurSurface.hide(); |
| 10899 | } catch (IllegalArgumentException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10900 | Slog.w(TAG, "Illegal argument exception hiding blur surface"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10901 | } |
| 10902 | mBlurShown = false; |
| 10903 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10904 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10905 | Slog.e(TAG, "Unhandled exception in Window Manager", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10906 | } |
| 10907 | |
| 10908 | Surface.closeTransaction(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10909 | |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 10910 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces"); |
| 10911 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10912 | if (mWatermark != null) { |
| 10913 | mWatermark.drawIfNeeded(); |
| 10914 | } |
| 10915 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10916 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10917 | "With display frozen, orientationChangeComplete=" |
| 10918 | + orientationChangeComplete); |
| 10919 | if (orientationChangeComplete) { |
| 10920 | if (mWindowsFreezingScreen) { |
| 10921 | mWindowsFreezingScreen = false; |
| 10922 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10923 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10924 | stopFreezingDisplayLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10925 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10926 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10927 | i = mResizingWindows.size(); |
| 10928 | if (i > 0) { |
| 10929 | do { |
| 10930 | i--; |
| 10931 | WindowState win = mResizingWindows.get(i); |
| 10932 | try { |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10933 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| 10934 | "Reporting new frame to " + win + ": " + win.mFrame); |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10935 | int diff = 0; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10936 | boolean configChanged = |
| 10937 | win.mConfiguration != mCurConfiguration |
| 10938 | && (win.mConfiguration == null |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10939 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); |
| 10940 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) |
| 10941 | && configChanged) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10942 | Slog.i(TAG, "Sending new config to window " + win + ": " |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10943 | + win.mFrame.width() + "x" + win.mFrame.height() |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10944 | + " / " + mCurConfiguration + " / 0x" |
| 10945 | + Integer.toHexString(diff)); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10946 | } |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10947 | win.mConfiguration = mCurConfiguration; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10948 | win.mClient.resized(win.mFrame.width(), |
| 10949 | win.mFrame.height(), win.mLastContentInsets, |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10950 | win.mLastVisibleInsets, win.mDrawPending, |
| 10951 | configChanged ? win.mConfiguration : null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10952 | win.mContentInsetsChanged = false; |
| 10953 | win.mVisibleInsetsChanged = false; |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10954 | win.mSurfaceResized = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10955 | } catch (RemoteException e) { |
| 10956 | win.mOrientationChanging = false; |
| 10957 | } |
| 10958 | } while (i > 0); |
| 10959 | mResizingWindows.clear(); |
| 10960 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10961 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10962 | // Destroy the surface of any windows that are no longer visible. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10963 | boolean wallpaperDestroyed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10964 | i = mDestroySurface.size(); |
| 10965 | if (i > 0) { |
| 10966 | do { |
| 10967 | i--; |
| 10968 | WindowState win = mDestroySurface.get(i); |
| 10969 | win.mDestroying = false; |
| 10970 | if (mInputMethodWindow == win) { |
| 10971 | mInputMethodWindow = null; |
| 10972 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10973 | if (win == mWallpaperTarget) { |
| 10974 | wallpaperDestroyed = true; |
| 10975 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10976 | win.destroySurfaceLocked(); |
| 10977 | } while (i > 0); |
| 10978 | mDestroySurface.clear(); |
| 10979 | } |
| 10980 | |
| 10981 | // Time to remove any exiting tokens? |
| 10982 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 10983 | WindowToken token = mExitingTokens.get(i); |
| 10984 | if (!token.hasVisible) { |
| 10985 | mExitingTokens.remove(i); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10986 | if (token.windowType == TYPE_WALLPAPER) { |
| 10987 | mWallpaperTokens.remove(token); |
| 10988 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10989 | } |
| 10990 | } |
| 10991 | |
| 10992 | // Time to remove any exiting applications? |
| 10993 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10994 | AppWindowToken token = mExitingAppTokens.get(i); |
| 10995 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 10996 | // Make sure there is no animation running on this token, |
| 10997 | // so any windows associated with it will be removed as |
| 10998 | // soon as their animations are complete |
| 10999 | token.animation = null; |
| 11000 | token.animating = false; |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 11001 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 11002 | "performLayout: App token exiting now removed" + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11003 | mAppTokens.remove(token); |
| 11004 | mExitingAppTokens.remove(i); |
| 11005 | } |
| 11006 | } |
| 11007 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11008 | boolean needRelayout = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11009 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11010 | if (!animating && mAppTransitionRunning) { |
| 11011 | // We have finished the animation of an app transition. To do |
| 11012 | // this, we have delayed a lot of operations like showing and |
| 11013 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 11014 | // reflects the correct Z-order, but the window list may now |
| 11015 | // be out of sync with it. So here we will just rebuild the |
| 11016 | // entire app window list. Fun! |
| 11017 | mAppTransitionRunning = false; |
| 11018 | needRelayout = true; |
| 11019 | rebuildAppWindowListLocked(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11020 | assignLayersLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11021 | // Clear information about apps that were moving. |
| 11022 | mToBottomApps.clear(); |
| 11023 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11024 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11025 | if (focusDisplayed) { |
| 11026 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 11027 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 11028 | if (wallpaperDestroyed) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11029 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 11030 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11031 | if (needRelayout) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 11032 | requestAnimationLocked(0); |
| 11033 | } else if (animating) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11034 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 11035 | } |
| Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 11036 | |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 11037 | // Finally update all input windows now that the window changes have stabilized. |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 11038 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
| Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 11039 | |
| Jeff Brown | 8e03b75 | 2010-06-13 19:16:55 -0700 | [diff] [blame] | 11040 | setHoldScreenLocked(holdScreen != null); |
| Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 11041 | if (!mDisplayFrozen) { |
| 11042 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 11043 | mPowerManager.setScreenBrightnessOverride(-1); |
| 11044 | } else { |
| 11045 | mPowerManager.setScreenBrightnessOverride((int) |
| 11046 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 11047 | } |
| 11048 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 11049 | mPowerManager.setButtonBrightnessOverride(-1); |
| 11050 | } else { |
| 11051 | mPowerManager.setButtonBrightnessOverride((int) |
| 11052 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 11053 | } |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 11054 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11055 | if (holdScreen != mHoldingScreenOn) { |
| 11056 | mHoldingScreenOn = holdScreen; |
| 11057 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 11058 | mH.sendMessage(m); |
| 11059 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11060 | |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 11061 | if (mTurnOnScreen) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 11062 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 11063 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 11064 | LocalPowerManager.BUTTON_EVENT, true); |
| 11065 | mTurnOnScreen = false; |
| 11066 | } |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 11067 | |
| Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 11068 | if (screenRotationFinished && mScreenRotationAnimation != null) { |
| 11069 | mScreenRotationAnimation.kill(); |
| 11070 | mScreenRotationAnimation = null; |
| 11071 | } |
| 11072 | |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 11073 | if (updateRotation) { |
| 11074 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation"); |
| 11075 | boolean changed = setRotationUncheckedLocked( |
| 11076 | WindowManagerPolicy.USE_LAST_ROTATION, 0, false); |
| 11077 | if (changed) { |
| Dianne Hackborn | 3e4f9d04 | 2011-02-04 14:05:55 -0800 | [diff] [blame^] | 11078 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 11079 | } |
| 11080 | } |
| 11081 | |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 11082 | // Check to see if we are now in a state where the screen should |
| 11083 | // be enabled, because the window obscured flags have changed. |
| 11084 | enableScreenIfNeededLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11085 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 11086 | |
| 11087 | /** |
| 11088 | * Must be called with the main window manager lock held. |
| 11089 | */ |
| 11090 | void setHoldScreenLocked(boolean holding) { |
| 11091 | boolean state = mHoldingScreenWakeLock.isHeld(); |
| 11092 | if (holding != state) { |
| 11093 | if (holding) { |
| 11094 | mHoldingScreenWakeLock.acquire(); |
| 11095 | } else { |
| 11096 | mPolicy.screenOnStoppedLw(); |
| 11097 | mHoldingScreenWakeLock.release(); |
| 11098 | } |
| 11099 | } |
| 11100 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11101 | |
| 11102 | void requestAnimationLocked(long delay) { |
| 11103 | if (!mAnimationPending) { |
| 11104 | mAnimationPending = true; |
| 11105 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 11106 | } |
| 11107 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11108 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11109 | /** |
| 11110 | * Have the surface flinger show a surface, robustly dealing with |
| 11111 | * error conditions. In particular, if there is not enough memory |
| 11112 | * to show the surface, then we will try to get rid of other surfaces |
| 11113 | * in order to succeed. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11114 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11115 | * @return Returns true if the surface was successfully shown. |
| 11116 | */ |
| 11117 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 11118 | try { |
| 11119 | if (win.mSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11120 | win.mSurfaceShown = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11121 | win.mSurface.show(); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 11122 | if (win.mTurnOnScreen) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 11123 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 11124 | "Show surface turning screen on: " + win); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 11125 | win.mTurnOnScreen = false; |
| 11126 | mTurnOnScreen = true; |
| 11127 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11128 | } |
| 11129 | return true; |
| 11130 | } catch (RuntimeException e) { |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 11131 | 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] | 11132 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11133 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11134 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11135 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11136 | return false; |
| 11137 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11138 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11139 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 11140 | final Surface surface = win.mSurface; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11141 | |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11142 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11143 | win.mSession.mPid, operation); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11144 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11145 | if (mForceRemoves == null) { |
| 11146 | mForceRemoves = new ArrayList<WindowState>(); |
| 11147 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11148 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11149 | long callingIdentity = Binder.clearCallingIdentity(); |
| 11150 | try { |
| 11151 | // There was some problem... first, do a sanity check of the |
| 11152 | // window list to make sure we haven't left any dangling surfaces |
| 11153 | // around. |
| 11154 | int N = mWindows.size(); |
| 11155 | boolean leakedSurface = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11156 | 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] | 11157 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 11158 | WindowState ws = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11159 | if (ws.mSurface != null) { |
| 11160 | if (!mSessions.contains(ws.mSession)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11161 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11162 | + ws + " surface=" + ws.mSurface |
| 11163 | + " token=" + win.mToken |
| 11164 | + " pid=" + ws.mSession.mPid |
| 11165 | + " uid=" + ws.mSession.mUid); |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 11166 | if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11167 | ws.mSurface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11168 | ws.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11169 | ws.mSurface = null; |
| 11170 | mForceRemoves.add(ws); |
| 11171 | i--; |
| 11172 | N--; |
| 11173 | leakedSurface = true; |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 11174 | } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11175 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11176 | + ws + " surface=" + ws.mSurface |
| 11177 | + " token=" + win.mAppToken); |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 11178 | if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11179 | ws.mSurface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11180 | ws.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11181 | ws.mSurface = null; |
| 11182 | leakedSurface = true; |
| 11183 | } |
| 11184 | } |
| 11185 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11186 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11187 | boolean killedApps = false; |
| 11188 | if (!leakedSurface) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11189 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11190 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 11191 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 11192 | WindowState ws = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11193 | if (ws.mSurface != null) { |
| 11194 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 11195 | } |
| 11196 | } |
| 11197 | if (pidCandidates.size() > 0) { |
| 11198 | int[] pids = new int[pidCandidates.size()]; |
| 11199 | for (int i=0; i<pids.length; i++) { |
| 11200 | pids[i] = pidCandidates.keyAt(i); |
| 11201 | } |
| 11202 | try { |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 11203 | if (mActivityManager.killPids(pids, "Free memory")) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11204 | killedApps = true; |
| 11205 | } |
| 11206 | } catch (RemoteException e) { |
| 11207 | } |
| 11208 | } |
| 11209 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11210 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11211 | if (leakedSurface || killedApps) { |
| 11212 | // We managed to reclaim some memory, so get rid of the trouble |
| 11213 | // surface and ask the app to request another one. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11214 | 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] | 11215 | if (surface != null) { |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 11216 | if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11217 | surface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11218 | win.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11219 | win.mSurface = null; |
| 11220 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11221 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11222 | try { |
| 11223 | win.mClient.dispatchGetNewSurface(); |
| 11224 | } catch (RemoteException e) { |
| 11225 | } |
| 11226 | } |
| 11227 | } finally { |
| 11228 | Binder.restoreCallingIdentity(callingIdentity); |
| 11229 | } |
| 11230 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11231 | |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 11232 | private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11233 | WindowState newFocus = computeFocusedWindowLocked(); |
| 11234 | if (mCurrentFocus != newFocus) { |
| 11235 | // This check makes sure that we don't already have the focus |
| 11236 | // change message pending. |
| 11237 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 11238 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11239 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11240 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 11241 | final WindowState oldFocus = mCurrentFocus; |
| 11242 | mCurrentFocus = newFocus; |
| 11243 | mLosingFocus.remove(newFocus); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11244 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11245 | final WindowState imWindow = mInputMethodWindow; |
| 11246 | if (newFocus != imWindow && oldFocus != imWindow) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11247 | if (moveInputMethodWindowsIfNeededLocked( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11248 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11249 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 11250 | mLayoutNeeded = true; |
| 11251 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11252 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 11253 | performLayoutLockedInner(true /*initial*/, updateInputWindows); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11254 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 11255 | // Client will do the layout, but we need to assign layers |
| 11256 | // for handleNewWindowLocked() below. |
| 11257 | assignLayersLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11258 | } |
| 11259 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11260 | |
| 11261 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 11262 | // If we defer assigning layers, then the caller is responsible for |
| 11263 | // doing this part. |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 11264 | finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11265 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11266 | return true; |
| 11267 | } |
| 11268 | return false; |
| 11269 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11270 | |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 11271 | private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) { |
| 11272 | mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11273 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11274 | |
| 11275 | private WindowState computeFocusedWindowLocked() { |
| 11276 | WindowState result = null; |
| 11277 | WindowState win; |
| 11278 | |
| 11279 | int i = mWindows.size() - 1; |
| 11280 | int nextAppIndex = mAppTokens.size()-1; |
| 11281 | WindowToken nextApp = nextAppIndex >= 0 |
| 11282 | ? mAppTokens.get(nextAppIndex) : null; |
| 11283 | |
| 11284 | while (i >= 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 11285 | win = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11286 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11287 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11288 | TAG, "Looking for focus: " + i |
| 11289 | + " = " + win |
| 11290 | + ", flags=" + win.mAttrs.flags |
| 11291 | + ", canReceive=" + win.canReceiveKeys()); |
| 11292 | |
| 11293 | AppWindowToken thisApp = win.mAppToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11294 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11295 | // If this window's application has been removed, just skip it. |
| 11296 | if (thisApp != null && thisApp.removed) { |
| 11297 | i--; |
| 11298 | continue; |
| 11299 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11300 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11301 | // If there is a focused app, don't allow focus to go to any |
| 11302 | // windows below it. If this is an application window, step |
| 11303 | // through the app tokens until we find its app. |
| 11304 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 11305 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 11306 | int origAppIndex = nextAppIndex; |
| 11307 | while (nextAppIndex > 0) { |
| 11308 | if (nextApp == mFocusedApp) { |
| 11309 | // Whoops, we are below the focused app... no focus |
| 11310 | // for you! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11311 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11312 | TAG, "Reached focused app: " + mFocusedApp); |
| 11313 | return null; |
| 11314 | } |
| 11315 | nextAppIndex--; |
| 11316 | nextApp = mAppTokens.get(nextAppIndex); |
| 11317 | if (nextApp == thisApp) { |
| 11318 | break; |
| 11319 | } |
| 11320 | } |
| 11321 | if (thisApp != nextApp) { |
| 11322 | // Uh oh, the app token doesn't exist! This shouldn't |
| 11323 | // happen, but if it does we can get totally hosed... |
| 11324 | // so restart at the original app. |
| 11325 | nextAppIndex = origAppIndex; |
| 11326 | nextApp = mAppTokens.get(nextAppIndex); |
| 11327 | } |
| 11328 | } |
| 11329 | |
| 11330 | // Dispatch to this window if it is wants key events. |
| 11331 | if (win.canReceiveKeys()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11332 | if (DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11333 | TAG, "Found focus @ " + i + " = " + win); |
| 11334 | result = win; |
| 11335 | break; |
| 11336 | } |
| 11337 | |
| 11338 | i--; |
| 11339 | } |
| 11340 | |
| 11341 | return result; |
| 11342 | } |
| 11343 | |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 11344 | private void startFreezingDisplayLocked(boolean inTransaction) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11345 | if (mDisplayFrozen) { |
| 11346 | return; |
| 11347 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11348 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11349 | mScreenFrozenLock.acquire(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11350 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11351 | long now = SystemClock.uptimeMillis(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11352 | //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11353 | if (mFreezeGcPending != 0) { |
| 11354 | if (now > (mFreezeGcPending+1000)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11355 | //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11356 | mH.removeMessages(H.FORCE_GC); |
| 11357 | Runtime.getRuntime().gc(); |
| 11358 | mFreezeGcPending = now; |
| 11359 | } |
| 11360 | } else { |
| 11361 | mFreezeGcPending = now; |
| 11362 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11363 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11364 | mDisplayFrozen = true; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11365 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 11366 | mInputMonitor.freezeInputDispatchingLw(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11367 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 11368 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 11369 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11370 | mNextAppTransitionPackage = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11371 | mAppTransitionReady = true; |
| 11372 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11373 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11374 | if (PROFILE_ORIENTATION) { |
| 11375 | File file = new File("/data/system/frozen"); |
| 11376 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 11377 | } |
| Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11378 | |
| 11379 | if (CUSTOM_SCREEN_ROTATION) { |
| Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 11380 | if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) { |
| 11381 | mScreenRotationAnimation.kill(); |
| 11382 | mScreenRotationAnimation = null; |
| 11383 | } |
| Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11384 | if (mScreenRotationAnimation == null) { |
| Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 11385 | mScreenRotationAnimation = new ScreenRotationAnimation(mContext, |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 11386 | mDisplay, mFxSession, inTransaction); |
| Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11387 | } |
| 11388 | } else { |
| 11389 | Surface.freezeDisplay(0); |
| 11390 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11391 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11392 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11393 | private void stopFreezingDisplayLocked() { |
| 11394 | if (!mDisplayFrozen) { |
| 11395 | return; |
| 11396 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11397 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11398 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) { |
| 11399 | return; |
| 11400 | } |
| 11401 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11402 | mDisplayFrozen = false; |
| 11403 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 11404 | if (PROFILE_ORIENTATION) { |
| 11405 | Debug.stopMethodTracing(); |
| 11406 | } |
| Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11407 | |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 11408 | boolean updateRotation = false; |
| 11409 | |
| Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11410 | if (CUSTOM_SCREEN_ROTATION) { |
| 11411 | if (mScreenRotationAnimation != null) { |
| Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 11412 | if (mScreenRotationAnimation.dismiss(mFxSession, MAX_ANIMATION_DURATION, |
| Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 11413 | mTransitionAnimationScale)) { |
| 11414 | requestAnimationLocked(0); |
| 11415 | } else { |
| 11416 | mScreenRotationAnimation = null; |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 11417 | updateRotation = true; |
| Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 11418 | } |
| Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11419 | } |
| 11420 | } else { |
| 11421 | Surface.unfreezeDisplay(0); |
| 11422 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11423 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 11424 | mInputMonitor.thawInputDispatchingLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11425 | |
| Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 11426 | boolean configChanged; |
| 11427 | |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 11428 | // While the display is frozen we don't re-compute the orientation |
| 11429 | // to avoid inconsistent states. However, something interesting |
| 11430 | // could have actually changed during that time so re-evaluate it |
| 11431 | // now to catch that. |
| Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 11432 | configChanged = updateOrientationFromAppTokensLocked(false); |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 11433 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11434 | // A little kludge: a lot could have happened while the |
| 11435 | // display was frozen, so now that we are coming back we |
| 11436 | // do a gc so that any remote references the system |
| 11437 | // processes holds on others can be released if they are |
| 11438 | // no longer needed. |
| 11439 | mH.removeMessages(H.FORCE_GC); |
| 11440 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 11441 | 2000); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11442 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11443 | mScreenFrozenLock.release(); |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 11444 | |
| 11445 | if (updateRotation) { |
| 11446 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation"); |
| Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 11447 | configChanged |= setRotationUncheckedLocked( |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 11448 | WindowManagerPolicy.USE_LAST_ROTATION, 0, false); |
| Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 11449 | } |
| 11450 | |
| 11451 | if (configChanged) { |
| 11452 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 11453 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11454 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11455 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11456 | static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps, |
| 11457 | DisplayMetrics dm) { |
| 11458 | if (index < tokens.length) { |
| 11459 | String str = tokens[index]; |
| 11460 | if (str != null && str.length() > 0) { |
| 11461 | try { |
| 11462 | int val = Integer.parseInt(str); |
| 11463 | return val; |
| 11464 | } catch (Exception e) { |
| 11465 | } |
| 11466 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11467 | } |
| 11468 | if (defUnits == TypedValue.COMPLEX_UNIT_PX) { |
| 11469 | return defDps; |
| 11470 | } |
| 11471 | int val = (int)TypedValue.applyDimension(defUnits, defDps, dm); |
| 11472 | return val; |
| 11473 | } |
| 11474 | |
| Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11475 | static class Watermark { |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11476 | final String[] mTokens; |
| 11477 | final String mText; |
| 11478 | final Paint mTextPaint; |
| 11479 | final int mTextWidth; |
| 11480 | final int mTextHeight; |
| 11481 | final int mTextAscent; |
| 11482 | final int mTextDescent; |
| 11483 | final int mDeltaX; |
| 11484 | final int mDeltaY; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11485 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11486 | Surface mSurface; |
| 11487 | int mLastDW; |
| 11488 | int mLastDH; |
| 11489 | boolean mDrawNeeded; |
| 11490 | |
| Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11491 | Watermark(Display display, SurfaceSession session, String[] tokens) { |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11492 | final DisplayMetrics dm = new DisplayMetrics(); |
| Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11493 | display.getMetrics(dm); |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11494 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11495 | if (false) { |
| 11496 | Log.i(TAG, "*********************** WATERMARK"); |
| 11497 | for (int i=0; i<tokens.length; i++) { |
| 11498 | Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]); |
| 11499 | } |
| 11500 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11501 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11502 | mTokens = tokens; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11503 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11504 | StringBuilder builder = new StringBuilder(32); |
| 11505 | int len = mTokens[0].length(); |
| 11506 | len = len & ~1; |
| 11507 | for (int i=0; i<len; i+=2) { |
| 11508 | int c1 = mTokens[0].charAt(i); |
| 11509 | int c2 = mTokens[0].charAt(i+1); |
| 11510 | if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10; |
| 11511 | else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10; |
| 11512 | else c1 -= '0'; |
| 11513 | if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10; |
| 11514 | else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10; |
| 11515 | else c2 -= '0'; |
| 11516 | builder.append((char)(255-((c1*16)+c2))); |
| 11517 | } |
| 11518 | mText = builder.toString(); |
| 11519 | if (false) { |
| 11520 | Log.i(TAG, "Final text: " + mText); |
| 11521 | } |
| 11522 | |
| 11523 | int fontSize = getPropertyInt(tokens, 1, |
| 11524 | TypedValue.COMPLEX_UNIT_DIP, 20, dm); |
| 11525 | |
| 11526 | mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
| 11527 | mTextPaint.setTextSize(fontSize); |
| 11528 | mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD)); |
| 11529 | |
| 11530 | FontMetricsInt fm = mTextPaint.getFontMetricsInt(); |
| 11531 | mTextWidth = (int)mTextPaint.measureText(mText); |
| 11532 | mTextAscent = fm.ascent; |
| 11533 | mTextDescent = fm.descent; |
| 11534 | mTextHeight = fm.descent - fm.ascent; |
| 11535 | |
| 11536 | mDeltaX = getPropertyInt(tokens, 2, |
| 11537 | TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm); |
| 11538 | mDeltaY = getPropertyInt(tokens, 3, |
| 11539 | TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm); |
| 11540 | int shadowColor = getPropertyInt(tokens, 4, |
| 11541 | TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm); |
| 11542 | int color = getPropertyInt(tokens, 5, |
| 11543 | TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm); |
| 11544 | int shadowRadius = getPropertyInt(tokens, 6, |
| 11545 | TypedValue.COMPLEX_UNIT_PX, 7, dm); |
| 11546 | int shadowDx = getPropertyInt(tokens, 8, |
| 11547 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 11548 | int shadowDy = getPropertyInt(tokens, 9, |
| 11549 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 11550 | |
| 11551 | mTextPaint.setColor(color); |
| 11552 | mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor); |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11553 | |
| 11554 | try { |
| 11555 | mSurface = new Surface(session, 0, |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11556 | "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0); |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11557 | mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100); |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11558 | mSurface.setPosition(0, 0); |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11559 | mSurface.show(); |
| 11560 | } catch (OutOfResourcesException e) { |
| 11561 | } |
| 11562 | } |
| 11563 | |
| 11564 | void positionSurface(int dw, int dh) { |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11565 | if (mLastDW != dw || mLastDH != dh) { |
| 11566 | mLastDW = dw; |
| 11567 | mLastDH = dh; |
| 11568 | mSurface.setSize(dw, dh); |
| 11569 | mDrawNeeded = true; |
| 11570 | } |
| 11571 | } |
| 11572 | |
| 11573 | void drawIfNeeded() { |
| 11574 | if (mDrawNeeded) { |
| 11575 | final int dw = mLastDW; |
| 11576 | final int dh = mLastDH; |
| 11577 | |
| 11578 | mDrawNeeded = false; |
| 11579 | Rect dirty = new Rect(0, 0, dw, dh); |
| 11580 | Canvas c = null; |
| 11581 | try { |
| 11582 | c = mSurface.lockCanvas(dirty); |
| 11583 | } catch (IllegalArgumentException e) { |
| 11584 | } catch (OutOfResourcesException e) { |
| 11585 | } |
| 11586 | if (c != null) { |
| Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11587 | c.drawColor(0, PorterDuff.Mode.CLEAR); |
| 11588 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11589 | int deltaX = mDeltaX; |
| 11590 | int deltaY = mDeltaY; |
| 11591 | |
| 11592 | // deltaX shouldn't be close to a round fraction of our |
| 11593 | // x step, or else things will line up too much. |
| 11594 | int div = (dw+mTextWidth)/deltaX; |
| 11595 | int rem = (dw+mTextWidth) - (div*deltaX); |
| 11596 | int qdelta = deltaX/4; |
| 11597 | if (rem < qdelta || rem > (deltaX-qdelta)) { |
| 11598 | deltaX += deltaX/3; |
| 11599 | } |
| 11600 | |
| 11601 | int y = -mTextHeight; |
| 11602 | int x = -mTextWidth; |
| 11603 | while (y < (dh+mTextHeight)) { |
| 11604 | c.drawText(mText, x, y, mTextPaint); |
| 11605 | x += deltaX; |
| 11606 | if (x >= dw) { |
| 11607 | x -= (dw+mTextWidth); |
| 11608 | y += deltaY; |
| 11609 | } |
| 11610 | } |
| 11611 | mSurface.unlockCanvasAndPost(c); |
| 11612 | } |
| 11613 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11614 | } |
| 11615 | } |
| 11616 | |
| 11617 | void createWatermark() { |
| 11618 | if (mWatermark != null) { |
| 11619 | return; |
| 11620 | } |
| 11621 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11622 | File file = new File("/system/etc/setup.conf"); |
| 11623 | FileInputStream in = null; |
| 11624 | try { |
| 11625 | in = new FileInputStream(file); |
| 11626 | DataInputStream ind = new DataInputStream(in); |
| 11627 | String line = ind.readLine(); |
| 11628 | if (line != null) { |
| 11629 | String[] toks = line.split("%"); |
| 11630 | if (toks != null && toks.length > 0) { |
| Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11631 | mWatermark = new Watermark(mDisplay, mFxSession, toks); |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11632 | } |
| 11633 | } |
| 11634 | } catch (FileNotFoundException e) { |
| 11635 | } catch (IOException e) { |
| 11636 | } finally { |
| 11637 | if (in != null) { |
| 11638 | try { |
| 11639 | in.close(); |
| 11640 | } catch (IOException e) { |
| 11641 | } |
| 11642 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11643 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11644 | } |
| 11645 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11646 | @Override |
| Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 11647 | public void statusBarVisibilityChanged(int visibility) { |
| 11648 | synchronized (mWindowMap) { |
| 11649 | final int N = mWindows.size(); |
| 11650 | for (int i = 0; i < N; i++) { |
| 11651 | WindowState ws = mWindows.get(i); |
| 11652 | try { |
| 11653 | if (ws.getAttrs().hasSystemUiListeners) { |
| 11654 | ws.mClient.dispatchSystemUiVisibilityChanged(visibility); |
| 11655 | } |
| 11656 | } catch (RemoteException e) { |
| 11657 | // so sorry |
| 11658 | } |
| 11659 | } |
| 11660 | } |
| 11661 | } |
| 11662 | |
| 11663 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11664 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 11665 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 11666 | != PackageManager.PERMISSION_GRANTED) { |
| 11667 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 11668 | + Binder.getCallingPid() |
| 11669 | + ", uid=" + Binder.getCallingUid()); |
| 11670 | return; |
| 11671 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11672 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 11673 | mInputManager.dump(pw); |
| Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 11674 | pw.println(" "); |
| 11675 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11676 | synchronized(mWindowMap) { |
| 11677 | pw.println("Current Window Manager state:"); |
| 11678 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 11679 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11680 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 11681 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11682 | w.dump(pw, " "); |
| 11683 | } |
| 11684 | if (mInputMethodDialogs.size() > 0) { |
| 11685 | pw.println(" "); |
| 11686 | pw.println(" Input method dialogs:"); |
| 11687 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 11688 | WindowState w = mInputMethodDialogs.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11689 | 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] | 11690 | } |
| 11691 | } |
| 11692 | if (mPendingRemove.size() > 0) { |
| 11693 | pw.println(" "); |
| 11694 | pw.println(" Remove pending for:"); |
| 11695 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 11696 | WindowState w = mPendingRemove.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11697 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 11698 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11699 | w.dump(pw, " "); |
| 11700 | } |
| 11701 | } |
| 11702 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 11703 | pw.println(" "); |
| 11704 | pw.println(" Windows force removing:"); |
| 11705 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 11706 | WindowState w = mForceRemoves.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11707 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 11708 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11709 | w.dump(pw, " "); |
| 11710 | } |
| 11711 | } |
| 11712 | if (mDestroySurface.size() > 0) { |
| 11713 | pw.println(" "); |
| 11714 | pw.println(" Windows waiting to destroy their surface:"); |
| 11715 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 11716 | WindowState w = mDestroySurface.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11717 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 11718 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11719 | w.dump(pw, " "); |
| 11720 | } |
| 11721 | } |
| 11722 | if (mLosingFocus.size() > 0) { |
| 11723 | pw.println(" "); |
| 11724 | pw.println(" Windows losing focus:"); |
| 11725 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 11726 | WindowState w = mLosingFocus.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11727 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 11728 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11729 | w.dump(pw, " "); |
| 11730 | } |
| 11731 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11732 | if (mResizingWindows.size() > 0) { |
| 11733 | pw.println(" "); |
| 11734 | pw.println(" Windows waiting to resize:"); |
| 11735 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 11736 | WindowState w = mResizingWindows.get(i); |
| 11737 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 11738 | pw.print(w); pw.println(":"); |
| 11739 | w.dump(pw, " "); |
| 11740 | } |
| 11741 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11742 | if (mSessions.size() > 0) { |
| 11743 | pw.println(" "); |
| 11744 | pw.println(" All active sessions:"); |
| 11745 | Iterator<Session> it = mSessions.iterator(); |
| 11746 | while (it.hasNext()) { |
| 11747 | Session s = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11748 | pw.print(" Session "); pw.print(s); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11749 | s.dump(pw, " "); |
| 11750 | } |
| 11751 | } |
| 11752 | if (mTokenMap.size() > 0) { |
| 11753 | pw.println(" "); |
| 11754 | pw.println(" All tokens:"); |
| 11755 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 11756 | while (it.hasNext()) { |
| 11757 | WindowToken token = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11758 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11759 | token.dump(pw, " "); |
| 11760 | } |
| 11761 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 11762 | if (mWallpaperTokens.size() > 0) { |
| 11763 | pw.println(" "); |
| 11764 | pw.println(" Wallpaper tokens:"); |
| 11765 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 11766 | WindowToken token = mWallpaperTokens.get(i); |
| 11767 | pw.print(" Wallpaper #"); pw.print(i); |
| 11768 | pw.print(' '); pw.print(token); pw.println(':'); |
| 11769 | token.dump(pw, " "); |
| 11770 | } |
| 11771 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11772 | if (mAppTokens.size() > 0) { |
| 11773 | pw.println(" "); |
| 11774 | pw.println(" Application tokens in Z order:"); |
| 11775 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11776 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 11777 | pw.println(mAppTokens.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11778 | } |
| 11779 | } |
| 11780 | if (mFinishedStarting.size() > 0) { |
| 11781 | pw.println(" "); |
| 11782 | pw.println(" Finishing start of application tokens:"); |
| 11783 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 11784 | WindowToken token = mFinishedStarting.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11785 | pw.print(" Finished Starting #"); pw.print(i); |
| 11786 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11787 | token.dump(pw, " "); |
| 11788 | } |
| 11789 | } |
| 11790 | if (mExitingTokens.size() > 0) { |
| 11791 | pw.println(" "); |
| 11792 | pw.println(" Exiting tokens:"); |
| 11793 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 11794 | WindowToken token = mExitingTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11795 | pw.print(" Exiting #"); pw.print(i); |
| 11796 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11797 | token.dump(pw, " "); |
| 11798 | } |
| 11799 | } |
| 11800 | if (mExitingAppTokens.size() > 0) { |
| 11801 | pw.println(" "); |
| 11802 | pw.println(" Exiting application tokens:"); |
| 11803 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 11804 | WindowToken token = mExitingAppTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11805 | pw.print(" Exiting App #"); pw.print(i); |
| 11806 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11807 | token.dump(pw, " "); |
| 11808 | } |
| 11809 | } |
| 11810 | pw.println(" "); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11811 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 11812 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 11813 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 11814 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 11815 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
| Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 11816 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11817 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 11818 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 11819 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 11820 | } |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 11821 | if (mWindowDetachedWallpaper != null) { |
| 11822 | pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper); |
| 11823 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11824 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 11825 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 11826 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11827 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 11828 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 11829 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 11830 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11831 | if (mDimAnimator != null) { |
| 11832 | mDimAnimator.printTo(pw); |
| 11833 | } else { |
| Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 11834 | pw.println( " no DimAnimator "); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11835 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11836 | pw.print(" mInputMethodAnimLayerAdjustment="); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 11837 | pw.print(mInputMethodAnimLayerAdjustment); |
| 11838 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 11839 | pw.println(mWallpaperAnimLayerAdjustment); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11840 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 11841 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11842 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 11843 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11844 | pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); |
| 11845 | pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11846 | pw.print(" mRotation="); pw.print(mRotation); |
| 11847 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 11848 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 11849 | pw.print(" mDeferredRotation="); pw.print(mDeferredRotation); |
| 11850 | pw.print(", mDeferredRotationAnimFlags="); pw.print(mDeferredRotationAnimFlags); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11851 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 11852 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 11853 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 11854 | pw.print(" mNextAppTransition=0x"); |
| 11855 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 11856 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11857 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11858 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11859 | if (mNextAppTransitionPackage != null) { |
| 11860 | pw.print(" mNextAppTransitionPackage="); |
| 11861 | pw.print(mNextAppTransitionPackage); |
| 11862 | pw.print(", mNextAppTransitionEnter=0x"); |
| 11863 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 11864 | pw.print(", mNextAppTransitionExit=0x"); |
| 11865 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 11866 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11867 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 11868 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
| 11869 | if (mOpeningApps.size() > 0) { |
| 11870 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 11871 | } |
| 11872 | if (mClosingApps.size() > 0) { |
| 11873 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 11874 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11875 | if (mToTopApps.size() > 0) { |
| 11876 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 11877 | } |
| 11878 | if (mToBottomApps.size() > 0) { |
| 11879 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 11880 | } |
| Dianne Hackborn | 87fc308 | 2010-12-03 13:09:12 -0800 | [diff] [blame] | 11881 | if (mDisplay != null) { |
| 11882 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 11883 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
| 11884 | } else { |
| 11885 | pw.println(" NO DISPLAY"); |
| 11886 | } |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 11887 | pw.println(" Policy:"); |
| 11888 | mPolicy.dump(" ", fd, pw, args); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11889 | } |
| 11890 | } |
| 11891 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11892 | // 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] | 11893 | public void monitor() { |
| 11894 | synchronized (mWindowMap) { } |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 11895 | synchronized (mKeyguardTokenWatcher) { } |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 11896 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11897 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11898 | /** |
| 11899 | * DimAnimator class that controls the dim animation. This holds the surface and |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11900 | * all state used for dim animation. |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11901 | */ |
| 11902 | private static class DimAnimator { |
| 11903 | Surface mDimSurface; |
| 11904 | boolean mDimShown = false; |
| 11905 | float mDimCurrentAlpha; |
| 11906 | float mDimTargetAlpha; |
| 11907 | float mDimDeltaPerMs; |
| 11908 | long mLastDimAnimTime; |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11909 | |
| 11910 | int mLastDimWidth, mLastDimHeight; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11911 | |
| 11912 | DimAnimator (SurfaceSession session) { |
| 11913 | if (mDimSurface == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11914 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11915 | + mDimSurface + ": CREATE"); |
| 11916 | try { |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 11917 | mDimSurface = new Surface(session, 0, |
| 11918 | "DimSurface", |
| 11919 | -1, 16, 16, PixelFormat.OPAQUE, |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11920 | Surface.FX_SURFACE_DIM); |
| Maciej Białka | 9ee5c22 | 2010-03-24 10:25:40 +0100 | [diff] [blame] | 11921 | mDimSurface.setAlpha(0.0f); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11922 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11923 | Slog.e(TAG, "Exception creating Dim surface", e); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11924 | } |
| 11925 | } |
| 11926 | } |
| 11927 | |
| 11928 | /** |
| 11929 | * Show the dim surface. |
| 11930 | */ |
| 11931 | void show(int dw, int dh) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11932 | if (!mDimShown) { |
| 11933 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 11934 | dw + "x" + dh + ")"); |
| 11935 | mDimShown = true; |
| 11936 | try { |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11937 | mLastDimWidth = dw; |
| 11938 | mLastDimHeight = dh; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11939 | mDimSurface.setPosition(0, 0); |
| 11940 | mDimSurface.setSize(dw, dh); |
| 11941 | mDimSurface.show(); |
| 11942 | } catch (RuntimeException e) { |
| 11943 | Slog.w(TAG, "Failure showing dim surface", e); |
| 11944 | } |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11945 | } else if (mLastDimWidth != dw || mLastDimHeight != dh) { |
| 11946 | mLastDimWidth = dw; |
| 11947 | mLastDimHeight = dh; |
| 11948 | mDimSurface.setSize(dw, dh); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11949 | } |
| 11950 | } |
| 11951 | |
| 11952 | /** |
| 11953 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 11954 | * {@link updateSurface} after all windows are examined. |
| 11955 | */ |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 11956 | void updateParameters(Resources res, WindowState w, long currentTime) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11957 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 11958 | |
| 11959 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11960 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11961 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11962 | if (mDimTargetAlpha != target) { |
| 11963 | // If the desired dim level has changed, then |
| 11964 | // start an animation to it. |
| 11965 | mLastDimAnimTime = currentTime; |
| 11966 | long duration = (w.mAnimating && w.mAnimation != null) |
| 11967 | ? w.mAnimation.computeDurationHint() |
| 11968 | : DEFAULT_DIM_DURATION; |
| 11969 | if (target > mDimTargetAlpha) { |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 11970 | TypedValue tv = new TypedValue(); |
| 11971 | res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration, |
| 11972 | tv, true); |
| 11973 | if (tv.type == TypedValue.TYPE_FRACTION) { |
| 11974 | duration = (long)tv.getFraction((float)duration, (float)duration); |
| 11975 | } else if (tv.type >= TypedValue.TYPE_FIRST_INT |
| 11976 | && tv.type <= TypedValue.TYPE_LAST_INT) { |
| 11977 | duration = tv.data; |
| 11978 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11979 | } |
| 11980 | if (duration < 1) { |
| 11981 | // Don't divide by zero |
| 11982 | duration = 1; |
| 11983 | } |
| 11984 | mDimTargetAlpha = target; |
| 11985 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 11986 | } |
| 11987 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11988 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11989 | /** |
| 11990 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 11991 | * false when the animation is finished and the dim surface is hidden. |
| 11992 | */ |
| 11993 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 11994 | if (!dimming) { |
| 11995 | if (mDimTargetAlpha != 0) { |
| 11996 | mLastDimAnimTime = currentTime; |
| 11997 | mDimTargetAlpha = 0; |
| 11998 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 11999 | } |
| 12000 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 12001 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12002 | boolean animating = false; |
| 12003 | if (mLastDimAnimTime != 0) { |
| 12004 | mDimCurrentAlpha += mDimDeltaPerMs |
| 12005 | * (currentTime-mLastDimAnimTime); |
| 12006 | boolean more = true; |
| 12007 | if (displayFrozen) { |
| 12008 | // If the display is frozen, there is no reason to animate. |
| 12009 | more = false; |
| 12010 | } else if (mDimDeltaPerMs > 0) { |
| 12011 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 12012 | more = false; |
| 12013 | } |
| 12014 | } else if (mDimDeltaPerMs < 0) { |
| 12015 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 12016 | more = false; |
| 12017 | } |
| 12018 | } else { |
| 12019 | more = false; |
| 12020 | } |
| 12021 | |
| 12022 | // Do we need to continue animating? |
| 12023 | if (more) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 12024 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12025 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 12026 | mLastDimAnimTime = currentTime; |
| 12027 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 12028 | animating = true; |
| 12029 | } else { |
| 12030 | mDimCurrentAlpha = mDimTargetAlpha; |
| 12031 | mLastDimAnimTime = 0; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 12032 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12033 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 12034 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 12035 | if (!dimming) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 12036 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12037 | + ": HIDE"); |
| 12038 | try { |
| 12039 | mDimSurface.hide(); |
| 12040 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 12041 | Slog.w(TAG, "Illegal argument exception hiding dim surface"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12042 | } |
| 12043 | mDimShown = false; |
| 12044 | } |
| 12045 | } |
| 12046 | } |
| 12047 | return animating; |
| 12048 | } |
| 12049 | |
| 12050 | public void printTo(PrintWriter pw) { |
| 12051 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 12052 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 12053 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 12054 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 12055 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 12056 | } |
| 12057 | } |
| 12058 | |
| 12059 | /** |
| 12060 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 12061 | * This is used for opening/closing transition for apps in compatible mode. |
| 12062 | */ |
| 12063 | private static class FadeInOutAnimation extends Animation { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12064 | boolean mFadeIn; |
| 12065 | |
| 12066 | public FadeInOutAnimation(boolean fadeIn) { |
| 12067 | setInterpolator(new AccelerateInterpolator()); |
| 12068 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 12069 | mFadeIn = fadeIn; |
| 12070 | } |
| 12071 | |
| 12072 | @Override |
| 12073 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 12074 | float x = interpolatedTime; |
| 12075 | if (!mFadeIn) { |
| 12076 | x = 1.0f - x; // reverse the interpolation for fade out |
| 12077 | } |
| Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 12078 | t.setAlpha(x); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12079 | } |
| 12080 | } |
| Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 12081 | |
| 12082 | public interface OnHardKeyboardStatusChangeListener { |
| 12083 | public void onHardKeyboardStatusChange(boolean available, boolean enabled); |
| 12084 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12085 | } |