The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 17 | package com.android.server.wm; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
| 20 | import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 21 | import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -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; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 26 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 28 | import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 29 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 31 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 32 | import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS; |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 33 | import static android.view.WindowManager.LayoutParams.TYPE_DREAM; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 35 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 36 | import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD; |
| 37 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG; |
| 38 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 39 | import static android.view.WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 40 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | |
| 42 | import com.android.internal.app.IBatteryStats; |
| 43 | import com.android.internal.policy.PolicyManager; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 44 | import com.android.internal.policy.impl.PhoneWindowManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import com.android.internal.view.IInputContext; |
| 46 | import com.android.internal.view.IInputMethodClient; |
| 47 | import com.android.internal.view.IInputMethodManager; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 48 | import com.android.internal.view.WindowManagerPolicyThread; |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 49 | import com.android.server.AttributeCache; |
| 50 | import com.android.server.EventLogTags; |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 51 | import com.android.server.Watchdog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import com.android.server.am.BatteryStatsService; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 53 | import com.android.server.display.DisplayManagerService; |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 54 | import com.android.server.input.InputManagerService; |
Jeff Brown | 4f8ecd8 | 2012-06-18 18:29:13 -0700 | [diff] [blame] | 55 | import com.android.server.power.PowerManagerService; |
| 56 | import com.android.server.power.ShutdownThread; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | |
| 58 | import android.Manifest; |
| 59 | import android.app.ActivityManagerNative; |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 60 | import android.app.ActivityOptions; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | import android.app.IActivityManager; |
Joe Onorato | ac0ee89 | 2011-01-30 15:38:30 -0800 | [diff] [blame] | 62 | import android.app.StatusBarManager; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 63 | import android.app.admin.DevicePolicyManager; |
Jeff Brown | ff7e6ef | 2012-08-15 02:05:18 -0700 | [diff] [blame] | 64 | import android.animation.ValueAnimator; |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 65 | import android.content.BroadcastReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | import android.content.Context; |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 67 | import android.content.Intent; |
| 68 | import android.content.IntentFilter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | import android.content.pm.ActivityInfo; |
| 70 | import android.content.pm.PackageManager; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 71 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | import android.content.res.Configuration; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 73 | import android.graphics.Bitmap; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 74 | import android.graphics.Canvas; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | import android.graphics.Matrix; |
| 76 | import android.graphics.PixelFormat; |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 77 | import android.graphics.Point; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | import android.graphics.Rect; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 79 | import android.graphics.RectF; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | import android.graphics.Region; |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 81 | import android.hardware.display.DisplayManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | import android.os.Binder; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 83 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | import android.os.Debug; |
| 85 | import android.os.Handler; |
| 86 | import android.os.IBinder; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 87 | import android.os.IRemoteCallback; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | import android.os.Looper; |
| 89 | import android.os.Message; |
| 90 | import android.os.Parcel; |
| 91 | import android.os.ParcelFileDescriptor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | import android.os.PowerManager; |
| 93 | import android.os.Process; |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 94 | import android.os.RemoteCallbackList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | import android.os.RemoteException; |
| 96 | import android.os.ServiceManager; |
Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 97 | import android.os.StrictMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | import android.os.SystemClock; |
| 99 | import android.os.SystemProperties; |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 100 | import android.os.Trace; |
Craig Mautner | 259328c | 2012-08-21 19:30:58 -0700 | [diff] [blame] | 101 | import android.os.WorkSource; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | import android.provider.Settings; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 103 | import android.util.DisplayMetrics; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | import android.util.EventLog; |
Michael Jurka | 4accb6a | 2012-03-26 09:18:46 -0700 | [diff] [blame] | 105 | import android.util.FloatMath; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 106 | import android.util.Log; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 107 | import android.util.SparseArray; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 108 | import android.util.Pair; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 109 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | import android.util.SparseIntArray; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 111 | import android.util.TypedValue; |
Dianne Hackborn | 8bcd54b | 2012-01-31 19:04:53 -0800 | [diff] [blame] | 112 | import android.view.Choreographer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | import android.view.Display; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 114 | import android.view.DisplayInfo; |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 115 | import android.view.Gravity; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | import android.view.IApplicationToken; |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 117 | import android.view.IDisplayContentChangeListener; |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 118 | import android.view.IInputFilter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | import android.view.IOnKeyguardExitResult; |
| 120 | import android.view.IRotationWatcher; |
| 121 | import android.view.IWindow; |
| 122 | import android.view.IWindowManager; |
| 123 | import android.view.IWindowSession; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 124 | import android.view.InputChannel; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 125 | import android.view.InputDevice; |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 126 | import android.view.InputEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 127 | import android.view.InputEventReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | import android.view.KeyEvent; |
| 129 | import android.view.MotionEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | import android.view.Surface; |
| 131 | import android.view.SurfaceSession; |
| 132 | import android.view.View; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 133 | import android.view.ViewTreeObserver; |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 134 | import android.view.WindowInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | import android.view.WindowManager; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 136 | import android.view.WindowManagerGlobal; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | import android.view.WindowManagerPolicy; |
| 138 | import android.view.WindowManager.LayoutParams; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 139 | import android.view.WindowManagerPolicy.FakeWindow; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 140 | import android.view.animation.AlphaAnimation; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | import android.view.animation.Animation; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 142 | import android.view.animation.AnimationSet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | import android.view.animation.AnimationUtils; |
Michael Jurka | c016aaa | 2012-06-05 17:22:24 -0700 | [diff] [blame] | 144 | import android.view.animation.DecelerateInterpolator; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 145 | import android.view.animation.Interpolator; |
| 146 | import android.view.animation.ScaleAnimation; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 147 | import android.view.animation.Transformation; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | |
| 149 | import java.io.BufferedWriter; |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 150 | import java.io.DataInputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | import java.io.File; |
| 152 | import java.io.FileDescriptor; |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 153 | import java.io.FileInputStream; |
| 154 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | import java.io.IOException; |
| 156 | import java.io.OutputStream; |
| 157 | import java.io.OutputStreamWriter; |
| 158 | import java.io.PrintWriter; |
| 159 | import java.io.StringWriter; |
| 160 | import java.net.Socket; |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 161 | import java.text.DateFormat; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | import java.util.ArrayList; |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 163 | import java.util.Date; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | import java.util.HashMap; |
| 165 | import java.util.HashSet; |
| 166 | import java.util.Iterator; |
| 167 | import java.util.List; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 168 | import java.util.NoSuchElementException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | |
| 170 | /** {@hide} */ |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 171 | public class WindowManagerService extends IWindowManager.Stub |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 172 | implements Watchdog.Monitor, WindowManagerPolicy.WindowManagerFuncs, |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 173 | DisplayManagerService.WindowManagerFuncs, DisplayManager.DisplayListener { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | static final String TAG = "WindowManager"; |
| 175 | static final boolean DEBUG = false; |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 176 | static final boolean DEBUG_ADD_REMOVE = false; |
Craig Mautner | 343511c | 2012-02-28 17:30:50 -0800 | [diff] [blame] | 177 | static final boolean DEBUG_FOCUS = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | static final boolean DEBUG_ANIM = false; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 179 | static final boolean DEBUG_LAYOUT = false; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 180 | static final boolean DEBUG_RESIZE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | static final boolean DEBUG_LAYERS = false; |
| 182 | static final boolean DEBUG_INPUT = false; |
| 183 | static final boolean DEBUG_INPUT_METHOD = false; |
| 184 | static final boolean DEBUG_VISIBILITY = false; |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 185 | static final boolean DEBUG_WINDOW_MOVEMENT = false; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 186 | static final boolean DEBUG_TOKEN_MOVEMENT = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | static final boolean DEBUG_ORIENTATION = false; |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 188 | static final boolean DEBUG_APP_ORIENTATION = false; |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 189 | static final boolean DEBUG_CONFIGURATION = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 191 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 192 | static final boolean DEBUG_REORDER = false; |
Craig Mautner | 343511c | 2012-02-28 17:30:50 -0800 | [diff] [blame] | 193 | static final boolean DEBUG_WALLPAPER = false; |
Christopher Tate | 994ef92 | 2011-01-12 20:06:07 -0800 | [diff] [blame] | 194 | static final boolean DEBUG_DRAG = false; |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 195 | static final boolean DEBUG_SCREEN_ON = false; |
Dianne Hackborn | cfb9f2b | 2011-08-24 10:51:49 -0700 | [diff] [blame] | 196 | static final boolean DEBUG_SCREENSHOT = false; |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 197 | static final boolean DEBUG_BOOT = false; |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 198 | static final boolean DEBUG_LAYOUT_REPEATS = true; |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 199 | static final boolean DEBUG_SURFACE_TRACE = false; |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 200 | static final boolean DEBUG_WINDOW_TRACE = false; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 201 | static final boolean SHOW_SURFACE_ALLOC = false; |
Craig Mautner | 343511c | 2012-02-28 17:30:50 -0800 | [diff] [blame] | 202 | static final boolean SHOW_TRANSACTIONS = false; |
Dianne Hackborn | 3699174 | 2011-10-11 21:35:26 -0700 | [diff] [blame] | 203 | static final boolean SHOW_LIGHT_TRANSACTIONS = false || SHOW_TRANSACTIONS; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 204 | static final boolean HIDE_STACK_CRAWLS = true; |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 205 | static final int LAYOUT_REPEAT_THRESHOLD = 4; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 206 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 207 | static final boolean PROFILE_ORIENTATION = false; |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 208 | static final boolean localLOGV = DEBUG; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 209 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | /** How much to multiply the policy's type layer, to reserve room |
| 211 | * for multiple windows of the same type and Z-ordering adjustment |
| 212 | * with TYPE_LAYER_OFFSET. */ |
| 213 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 214 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 216 | * or below others in the same layer. */ |
| 217 | static final int TYPE_LAYER_OFFSET = 1000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 218 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 219 | /** How much to increment the layer for each window, to reserve room |
| 220 | * for effect surfaces between them. |
| 221 | */ |
| 222 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 223 | |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 224 | /** |
| 225 | * Dim surface layer is immediately below target window. |
| 226 | */ |
| 227 | static final int LAYER_OFFSET_DIM = 1; |
| 228 | |
| 229 | /** |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 230 | * Blur surface layer is immediately below dim layer. |
| 231 | */ |
| 232 | static final int LAYER_OFFSET_BLUR = 2; |
| 233 | |
| 234 | /** |
| 235 | * Animation thumbnail is as far as possible below the window above |
| 236 | * the thumbnail (or in other words as far as possible above the window |
| 237 | * below it). |
| 238 | */ |
| 239 | static final int LAYER_OFFSET_THUMBNAIL = WINDOW_LAYER_MULTIPLIER-1; |
| 240 | |
| 241 | /** |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 242 | * Layer at which to put the rotation freeze snapshot. |
| 243 | */ |
| 244 | static final int FREEZE_LAYER = (TYPE_LAYER_MULTIPLIER * 200) + 1; |
| 245 | |
| 246 | /** |
| 247 | * Layer at which to put the mask for emulated screen sizes. |
| 248 | */ |
| 249 | static final int MASK_LAYER = TYPE_LAYER_MULTIPLIER * 200; |
| 250 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | /** The maximum length we will accept for a loaded animation duration: |
| 252 | * this is 10 seconds. |
| 253 | */ |
| 254 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 255 | |
| 256 | /** Amount of time (in milliseconds) to animate the dim surface from one |
| 257 | * value to another, when no window animation is driving it. |
| 258 | */ |
| 259 | static final int DEFAULT_DIM_DURATION = 200; |
| 260 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 261 | /** Amount of time (in milliseconds) to animate the fade-in-out transition for |
| 262 | * compatible windows. |
| 263 | */ |
| 264 | static final int DEFAULT_FADE_IN_OUT_DURATION = 400; |
| 265 | |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 266 | /** |
| 267 | * If true, the window manager will do its own custom freezing and general |
| 268 | * management of the screen during rotation. |
| 269 | */ |
| 270 | static final boolean CUSTOM_SCREEN_ROTATION = true; |
| 271 | |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 272 | // Maximum number of milliseconds to wait for input devices to be enumerated before |
| 273 | // proceding with safe mode detection. |
| 274 | private static final int INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS = 1000; |
Jim Miller | 28637ba | 2011-07-06 19:57:05 -0700 | [diff] [blame] | 275 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 276 | // Default input dispatching timeout in nanoseconds. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 277 | static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 278 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 279 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 280 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 281 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 282 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 283 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 284 | private static final String SYSTEM_SECURE = "ro.secure"; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 285 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | |
Craig Mautner | 5642a48 | 2012-08-23 12:16:53 -0700 | [diff] [blame] | 287 | final private KeyguardDisableHandler mKeyguardDisableHandler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 288 | |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 289 | private final boolean mHeadless; |
| 290 | |
Michael Jurka | c016aaa | 2012-06-05 17:22:24 -0700 | [diff] [blame] | 291 | private static final float THUMBNAIL_ANIMATION_DECELERATE_FACTOR = 1.5f; |
| 292 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 293 | final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 294 | @Override |
| 295 | public void onReceive(Context context, Intent intent) { |
Craig Mautner | 9dc52bc | 2012-08-06 14:15:42 -0700 | [diff] [blame] | 296 | final String action = intent.getAction(); |
| 297 | if (DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED.equals(action)) { |
Craig Mautner | 5642a48 | 2012-08-23 12:16:53 -0700 | [diff] [blame] | 298 | mKeyguardDisableHandler.sendEmptyMessage( |
| 299 | KeyguardDisableHandler.KEYGUARD_POLICY_CHANGED); |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | }; |
| 303 | |
Craig Mautner | 9dc52bc | 2012-08-06 14:15:42 -0700 | [diff] [blame] | 304 | // Current user when multi-user is enabled. Don't show windows of non-current user. |
| 305 | int mCurrentUserId; |
| 306 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 307 | final Context mContext; |
| 308 | |
| 309 | final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 310 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 311 | final boolean mAllowBootMessages; |
| 312 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | final boolean mLimitedAlphaCompositing; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 314 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 315 | final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 316 | |
| 317 | final IActivityManager mActivityManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 318 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | final IBatteryStats mBatteryStats; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 320 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 321 | /** |
| 322 | * All currently active sessions with clients. |
| 323 | */ |
| 324 | final HashSet<Session> mSessions = new HashSet<Session>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 325 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 326 | /** |
| 327 | * Mapping from an IWindow IBinder to the server's Window object. |
| 328 | * This is also used as the lock for all of our state. |
| 329 | */ |
| 330 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 331 | |
| 332 | /** |
| 333 | * Mapping from a token IBinder to a WindowToken object. |
| 334 | */ |
| 335 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 336 | new HashMap<IBinder, WindowToken>(); |
| 337 | |
| 338 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 339 | * Window tokens that are in the process of exiting, but still |
| 340 | * on screen for animations. |
| 341 | */ |
| 342 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 343 | |
| 344 | /** |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 345 | * List controlling the ordering of windows in different applications which must |
| 346 | * be kept in sync with ActivityManager. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | */ |
Craig Mautner | bec53f7 | 2012-04-05 11:49:05 -0700 | [diff] [blame] | 348 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 349 | |
| 350 | /** |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 351 | * AppWindowTokens in the Z order they were in at the start of an animation. Between |
| 352 | * animations this list is maintained in the exact order of mAppTokens. If tokens |
| 353 | * are added to mAppTokens during an animation an attempt is made to insert them at the same |
| 354 | * logical location in this list. Note that this list is always in sync with mWindows. |
| 355 | */ |
| 356 | ArrayList<AppWindowToken> mAnimatingAppTokens = new ArrayList<AppWindowToken>(); |
| 357 | |
| 358 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 359 | * Application tokens that are in the process of exiting, but still |
| 360 | * on screen for animations. |
| 361 | */ |
| 362 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 363 | |
| 364 | /** |
| 365 | * List of window tokens that have finished starting their application, |
| 366 | * and now need to have the policy remove their windows. |
| 367 | */ |
| 368 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 369 | |
| 370 | /** |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 371 | * Fake windows added to the window manager. Note: ordered from top to |
| 372 | * bottom, opposite of mWindows. |
| 373 | */ |
| 374 | final ArrayList<FakeWindowImpl> mFakeWindows = new ArrayList<FakeWindowImpl>(); |
| 375 | |
| 376 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 377 | * Windows that are being resized. Used so we can tell the client about |
| 378 | * the resize after closing the transaction in which we resized the |
| 379 | * underlying surface. |
| 380 | */ |
| 381 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 382 | |
| 383 | /** |
| 384 | * Windows whose animations have ended and now must be removed. |
| 385 | */ |
| 386 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 387 | |
| 388 | /** |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 389 | * Used when processing mPendingRemove to avoid working on the original array. |
| 390 | */ |
| 391 | WindowState[] mPendingRemoveTmp = new WindowState[20]; |
| 392 | |
| 393 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 394 | * Windows whose surface should be destroyed. |
| 395 | */ |
| 396 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 397 | |
| 398 | /** |
| 399 | * Windows that have lost input focus and are waiting for the new |
| 400 | * focus window to be displayed before they are told about this. |
| 401 | */ |
| 402 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 403 | |
| 404 | /** |
| 405 | * This is set when we have run out of memory, and will either be an empty |
| 406 | * list or contain windows that need to be force removed. |
| 407 | */ |
| 408 | ArrayList<WindowState> mForceRemoves; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 409 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 410 | /** |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 411 | * Windows that clients are waiting to have drawn. |
| 412 | */ |
| 413 | ArrayList<Pair<WindowState, IRemoteCallback>> mWaitingForDrawn |
| 414 | = new ArrayList<Pair<WindowState, IRemoteCallback>>(); |
| 415 | |
| 416 | /** |
Dianne Hackborn | 12d3a94 | 2012-04-27 14:16:30 -0700 | [diff] [blame] | 417 | * Windows that have called relayout() while we were running animations, |
| 418 | * so we need to tell when the animation is done. |
| 419 | */ |
| 420 | final ArrayList<WindowState> mRelayoutWhileAnimating = new ArrayList<WindowState>(); |
| 421 | |
| 422 | /** |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 423 | * Used when rebuilding window list to keep track of windows that have |
| 424 | * been removed. |
| 425 | */ |
| 426 | WindowState[] mRebuildTmp = new WindowState[20]; |
| 427 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 428 | IInputMethodManager mInputMethodManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 429 | |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 430 | final SurfaceSession mFxSession; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 431 | Watermark mWatermark; |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 432 | StrictModeFlash mStrictModeFlash; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 433 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 434 | final float[] mTmpFloats = new float[9]; |
| 435 | |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 436 | boolean mDisplayReady; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 437 | boolean mSafeMode; |
| 438 | boolean mDisplayEnabled = false; |
| 439 | boolean mSystemBooted = false; |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 440 | boolean mForceDisplayEnabled = false; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 441 | boolean mShowingBootMessages = false; |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 442 | |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 443 | String mLastANRState; |
| 444 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 445 | /** All DisplayDontents in the world, kept here */ |
| 446 | private SparseArray<DisplayContent> mDisplayContents = new SparseArray<DisplayContent>(); |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 447 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | int mRotation = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 449 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 450 | boolean mAltOrientation = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | ArrayList<IRotationWatcher> mRotationWatchers |
| 452 | = new ArrayList<IRotationWatcher>(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 453 | int mDeferredRotationPauseCount; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 454 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 455 | final Rect mSystemDecorRect = new Rect(); |
| 456 | int mSystemDecorLayer = 0; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 457 | final Rect mScreenRect = new Rect(); |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 458 | |
Dianne Hackborn | 8bcd54b | 2012-01-31 19:04:53 -0800 | [diff] [blame] | 459 | boolean mTraversalScheduled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 460 | boolean mDisplayFrozen = false; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 461 | boolean mWaitingForConfig = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 462 | boolean mWindowsFreezingScreen = false; |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 463 | boolean mClientFreezingScreen = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 464 | int mAppsFreezingScreen = 0; |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 465 | int mLastWindowForcedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 466 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 467 | int mLayoutSeq = 0; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 468 | |
| 469 | int mLastStatusBarVisibility = 0; |
| 470 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 471 | // State while inside of layoutAndPlaceSurfacesLocked(). |
| 472 | boolean mFocusMayChange; |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 473 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 474 | Configuration mCurConfiguration = new Configuration(); |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 475 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | // This is held as long as we have the screen frozen, to give us time to |
| 477 | // perform a rotation animation when turning off shows the lock screen which |
| 478 | // changes the orientation. |
| 479 | PowerManager.WakeLock mScreenFrozenLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 480 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 481 | // State management of app transitions. When we are preparing for a |
| 482 | // transition, mNextAppTransition will be the kind of transition to |
| 483 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 484 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 485 | // made visible or hidden at the next transition. |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 486 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 487 | int mNextAppTransitionType = ActivityOptions.ANIM_NONE; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 488 | String mNextAppTransitionPackage; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 489 | Bitmap mNextAppTransitionThumbnail; |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 490 | // Used for thumbnail transitions. True if we're scaling up, false if scaling down |
| 491 | boolean mNextAppTransitionScaleUp; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 492 | IRemoteCallback mNextAppTransitionCallback; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 493 | int mNextAppTransitionEnter; |
| 494 | int mNextAppTransitionExit; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 495 | int mNextAppTransitionStartX; |
| 496 | int mNextAppTransitionStartY; |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 497 | int mNextAppTransitionStartWidth; |
| 498 | int mNextAppTransitionStartHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 499 | boolean mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 500 | boolean mAppTransitionRunning = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 501 | boolean mAppTransitionTimeout = false; |
| 502 | boolean mStartingIconInTransition = false; |
| 503 | boolean mSkipAppTransitionAnimation = false; |
| 504 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 505 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 506 | |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 507 | boolean mIsTouchDevice; |
| 508 | |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 509 | final DisplayMetrics mDisplayMetrics = new DisplayMetrics(); |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 510 | final DisplayMetrics mRealDisplayMetrics = new DisplayMetrics(); |
Dianne Hackborn | 48a7651 | 2011-06-08 21:51:44 -0700 | [diff] [blame] | 511 | final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics(); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 512 | final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics(); |
| 513 | |
Dianne Hackborn | 8bcd54b | 2012-01-31 19:04:53 -0800 | [diff] [blame] | 514 | final H mH = new H(); |
| 515 | |
| 516 | final Choreographer mChoreographer = Choreographer.getInstance(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 517 | |
| 518 | WindowState mCurrentFocus = null; |
| 519 | WindowState mLastFocus = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 520 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 521 | /** This just indicates the window the input method is on top of, not |
| 522 | * necessarily the window its input is going to. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 523 | WindowState mInputMethodTarget = null; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 524 | |
| 525 | /** If true hold off on modifying the animation layer of mInputMethodTarget */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 526 | boolean mInputMethodTargetWaitingAnim; |
| 527 | int mInputMethodAnimLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 528 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 529 | WindowState mInputMethodWindow = null; |
| 530 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 531 | |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 532 | boolean mHardKeyboardAvailable; |
| 533 | boolean mHardKeyboardEnabled; |
| 534 | OnHardKeyboardStatusChangeListener mHardKeyboardStatusChangeListener; |
| 535 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 536 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 537 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 538 | // If non-null, this is the currently visible window that is associated |
| 539 | // with the wallpaper. |
| 540 | WindowState mWallpaperTarget = null; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 541 | // If non-null, we are in the middle of animating from one wallpaper target |
| 542 | // to another, and this is the lower one in Z-order. |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 543 | private WindowState mLowerWallpaperTarget = null; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 544 | // If non-null, we are in the middle of animating from one wallpaper target |
| 545 | // to another, and this is the higher one in Z-order. |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 546 | private WindowState mUpperWallpaperTarget = null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 547 | int mWallpaperAnimLayerAdjustment; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 548 | float mLastWallpaperX = -1; |
| 549 | float mLastWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 550 | float mLastWallpaperXStep = -1; |
| 551 | float mLastWallpaperYStep = -1; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 552 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 553 | // changing its scroll position. |
| 554 | WindowState mWaitingOnWallpaper; |
| 555 | // The last time we had a timeout when waiting for a wallpaper. |
| 556 | long mLastWallpaperTimeoutTime; |
| 557 | // We give a wallpaper up to 150ms to finish scrolling. |
| 558 | static final long WALLPAPER_TIMEOUT = 150; |
| 559 | // Time we wait after a timeout before trying to wait again. |
| 560 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 561 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 562 | AppWindowToken mFocusedApp = null; |
| 563 | |
| 564 | PowerManagerService mPowerManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 565 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 566 | float mWindowAnimationScale = 1.0f; |
| 567 | float mTransitionAnimationScale = 1.0f; |
Chet Haase | c38fa1f | 2012-02-01 16:37:46 -0800 | [diff] [blame] | 568 | float mAnimatorDurationScale = 1.0f; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 569 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 570 | final InputManagerService mInputManager; |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 571 | final DisplayManagerService mDisplayManagerService; |
| 572 | final DisplayManager mDisplayManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 573 | |
| 574 | // Who is holding the screen on. |
| 575 | Session mHoldingScreenOn; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 576 | PowerManager.WakeLock mHoldingScreenWakeLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 577 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 578 | boolean mTurnOnScreen; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 579 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 580 | DragState mDragState = null; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 581 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 582 | /** Pulled out of performLayoutAndPlaceSurfacesLockedInner in order to refactor into multiple |
| 583 | * methods. */ |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 584 | class LayoutFields { |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 585 | static final int SET_UPDATE_ROTATION = 1 << 0; |
| 586 | static final int SET_WALLPAPER_MAY_CHANGE = 1 << 1; |
| 587 | static final int SET_FORCE_HIDING_CHANGED = 1 << 2; |
Craig Mautner | 2639da5 | 2012-07-09 09:39:06 -0700 | [diff] [blame] | 588 | static final int SET_ORIENTATION_CHANGE_COMPLETE = 1 << 3; |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 589 | static final int SET_TURN_ON_SCREEN = 1 << 4; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 590 | |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 591 | boolean mWallpaperForceHidingChanged = false; |
| 592 | boolean mWallpaperMayChange = false; |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 593 | boolean mOrientationChangeComplete = true; |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 594 | int mAdjResult = 0; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 595 | private Session mHoldScreen = null; |
| 596 | private boolean mObscured = false; |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 597 | boolean mDimming = false; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 598 | private boolean mSyswin = false; |
| 599 | private float mScreenBrightness = -1; |
| 600 | private float mButtonBrightness = -1; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 601 | private boolean mUpdateRotation = false; |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 602 | |
| 603 | private static final int DISPLAY_CONTENT_UNKNOWN = 0; |
| 604 | private static final int DISPLAY_CONTENT_MIRROR = 1; |
| 605 | private static final int DISPLAY_CONTENT_UNIQUE = 2; |
| 606 | private int mDisplayHasContent = DISPLAY_CONTENT_UNKNOWN; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 607 | } |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 608 | final LayoutFields mInnerFields = new LayoutFields(); |
| 609 | |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 610 | static class AppWindowAnimParams { |
| 611 | AppWindowAnimator mAppAnimator; |
| 612 | ArrayList<WindowStateAnimator> mWinAnimators; |
| 613 | |
| 614 | public AppWindowAnimParams(final AppWindowAnimator appAnimator) { |
| 615 | mAppAnimator = appAnimator; |
| 616 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 617 | final AppWindowToken atoken = appAnimator.mAppToken; |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 618 | mWinAnimators = new ArrayList<WindowStateAnimator>(); |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 619 | final int N = atoken.allAppWindows.size(); |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 620 | for (int i = 0; i < N; i++) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 621 | mWinAnimators.add(atoken.allAppWindows.get(i).mWinAnimator); |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 622 | } |
| 623 | } |
| 624 | } |
| 625 | |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 626 | static class LayoutToAnimatorParams { |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 627 | boolean mParamsModified; |
| 628 | |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 629 | static final long WALLPAPER_TOKENS_CHANGED = 1 << 0; |
| 630 | long mChanges; |
| 631 | |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 632 | boolean mAnimationScheduled; |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 633 | SparseArray<WinAnimatorList> mWinAnimatorLists = new SparseArray<WinAnimatorList>(); |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 634 | WindowState mWallpaperTarget; |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 635 | WindowState mLowerWallpaperTarget; |
| 636 | WindowState mUpperWallpaperTarget; |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 637 | SparseArray<DimAnimator.Parameters> mDimParams = new SparseArray<DimAnimator.Parameters>(); |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 638 | ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 639 | ArrayList<AppWindowAnimParams> mAppWindowAnimParams = new ArrayList<AppWindowAnimParams>(); |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 640 | } |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 641 | /** Params from WindowManagerService to WindowAnimator. Do not modify or read without first |
| 642 | * locking on either mWindowMap or mAnimator and then on mLayoutToAnim */ |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 643 | final LayoutToAnimatorParams mLayoutToAnim = new LayoutToAnimatorParams(); |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 644 | |
| 645 | /** The lowest wallpaper target with a detached wallpaper animation on it. */ |
| 646 | WindowState mWindowDetachedWallpaper = null; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 647 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 648 | /** Skip repeated AppWindowTokens initialization. Note that AppWindowsToken's version of this |
| 649 | * is a long initialized to Long.MIN_VALUE so that it doesn't match this value on startup. */ |
| 650 | private int mTransactionSequence; |
| 651 | |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 652 | /** Only do a maximum of 6 repeated layouts. After that quit */ |
| 653 | private int mLayoutRepeatCount; |
| 654 | |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 655 | final WindowAnimator mAnimator; |
Jeff Brown | 4a06c80 | 2012-02-15 15:06:01 -0800 | [diff] [blame] | 656 | |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 657 | final class DragInputEventReceiver extends InputEventReceiver { |
| 658 | public DragInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 659 | super(inputChannel, looper); |
| 660 | } |
| 661 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 662 | @Override |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 663 | public void onInputEvent(InputEvent event) { |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 664 | boolean handled = false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 665 | try { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 666 | if (event instanceof MotionEvent |
| 667 | && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0 |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 668 | && mDragState != null) { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 669 | final MotionEvent motionEvent = (MotionEvent)event; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 670 | boolean endDrag = false; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 671 | final float newX = motionEvent.getRawX(); |
| 672 | final float newY = motionEvent.getRawY(); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 673 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 674 | switch (motionEvent.getAction()) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 675 | case MotionEvent.ACTION_DOWN: { |
| 676 | if (DEBUG_DRAG) { |
| 677 | Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer"); |
| 678 | } |
| 679 | } break; |
| 680 | |
| 681 | case MotionEvent.ACTION_MOVE: { |
| 682 | synchronized (mWindowMap) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 683 | // move the surface and tell the involved window(s) where we are |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 684 | mDragState.notifyMoveLw(newX, newY); |
| 685 | } |
| 686 | } break; |
| 687 | |
| 688 | case MotionEvent.ACTION_UP: { |
| 689 | if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at " |
| 690 | + newX + "," + newY); |
| 691 | synchronized (mWindowMap) { |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 692 | endDrag = mDragState.notifyDropLw(newX, newY); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 693 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 694 | } break; |
| 695 | |
| 696 | case MotionEvent.ACTION_CANCEL: { |
| 697 | if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!"); |
| 698 | endDrag = true; |
| 699 | } break; |
| 700 | } |
| 701 | |
| 702 | if (endDrag) { |
| 703 | if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state"); |
| 704 | // tell all the windows that the drag has ended |
Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 705 | synchronized (mWindowMap) { |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 706 | mDragState.endDragLw(); |
Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 707 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 708 | } |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 709 | |
| 710 | handled = true; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 711 | } |
| 712 | } catch (Exception e) { |
| 713 | Slog.e(TAG, "Exception caught by drag handleMotion", e); |
| 714 | } finally { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 715 | finishInputEvent(event, handled); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 716 | } |
| 717 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 718 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 719 | |
| 720 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 721 | * Whether the UI is currently running in touch mode (not showing |
| 722 | * navigational focus because the user is directly pressing the screen). |
| 723 | */ |
Michael Jurka | e99adc7 | 2011-08-11 18:28:01 -0700 | [diff] [blame] | 724 | boolean mInTouchMode = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 725 | |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 726 | // Temp regions for intermediary calculations. |
| 727 | private final Region mTempRegion = new Region(); |
| 728 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 729 | private ViewServer mViewServer; |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 730 | private ArrayList<WindowChangeListener> mWindowChangeListeners = |
| 731 | new ArrayList<WindowChangeListener>(); |
| 732 | private boolean mWindowsChanged = false; |
| 733 | |
| 734 | public interface WindowChangeListener { |
| 735 | public void windowsChanged(); |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 736 | public void focusChanged(); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 737 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 738 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 739 | final Configuration mTempConfiguration = new Configuration(); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 740 | |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 741 | // The desired scaling factor for compatible apps. |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 742 | float mCompatibleScreenScale; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 743 | |
Jeff Brown | 780c46f | 2012-06-24 12:15:38 -0700 | [diff] [blame] | 744 | // If true, only the core apps and services are being launched because the device |
| 745 | // is in a special boot mode, such as being encrypted or waiting for a decryption password. |
| 746 | // For example, when this flag is true, there will be no wallpaper service. |
| 747 | final boolean mOnlyCore; |
| 748 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 749 | public static WindowManagerService main(final Context context, |
| 750 | final PowerManagerService pm, final DisplayManagerService dm, |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 751 | final InputManagerService im, |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 752 | final Handler uiHandler, final Handler wmHandler, |
| 753 | final boolean haveInputMethods, final boolean showBootMsgs, |
| 754 | final boolean onlyCore) { |
| 755 | final WindowManagerService[] holder = new WindowManagerService[1]; |
| 756 | wmHandler.runWithScissors(new Runnable() { |
| 757 | @Override |
| 758 | public void run() { |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 759 | holder[0] = new WindowManagerService(context, pm, dm, im, |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 760 | uiHandler, haveInputMethods, showBootMsgs, onlyCore); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 761 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 762 | }, 0); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 763 | return holder[0]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 764 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 765 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 766 | private void initPolicy(Handler uiHandler) { |
| 767 | uiHandler.runWithScissors(new Runnable() { |
| 768 | @Override |
| 769 | public void run() { |
| 770 | WindowManagerPolicyThread.set(Thread.currentThread(), Looper.myLooper()); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 771 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 772 | mPolicy.init(mContext, WindowManagerService.this, WindowManagerService.this); |
| 773 | mAnimator.mAboveUniverseLayer = mPolicy.getAboveUniverseLayer() |
| 774 | * TYPE_LAYER_MULTIPLIER |
| 775 | + TYPE_LAYER_OFFSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 776 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 777 | }, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | private WindowManagerService(Context context, PowerManagerService pm, |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 781 | DisplayManagerService displayManager, InputManagerService inputManager, |
| 782 | Handler uiHandler, |
Jeff Brown | 780c46f | 2012-06-24 12:15:38 -0700 | [diff] [blame] | 783 | boolean haveInputMethods, boolean showBootMsgs, boolean onlyCore) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 784 | mContext = context; |
| 785 | mHaveInputMethods = haveInputMethods; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 786 | mAllowBootMessages = showBootMsgs; |
Jeff Brown | 780c46f | 2012-06-24 12:15:38 -0700 | [diff] [blame] | 787 | mOnlyCore = onlyCore; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 788 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 789 | com.android.internal.R.bool.config_sf_limitedAlpha); |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 790 | mDisplayManagerService = displayManager; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 791 | mHeadless = displayManager.isHeadless(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 792 | |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 793 | mDisplayManager = (DisplayManager)context.getSystemService(Context.DISPLAY_SERVICE); |
| 794 | mDisplayManager.registerDisplayListener(this, null); |
| 795 | Display[] displays = mDisplayManager.getDisplays(); |
| 796 | for (Display display : displays) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 797 | createDisplayContentLocked(display); |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 798 | } |
| 799 | |
Craig Mautner | 5642a48 | 2012-08-23 12:16:53 -0700 | [diff] [blame] | 800 | mKeyguardDisableHandler = new KeyguardDisableHandler(mContext, mPolicy); |
| 801 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 802 | mPowerManager = pm; |
| 803 | mPowerManager.setPolicy(mPolicy); |
| 804 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 805 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 806 | "SCREEN_FROZEN"); |
| 807 | mScreenFrozenLock.setReferenceCounted(false); |
| 808 | |
| 809 | mActivityManager = ActivityManagerNative.getDefault(); |
| 810 | mBatteryStats = BatteryStatsService.getService(); |
| 811 | |
| 812 | // Get persisted window scale setting |
| 813 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 814 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 815 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 816 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
Jeff Brown | ff7e6ef | 2012-08-15 02:05:18 -0700 | [diff] [blame] | 817 | setAnimatorDurationScale(Settings.System.getFloat(context.getContentResolver(), |
| 818 | Settings.System.ANIMATOR_DURATION_SCALE, mTransitionAnimationScale)); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 819 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 820 | // Track changes to DevicePolicyManager state so we can enable/disable keyguard. |
| 821 | IntentFilter filter = new IntentFilter(); |
| 822 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 823 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 824 | |
Dianne Hackborn | b80395c | 2012-06-14 19:38:20 -0700 | [diff] [blame] | 825 | mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK |
Craig Mautner | 259328c | 2012-08-21 19:30:58 -0700 | [diff] [blame] | 826 | | PowerManager.ON_AFTER_RELEASE, TAG); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 827 | mHoldingScreenWakeLock.setReferenceCounted(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 828 | |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 829 | mInputManager = inputManager; |
Craig Mautner | 9e80944 | 2012-06-22 17:13:04 -0700 | [diff] [blame] | 830 | mFxSession = new SurfaceSession(); |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 831 | mAnimator = new WindowAnimator(this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 832 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 833 | initPolicy(uiHandler); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 834 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 835 | // Add ourself to the Watchdog monitors. |
| 836 | Watchdog.getInstance().addMonitor(this); |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 837 | |
| 838 | Surface.openTransaction(); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 839 | try { |
| 840 | createWatermarkInTransaction(); |
| 841 | } finally { |
| 842 | Surface.closeTransaction(); |
| 843 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 844 | } |
| 845 | |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 846 | public InputMonitor getInputMonitor() { |
| 847 | return mInputMonitor; |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 848 | } |
| 849 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 850 | @Override |
| 851 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 852 | throws RemoteException { |
| 853 | try { |
| 854 | return super.onTransact(code, data, reply, flags); |
| 855 | } catch (RuntimeException e) { |
| 856 | // The window manager only throws security exceptions, so let's |
| 857 | // log all others. |
| 858 | if (!(e instanceof SecurityException)) { |
Dianne Hackborn | 8962028 | 2011-09-11 12:47:45 -0700 | [diff] [blame] | 859 | Log.wtf(TAG, "Window Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 860 | } |
| 861 | throw e; |
| 862 | } |
| 863 | } |
| 864 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 865 | private void placeWindowAfter(WindowState pos, WindowState window) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 866 | final WindowList windows = pos.getWindowList(); |
| 867 | final int i = windows.indexOf(pos); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 868 | 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] | 869 | TAG, "Adding window " + window + " at " |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 870 | + (i+1) + " of " + windows.size() + " (after " + pos + ")"); |
| 871 | windows.add(i+1, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 872 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 873 | } |
| 874 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 875 | private void placeWindowBefore(WindowState pos, WindowState window) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 876 | final WindowList windows = pos.getWindowList(); |
| 877 | final int i = windows.indexOf(pos); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 878 | 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] | 879 | TAG, "Adding window " + window + " at " |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 880 | + i + " of " + windows.size() + " (before " + pos + ")"); |
| 881 | windows.add(i, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 882 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | //This method finds out the index of a window that has the same app token as |
| 886 | //win. used for z ordering the windows in mWindows |
| 887 | private int findIdxBasedOnAppTokens(WindowState win) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 888 | WindowList windows = win.getWindowList(); |
| 889 | for(int j = windows.size() - 1; j >= 0; j--) { |
| 890 | WindowState wentry = windows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 891 | if(wentry.mAppToken == win.mAppToken) { |
| 892 | return j; |
| 893 | } |
| 894 | } |
| 895 | return -1; |
| 896 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 897 | |
Craig Mautner | efb735d | 2012-09-07 15:40:24 -0700 | [diff] [blame] | 898 | /** |
| 899 | * Return the list of Windows from the passed token on the given Display. |
| 900 | * @param token The token with all the windows. |
| 901 | * @param displayContent The display we are interested in. |
| 902 | * @return List of windows from token that are on displayContent. |
| 903 | */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 904 | WindowList getTokenWindowsOnDisplay(WindowToken token, DisplayContent displayContent) { |
| 905 | final WindowList windowList = new WindowList(); |
| 906 | final int count = token.windows.size(); |
| 907 | for (int i = 0; i < count; i++) { |
| 908 | final WindowState win = token.windows.get(i); |
| 909 | if (win.mDisplayContent == displayContent) { |
| 910 | windowList.add(win); |
| 911 | } |
| 912 | } |
| 913 | return windowList; |
| 914 | } |
| 915 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 916 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 917 | final IWindow client = win.mClient; |
| 918 | final WindowToken token = win.mToken; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 919 | final DisplayContent displayContent = win.mDisplayContent; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 920 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 921 | final WindowList windows = win.getWindowList(); |
| 922 | final int N = windows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 923 | final WindowState attached = win.mAttachedWindow; |
| 924 | int i; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 925 | WindowList tokenWindowList = getTokenWindowsOnDisplay(token, displayContent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 926 | if (attached == null) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 927 | int tokenWindowsPos = 0; |
| 928 | int windowListPos = tokenWindowList.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 929 | if (token.appWindowToken != null) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 930 | int index = windowListPos - 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 931 | if (index >= 0) { |
| 932 | // If this application has existing windows, we |
| 933 | // simply place the new window on top of them... but |
| 934 | // keep the starting window on top. |
| 935 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 936 | // Base windows go behind everything else. |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 937 | WindowState lowestWindow = tokenWindowList.get(0); |
| 938 | placeWindowBefore(lowestWindow, win); |
| 939 | tokenWindowsPos = token.windows.indexOf(lowestWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 940 | } else { |
| 941 | AppWindowToken atoken = win.mAppToken; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 942 | WindowState lastWindow = tokenWindowList.get(index); |
| 943 | if (atoken != null && lastWindow == atoken.startingWindow) { |
| 944 | placeWindowBefore(lastWindow, win); |
Craig Mautner | efb735d | 2012-09-07 15:40:24 -0700 | [diff] [blame] | 945 | tokenWindowsPos = token.windows.indexOf(lastWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 946 | } else { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 947 | int newIdx = findIdxBasedOnAppTokens(win); |
| 948 | //there is a window above this one associated with the same |
| 949 | //apptoken note that the window could be a floating window |
| 950 | //that was created later or a window at the top of the list of |
| 951 | //windows associated with this token. |
| 952 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 953 | Slog.v(TAG, "Adding window " + win + " at " |
Craig Mautner | efb735d | 2012-09-07 15:40:24 -0700 | [diff] [blame] | 954 | + (newIdx + 1) + " of " + N); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 955 | } |
Craig Mautner | efb735d | 2012-09-07 15:40:24 -0700 | [diff] [blame] | 956 | windows.add(newIdx + 1, win); |
| 957 | if (newIdx < 0) { |
| 958 | // No window from token found on win's display. |
| 959 | tokenWindowsPos = 0; |
| 960 | } else { |
| 961 | tokenWindowsPos = token.windows.indexOf(windows.get(newIdx)) + 1; |
| 962 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 963 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 964 | } |
| 965 | } |
| 966 | } else { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 967 | // No windows from this token on this display |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 968 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 969 | TAG, "Figuring out where to add app window " |
| 970 | + client.asBinder() + " (token=" + token + ")"); |
| 971 | // Figure out where the window should go, based on the |
| 972 | // order of applications. |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 973 | final int NA = mAnimatingAppTokens.size(); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 974 | WindowState pos = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 975 | for (i=NA-1; i>=0; i--) { |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 976 | AppWindowToken t = mAnimatingAppTokens.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 977 | if (t == token) { |
| 978 | i--; |
| 979 | break; |
| 980 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 981 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 982 | // We haven't reached the token yet; if this token |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 983 | // is not going to the bottom and has windows on this display, we can |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 984 | // use it as an anchor for when we do reach the token. |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 985 | tokenWindowList = getTokenWindowsOnDisplay(t, win.mDisplayContent); |
| 986 | if (!t.sendingToBottom && tokenWindowList.size() > 0) { |
| 987 | pos = tokenWindowList.get(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 988 | } |
| 989 | } |
| 990 | // We now know the index into the apps. If we found |
| 991 | // an app window above, that gives us the position; else |
| 992 | // we need to look some more. |
| 993 | if (pos != null) { |
| 994 | // Move behind any windows attached to this one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 995 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 996 | if (atoken != null) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 997 | tokenWindowList = |
| 998 | getTokenWindowsOnDisplay(atoken, win.mDisplayContent); |
| 999 | final int NC = tokenWindowList.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1000 | if (NC > 0) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 1001 | WindowState bottom = tokenWindowList.get(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1002 | if (bottom.mSubLayer < 0) { |
| 1003 | pos = bottom; |
| 1004 | } |
| 1005 | } |
| 1006 | } |
| 1007 | placeWindowBefore(pos, win); |
| 1008 | } else { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1009 | // Continue looking down until we find the first |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 1010 | // token that has windows on this display. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1011 | while (i >= 0) { |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 1012 | AppWindowToken t = mAnimatingAppTokens.get(i); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 1013 | tokenWindowList = getTokenWindowsOnDisplay(t, win.mDisplayContent); |
| 1014 | final int NW = tokenWindowList.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1015 | if (NW > 0) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 1016 | pos = tokenWindowList.get(NW-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1017 | break; |
| 1018 | } |
| 1019 | i--; |
| 1020 | } |
| 1021 | if (pos != null) { |
| 1022 | // Move in front of any windows attached to this |
| 1023 | // one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1024 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1025 | if (atoken != null) { |
| 1026 | final int NC = atoken.windows.size(); |
| 1027 | if (NC > 0) { |
| 1028 | WindowState top = atoken.windows.get(NC-1); |
| 1029 | if (top.mSubLayer >= 0) { |
| 1030 | pos = top; |
| 1031 | } |
| 1032 | } |
| 1033 | } |
| 1034 | placeWindowAfter(pos, win); |
| 1035 | } else { |
| 1036 | // Just search for the start of this layer. |
| 1037 | final int myLayer = win.mBaseLayer; |
| 1038 | for (i=0; i<N; i++) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1039 | WindowState w = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1040 | if (w.mBaseLayer > myLayer) { |
| 1041 | break; |
| 1042 | } |
| 1043 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1044 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 1045 | Slog.v(TAG, "Adding window " + win + " at " |
| 1046 | + i + " of " + N); |
| 1047 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1048 | windows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1049 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1050 | } |
| 1051 | } |
| 1052 | } |
| 1053 | } else { |
| 1054 | // Figure out where window should go, based on layer. |
| 1055 | final int myLayer = win.mBaseLayer; |
| 1056 | for (i=N-1; i>=0; i--) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1057 | if (windows.get(i).mBaseLayer <= myLayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1058 | break; |
| 1059 | } |
| 1060 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 1061 | i++; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1062 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1063 | TAG, "Adding window " + win + " at " |
| 1064 | + i + " of " + N); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1065 | windows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1066 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1067 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1068 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1069 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1070 | 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] | 1071 | token.windows.add(tokenWindowsPos, win); |
| 1072 | } |
| 1073 | |
| 1074 | } else { |
| 1075 | // Figure out this window's ordering relative to the window |
| 1076 | // it is attached to. |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 1077 | final int NA = tokenWindowList.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1078 | final int sublayer = win.mSubLayer; |
| 1079 | int largestSublayer = Integer.MIN_VALUE; |
| 1080 | WindowState windowWithLargestSublayer = null; |
| 1081 | for (i=0; i<NA; i++) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 1082 | WindowState w = tokenWindowList.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1083 | final int wSublayer = w.mSubLayer; |
| 1084 | if (wSublayer >= largestSublayer) { |
| 1085 | largestSublayer = wSublayer; |
| 1086 | windowWithLargestSublayer = w; |
| 1087 | } |
| 1088 | if (sublayer < 0) { |
| 1089 | // For negative sublayers, we go below all windows |
| 1090 | // in the same sublayer. |
| 1091 | if (wSublayer >= sublayer) { |
| 1092 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1093 | 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] | 1094 | token.windows.add(i, win); |
| 1095 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1096 | placeWindowBefore(wSublayer >= 0 ? attached : w, win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1097 | break; |
| 1098 | } |
| 1099 | } else { |
| 1100 | // For positive sublayers, we go above all windows |
| 1101 | // in the same sublayer. |
| 1102 | if (wSublayer > sublayer) { |
| 1103 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1104 | 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] | 1105 | token.windows.add(i, win); |
| 1106 | } |
| 1107 | placeWindowBefore(w, win); |
| 1108 | break; |
| 1109 | } |
| 1110 | } |
| 1111 | } |
| 1112 | if (i >= NA) { |
| 1113 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1114 | 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] | 1115 | token.windows.add(win); |
| 1116 | } |
| 1117 | if (sublayer < 0) { |
| 1118 | placeWindowBefore(attached, win); |
| 1119 | } else { |
| 1120 | placeWindowAfter(largestSublayer >= 0 |
| 1121 | ? windowWithLargestSublayer |
| 1122 | : attached, |
| 1123 | win); |
| 1124 | } |
| 1125 | } |
| 1126 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1127 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1128 | if (win.mAppToken != null && addToToken) { |
| 1129 | win.mAppToken.allAppWindows.add(win); |
| 1130 | } |
| 1131 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1132 | |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 1133 | /** TODO(cmautner): Is this the same as {@link WindowState#canReceiveKeys()} */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1134 | static boolean canBeImeTarget(WindowState w) { |
| 1135 | final int fl = w.mAttrs.flags |
| 1136 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1137 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM) |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 1138 | || w.mAttrs.type == TYPE_APPLICATION_STARTING) { |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1139 | if (DEBUG_INPUT_METHOD) { |
| 1140 | Slog.i(TAG, "isVisibleOrAdding " + w + ": " + w.isVisibleOrAdding()); |
| 1141 | if (!w.isVisibleOrAdding()) { |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 1142 | Slog.i(TAG, " mSurface=" + w.mWinAnimator.mSurface |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1143 | + " relayoutCalled=" + w.mRelayoutCalled + " viewVis=" + w.mViewVisibility |
Dianne Hackborn | ac92087 | 2012-05-22 11:49:49 -0700 | [diff] [blame] | 1144 | + " policyVis=" + w.mPolicyVisibility |
| 1145 | + " policyVisAfterAnim=" + w.mPolicyVisibilityAfterAnim |
| 1146 | + " attachHid=" + w.mAttachedHidden |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1147 | + " exiting=" + w.mExiting + " destroying=" + w.mDestroying); |
| 1148 | if (w.mAppToken != null) { |
| 1149 | Slog.i(TAG, " mAppToken.hiddenRequested=" + w.mAppToken.hiddenRequested); |
| 1150 | } |
| 1151 | } |
| 1152 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1153 | return w.isVisibleOrAdding(); |
| 1154 | } |
| 1155 | return false; |
| 1156 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1157 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 1158 | /** |
| 1159 | * Dig through the WindowStates and find the one that the Input Method will target. |
| 1160 | * @param willMove |
| 1161 | * @return The index+1 in mWindows of the discovered target. |
| 1162 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1163 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1164 | // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the |
| 1165 | // same display. Or even when the current IME/target are not on the same screen as the next |
| 1166 | // IME/target. For now only look for input windows on the main screen. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 1167 | WindowList windows = getDefaultWindowListLocked(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1168 | final int N = windows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1169 | WindowState w = null; |
| 1170 | int i = N; |
| 1171 | while (i > 0) { |
| 1172 | i--; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1173 | w = windows.get(i); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1174 | |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1175 | if (DEBUG_INPUT_METHOD && willMove) Slog.i(TAG, "Checking window @" + i |
| 1176 | + " " + w + " fl=0x" + Integer.toHexString(w.mAttrs.flags)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1177 | if (canBeImeTarget(w)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1178 | //Slog.i(TAG, "Putting input method here!"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1179 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1180 | // Yet more tricksyness! If this window is a "starting" |
| 1181 | // window, we do actually want to be on top of it, but |
| 1182 | // it is not -really- where input will go. So if the caller |
| 1183 | // is not actually looking to move the IME, look down below |
| 1184 | // for a real window to target... |
| 1185 | if (!willMove |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 1186 | && w.mAttrs.type == TYPE_APPLICATION_STARTING |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1187 | && i > 0) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1188 | WindowState wb = windows.get(i-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1189 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 1190 | i--; |
| 1191 | w = wb; |
| 1192 | } |
| 1193 | } |
| 1194 | break; |
| 1195 | } |
| 1196 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1197 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 1198 | // Now w is either mWindows[0] or an IME (or null if mWindows is empty). |
| 1199 | |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1200 | if (DEBUG_INPUT_METHOD && willMove) Slog.v(TAG, "Proposed new IME target: " + w); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 1201 | |
Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1202 | // Now, a special case -- if the last target's window is in the |
| 1203 | // process of exiting, and is above the new target, keep on the |
| 1204 | // last target to avoid flicker. Consider for example a Dialog with |
| 1205 | // the IME shown: when the Dialog is dismissed, we want to keep |
| 1206 | // the IME above it until it is completely gone so it doesn't drop |
| 1207 | // behind the dialog or its full-screen scrim. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1208 | final WindowState curTarget = mInputMethodTarget; |
| 1209 | if (curTarget != null && w != null |
| 1210 | && curTarget.isDisplayedLw() |
| 1211 | && curTarget.mExiting) { |
| 1212 | if (curTarget.mWinAnimator.mAnimLayer > w.mWinAnimator.mAnimLayer) { |
| 1213 | w = curTarget; |
| 1214 | i = windows.indexOf(w); |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1215 | 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] | 1216 | } |
| 1217 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1218 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1219 | 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] | 1220 | + w + " willMove=" + willMove); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1221 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1222 | if (willMove && w != null) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1223 | AppWindowToken token = curTarget == null ? null : curTarget.mAppToken; |
| 1224 | if (token != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1225 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1226 | // Now some fun for dealing with window animations that |
| 1227 | // modify the Z order. We need to look at all windows below |
| 1228 | // the current target that are in this app, finding the highest |
| 1229 | // visible one in layering. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1230 | WindowState highestTarget = null; |
| 1231 | int highestPos = 0; |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1232 | if (token.mAppAnimator.animating || token.mAppAnimator.animation != null) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1233 | WindowList curWindows = curTarget.getWindowList(); |
| 1234 | int pos = curWindows.indexOf(curTarget); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1235 | while (pos >= 0) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1236 | WindowState win = curWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1237 | if (win.mAppToken != token) { |
| 1238 | break; |
| 1239 | } |
| 1240 | if (!win.mRemoved) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1241 | if (highestTarget == null || win.mWinAnimator.mAnimLayer > |
| 1242 | highestTarget.mWinAnimator.mAnimLayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1243 | highestTarget = win; |
| 1244 | highestPos = pos; |
| 1245 | } |
| 1246 | } |
| 1247 | pos--; |
| 1248 | } |
| 1249 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1250 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1251 | if (highestTarget != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1252 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1253 | + mNextAppTransition + " " + highestTarget |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1254 | + " animating=" + highestTarget.mWinAnimator.isAnimating() |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1255 | + " layer=" + highestTarget.mWinAnimator.mAnimLayer |
| 1256 | + " new layer=" + w.mWinAnimator.mAnimLayer); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1257 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1258 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1259 | // If we are currently setting up for an animation, |
| 1260 | // hold everything until we can find out what will happen. |
| 1261 | mInputMethodTargetWaitingAnim = true; |
| 1262 | mInputMethodTarget = highestTarget; |
| 1263 | return highestPos + 1; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1264 | } else if (highestTarget.mWinAnimator.isAnimating() && |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1265 | highestTarget.mWinAnimator.mAnimLayer > w.mWinAnimator.mAnimLayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1266 | // If the window we are currently targeting is involved |
| 1267 | // with an animation, and it is on top of the next target |
| 1268 | // we will be over, then hold off on moving until |
| 1269 | // that is done. |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1270 | mInputMethodTargetWaitingAnim = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1271 | mInputMethodTarget = highestTarget; |
| 1272 | return highestPos + 1; |
| 1273 | } |
| 1274 | } |
| 1275 | } |
| 1276 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1277 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1278 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1279 | if (w != null) { |
| 1280 | if (willMove) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1281 | if (DEBUG_INPUT_METHOD) Slog.w(TAG, "Moving IM target from " + curTarget + " to " |
| 1282 | + w + (HIDE_STACK_CRAWLS ? "" : " Callers=" + Debug.getCallers(4))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1283 | mInputMethodTarget = w; |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1284 | mInputMethodTargetWaitingAnim = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1285 | if (w.mAppToken != null) { |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1286 | setInputMethodAnimLayerAdjustment(w.mAppToken.mAppAnimator.animLayerAdjustment); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1287 | } else { |
| 1288 | setInputMethodAnimLayerAdjustment(0); |
| 1289 | } |
| 1290 | } |
| 1291 | return i+1; |
| 1292 | } |
| 1293 | if (willMove) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1294 | if (DEBUG_INPUT_METHOD) Slog.w(TAG, "Moving IM target from " + curTarget + " to null." |
| 1295 | + (HIDE_STACK_CRAWLS ? "" : " Callers=" + Debug.getCallers(4))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1296 | mInputMethodTarget = null; |
| 1297 | setInputMethodAnimLayerAdjustment(0); |
| 1298 | } |
| 1299 | return -1; |
| 1300 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1301 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1302 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1303 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1304 | if (pos >= 0) { |
| 1305 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1306 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1307 | TAG, "Adding input method window " + win + " at " + pos); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1308 | // TODO(multidisplay): IMEs are only supported on the default display. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 1309 | getDefaultWindowListLocked().add(pos, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1310 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1311 | moveInputMethodDialogsLocked(pos+1); |
| 1312 | return; |
| 1313 | } |
| 1314 | win.mTargetAppToken = null; |
| 1315 | addWindowToListInOrderLocked(win, true); |
| 1316 | moveInputMethodDialogsLocked(pos); |
| 1317 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1318 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1319 | void setInputMethodAnimLayerAdjustment(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1320 | 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] | 1321 | mInputMethodAnimLayerAdjustment = adj; |
| 1322 | WindowState imw = mInputMethodWindow; |
| 1323 | if (imw != null) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1324 | imw.mWinAnimator.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1325 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1326 | + " anim layer: " + imw.mWinAnimator.mAnimLayer); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1327 | int wi = imw.mChildWindows.size(); |
| 1328 | while (wi > 0) { |
| 1329 | wi--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1330 | WindowState cw = imw.mChildWindows.get(wi); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1331 | cw.mWinAnimator.mAnimLayer = cw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1332 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1333 | + " anim layer: " + cw.mWinAnimator.mAnimLayer); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1334 | } |
| 1335 | } |
| 1336 | int di = mInputMethodDialogs.size(); |
| 1337 | while (di > 0) { |
| 1338 | di --; |
| 1339 | imw = mInputMethodDialogs.get(di); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1340 | imw.mWinAnimator.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1341 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1342 | + " anim layer: " + imw.mWinAnimator.mAnimLayer); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1343 | } |
| 1344 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1345 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1346 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1347 | WindowList windows = win.getWindowList(); |
| 1348 | int wpos = windows.indexOf(win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1349 | if (wpos >= 0) { |
| 1350 | if (wpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1351 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1352 | windows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1353 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1354 | int NC = win.mChildWindows.size(); |
| 1355 | while (NC > 0) { |
| 1356 | NC--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1357 | WindowState cw = win.mChildWindows.get(NC); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1358 | int cpos = windows.indexOf(cw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1359 | if (cpos >= 0) { |
| 1360 | if (cpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1361 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1362 | + cpos + ": " + cw); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1363 | windows.remove(cpos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1364 | } |
| 1365 | } |
| 1366 | } |
| 1367 | return interestingPos; |
| 1368 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1369 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1370 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1371 | addWindowToListInOrderLocked(win, false); |
| 1372 | // This is a hack to get all of the child windows added as well |
| 1373 | // at the right position. Child windows should be rare and |
| 1374 | // this case should be rare, so it shouldn't be that big a deal. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1375 | WindowList windows = win.getWindowList(); |
| 1376 | int wpos = windows.indexOf(win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1377 | if (wpos >= 0) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1378 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos + ": " + win); |
| 1379 | windows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1380 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1381 | reAddWindowLocked(wpos, win); |
| 1382 | } |
| 1383 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1384 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1385 | void logWindowList(final WindowList windows, String prefix) { |
| 1386 | int N = windows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1387 | while (N > 0) { |
| 1388 | N--; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1389 | Slog.v(TAG, prefix + "#" + N + ": " + windows.get(N)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1390 | } |
| 1391 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1392 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1393 | void moveInputMethodDialogsLocked(int pos) { |
| 1394 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1395 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1396 | // TODO(multidisplay): IMEs are only supported on the default display. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 1397 | WindowList windows = getDefaultWindowListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1398 | final int N = dialogs.size(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1399 | 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] | 1400 | for (int i=0; i<N; i++) { |
| 1401 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1402 | } |
| 1403 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1404 | Slog.v(TAG, "Window list w/pos=" + pos); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1405 | logWindowList(windows, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1406 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1407 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1408 | if (pos >= 0) { |
| 1409 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1410 | if (pos < windows.size()) { |
| 1411 | WindowState wp = windows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1412 | if (wp == mInputMethodWindow) { |
| 1413 | pos++; |
| 1414 | } |
| 1415 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1416 | 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] | 1417 | for (int i=0; i<N; i++) { |
| 1418 | WindowState win = dialogs.get(i); |
| 1419 | win.mTargetAppToken = targetAppToken; |
| 1420 | pos = reAddWindowLocked(pos, win); |
| 1421 | } |
| 1422 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1423 | Slog.v(TAG, "Final window list:"); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1424 | logWindowList(windows, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1425 | } |
| 1426 | return; |
| 1427 | } |
| 1428 | for (int i=0; i<N; i++) { |
| 1429 | WindowState win = dialogs.get(i); |
| 1430 | win.mTargetAppToken = null; |
| 1431 | reAddWindowToListInOrderLocked(win); |
| 1432 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1433 | Slog.v(TAG, "No IM target, final list:"); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1434 | logWindowList(windows, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1435 | } |
| 1436 | } |
| 1437 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1438 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1439 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1440 | final WindowState imWin = mInputMethodWindow; |
| 1441 | final int DN = mInputMethodDialogs.size(); |
| 1442 | if (imWin == null && DN == 0) { |
| 1443 | return false; |
| 1444 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1445 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1446 | // TODO(multidisplay): IMEs are only supported on the default display. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 1447 | WindowList windows = getDefaultWindowListLocked(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1448 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1449 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1450 | if (imPos >= 0) { |
| 1451 | // In this case, the input method windows are to be placed |
| 1452 | // immediately above the window they are targeting. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1453 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1454 | // First check to see if the input method windows are already |
| 1455 | // located here, and contiguous. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1456 | final int N = windows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1457 | WindowState firstImWin = imPos < N |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1458 | ? windows.get(imPos) : null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1459 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1460 | // Figure out the actual input method window that should be |
| 1461 | // at the bottom of their stack. |
| 1462 | WindowState baseImWin = imWin != null |
| 1463 | ? imWin : mInputMethodDialogs.get(0); |
| 1464 | if (baseImWin.mChildWindows.size() > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1465 | WindowState cw = baseImWin.mChildWindows.get(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1466 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1467 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1468 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1469 | if (firstImWin == baseImWin) { |
| 1470 | // The windows haven't moved... but are they still contiguous? |
| 1471 | // First find the top IM window. |
| 1472 | int pos = imPos+1; |
| 1473 | while (pos < N) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1474 | if (!(windows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1475 | break; |
| 1476 | } |
| 1477 | pos++; |
| 1478 | } |
| 1479 | pos++; |
| 1480 | // Now there should be no more input method windows above. |
| 1481 | while (pos < N) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1482 | if ((windows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1483 | break; |
| 1484 | } |
| 1485 | pos++; |
| 1486 | } |
| 1487 | if (pos >= N) { |
| 1488 | // All is good! |
| 1489 | return false; |
| 1490 | } |
| 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 | if (imWin != null) { |
| 1494 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1495 | Slog.v(TAG, "Moving IM from " + imPos); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1496 | logWindowList(windows, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1497 | } |
| 1498 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1499 | if (DEBUG_INPUT_METHOD) { |
Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1500 | Slog.v(TAG, "List after removing with new pos " + imPos + ":"); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1501 | logWindowList(windows, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1502 | } |
| 1503 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1504 | reAddWindowLocked(imPos, imWin); |
| 1505 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1506 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1507 | logWindowList(windows, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1508 | } |
| 1509 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1510 | } else { |
| 1511 | moveInputMethodDialogsLocked(imPos); |
| 1512 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1513 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1514 | } else { |
| 1515 | // In this case, the input method windows go in a fixed layer, |
| 1516 | // because they aren't currently associated with a focus window. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1517 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1518 | if (imWin != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1519 | 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] | 1520 | tmpRemoveWindowLocked(0, imWin); |
| 1521 | imWin.mTargetAppToken = null; |
| 1522 | reAddWindowToListInOrderLocked(imWin); |
| 1523 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1524 | Slog.v(TAG, "List with no IM target:"); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1525 | logWindowList(windows, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1526 | } |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 1527 | if (DN > 0) moveInputMethodDialogsLocked(-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1528 | } else { |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 1529 | moveInputMethodDialogsLocked(-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1530 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1531 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1532 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1533 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1534 | if (needAssignLayers) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1535 | assignLayersLocked(windows); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1536 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1537 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1538 | return true; |
| 1539 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1540 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1541 | void adjustInputMethodDialogsLocked() { |
| 1542 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1543 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1544 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1545 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
Craig Mautner | ad3a9bb | 2012-03-09 11:31:06 -0800 | [diff] [blame] | 1546 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target " + wallpaperTarget + ", obscured=" |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1547 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1548 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1549 | ? wallpaperTarget.mAppToken.mAppAnimator.animation : null) |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1550 | + " upper=" + mUpperWallpaperTarget |
| 1551 | + " lower=" + mLowerWallpaperTarget); |
| 1552 | return (wallpaperTarget != null |
| 1553 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1554 | && wallpaperTarget.mAppToken.mAppAnimator.animation != null))) |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1555 | || mUpperWallpaperTarget != null |
| 1556 | || mLowerWallpaperTarget != null; |
| 1557 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1558 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1559 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1560 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1561 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1562 | int adjustWallpaperWindowsLocked() { |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 1563 | mInnerFields.mWallpaperMayChange = false; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1564 | int changed = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1565 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1566 | // TODO(multidisplay): Wallpapers on main screen only. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 1567 | final DisplayInfo displayInfo = getDefaultDisplayContentLocked().getDisplayInfo(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1568 | final int dw = displayInfo.appWidth; |
| 1569 | final int dh = displayInfo.appHeight; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1570 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1571 | // First find top-most window that has asked to be on top of the |
| 1572 | // wallpaper; all wallpapers go behind it. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 1573 | final WindowList windows = getDefaultWindowListLocked(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1574 | int N = windows.size(); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1575 | WindowState w = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1576 | WindowState foundW = null; |
| 1577 | int foundI = 0; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1578 | WindowState topCurW = null; |
| 1579 | int topCurI = 0; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1580 | int windowDetachedI = -1; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1581 | int i = N; |
| 1582 | while (i > 0) { |
| 1583 | i--; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1584 | w = windows.get(i); |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 1585 | if ((w.mAttrs.type == TYPE_WALLPAPER)) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1586 | if (topCurW == null) { |
| 1587 | topCurW = w; |
| 1588 | topCurI = i; |
| 1589 | } |
| 1590 | continue; |
| 1591 | } |
| 1592 | topCurW = null; |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 1593 | if (w != mWindowDetachedWallpaper && w.mAppToken != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1594 | // If this window's app token is hidden and not animating, |
| 1595 | // it is of no interest to us. |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1596 | if (w.mAppToken.hidden && w.mAppToken.mAppAnimator.animation == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1597 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Craig Mautner | 1d961d4 | 2012-05-27 12:02:11 -0700 | [diff] [blame] | 1598 | "Skipping hidden and not animating token: " + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1599 | continue; |
| 1600 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1601 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1602 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win #" + i + " " + w + ": readyfordisplay=" |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 1603 | + w.isReadyForDisplay() + " mDrawState=" + w.mWinAnimator.mDrawState); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1604 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
Craig Mautner | bf90eaa | 2012-03-15 11:28:53 -0700 | [diff] [blame] | 1605 | && (mWallpaperTarget == w || w.isDrawnLw())) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1606 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1607 | "Found wallpaper activity: #" + i + "=" + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1608 | foundW = w; |
| 1609 | foundI = i; |
Craig Mautner | 4d7349b | 2012-04-20 14:52:47 -0700 | [diff] [blame] | 1610 | if (w == mWallpaperTarget && w.mWinAnimator.isAnimating()) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1611 | // The current wallpaper target is animating, so we'll |
| 1612 | // look behind it for another possible target and figure |
| 1613 | // out what is going on below. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1614 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1615 | + ": token animating, looking behind."); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1616 | continue; |
| 1617 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1618 | break; |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 1619 | } else if (w == mWindowDetachedWallpaper) { |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1620 | windowDetachedI = i; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1621 | } |
| 1622 | } |
| 1623 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1624 | if (foundW == null && windowDetachedI >= 0) { |
| 1625 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 1626 | "Found animating detached wallpaper activity: #" + i + "=" + w); |
| 1627 | foundW = w; |
| 1628 | foundI = windowDetachedI; |
| 1629 | } |
| 1630 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1631 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1632 | // If we are currently waiting for an app transition, and either |
| 1633 | // the current target or the next target are involved with it, |
| 1634 | // then hold off on doing anything with the wallpaper. |
| 1635 | // Note that we are checking here for just whether the target |
| 1636 | // is part of an app token... which is potentially overly aggressive |
| 1637 | // (the app token may not be involved in the transition), but good |
| 1638 | // enough (we'll just wait until whatever transition is pending |
| 1639 | // executes). |
| 1640 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1641 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1642 | "Wallpaper not changing: waiting for app anim in current target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1643 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1644 | } |
| 1645 | if (foundW != null && foundW.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1646 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1647 | "Wallpaper not changing: waiting for app anim in found target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1648 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1649 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1650 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1651 | |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 1652 | if (mWallpaperTarget != foundW |
| 1653 | && (mLowerWallpaperTarget == null || mLowerWallpaperTarget != foundW)) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1654 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1655 | Slog.v(TAG, "New wallpaper target: " + foundW |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1656 | + " oldTarget: " + mWallpaperTarget); |
| 1657 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1658 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1659 | mLowerWallpaperTarget = null; |
| 1660 | mUpperWallpaperTarget = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1661 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1662 | WindowState oldW = mWallpaperTarget; |
| 1663 | mWallpaperTarget = foundW; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1664 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1665 | // Now what is happening... if the current and new targets are |
| 1666 | // animating, then we are in our super special mode! |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1667 | if (foundW != null && oldW != null) { |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1668 | boolean oldAnim = oldW.mWinAnimator.mAnimation != null |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1669 | || (oldW.mAppToken != null |
| 1670 | && oldW.mAppToken.mAppAnimator.animation != null); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1671 | boolean foundAnim = foundW.mWinAnimator.mAnimation != null |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1672 | || (foundW.mAppToken != null && |
| 1673 | foundW.mAppToken.mAppAnimator.animation != null); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1674 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1675 | Slog.v(TAG, "New animation: " + foundAnim |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1676 | + " old animation: " + oldAnim); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1677 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1678 | if (foundAnim && oldAnim) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1679 | int oldI = windows.indexOf(oldW); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1680 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1681 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1682 | } |
| 1683 | if (oldI >= 0) { |
| 1684 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1685 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1686 | + "=" + oldW + "; new#" + foundI |
| 1687 | + "=" + foundW); |
| 1688 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1689 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1690 | // Set the new target correctly. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1691 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1692 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1693 | Slog.v(TAG, "Old wallpaper still the target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1694 | } |
| 1695 | mWallpaperTarget = oldW; |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1696 | foundW = oldW; |
| 1697 | foundI = oldI; |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 1698 | } |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1699 | // Now set the upper and lower wallpaper targets |
| 1700 | // correctly, and make sure that we are positioning |
| 1701 | // the wallpaper below the lower. |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1702 | else if (foundI > oldI) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1703 | // The new target is on top of the old one. |
| 1704 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1705 | Slog.v(TAG, "Found target above old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1706 | } |
| 1707 | mUpperWallpaperTarget = foundW; |
| 1708 | mLowerWallpaperTarget = oldW; |
| 1709 | foundW = oldW; |
| 1710 | foundI = oldI; |
| 1711 | } else { |
| 1712 | // The new target is below the old one. |
| 1713 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1714 | Slog.v(TAG, "Found target below old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1715 | } |
| 1716 | mUpperWallpaperTarget = oldW; |
| 1717 | mLowerWallpaperTarget = foundW; |
| 1718 | } |
| 1719 | } |
| 1720 | } |
| 1721 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1722 | |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1723 | } else if (mLowerWallpaperTarget != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1724 | // Is it time to stop animating? |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1725 | boolean lowerAnimating = mLowerWallpaperTarget.mWinAnimator.mAnimation != null |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1726 | || (mLowerWallpaperTarget.mAppToken != null |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1727 | && mLowerWallpaperTarget.mAppToken.mAppAnimator.animation != null); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1728 | boolean upperAnimating = mUpperWallpaperTarget.mWinAnimator.mAnimation != null |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1729 | || (mUpperWallpaperTarget.mAppToken != null |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1730 | && mUpperWallpaperTarget.mAppToken.mAppAnimator.animation != null); |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1731 | if (!lowerAnimating || !upperAnimating) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1732 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1733 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1734 | } |
| 1735 | mLowerWallpaperTarget = null; |
| 1736 | mUpperWallpaperTarget = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1737 | } |
| 1738 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1739 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1740 | boolean visible = foundW != null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1741 | if (visible) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1742 | // The window is visible to the compositor... but is it visible |
| 1743 | // to the user? That is what the wallpaper cares about. |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1744 | visible = isWallpaperVisible(foundW); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1745 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1746 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1747 | // If the wallpaper target is animating, we may need to copy |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1748 | // its layer adjustment. Only do this if we are not transfering |
| 1749 | // between two wallpaper targets. |
| 1750 | mWallpaperAnimLayerAdjustment = |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1751 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1752 | ? foundW.mAppToken.mAppAnimator.animLayerAdjustment : 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1753 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1754 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1755 | * TYPE_LAYER_MULTIPLIER |
| 1756 | + TYPE_LAYER_OFFSET; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1757 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1758 | // Now w is the window we are supposed to be behind... but we |
| 1759 | // 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] | 1760 | // AND any starting window associated with it, AND below the |
| 1761 | // maximum layer the policy allows for wallpapers. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1762 | while (foundI > 0) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1763 | WindowState wb = windows.get(foundI-1); |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1764 | if (wb.mBaseLayer < maxLayer && |
| 1765 | wb.mAttachedWindow != foundW && |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 1766 | (foundW.mAttachedWindow == null || |
| 1767 | wb.mAttachedWindow != foundW.mAttachedWindow) && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1768 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 1769 | foundW.mToken == null || wb.mToken != foundW.mToken)) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1770 | // This window is not related to the previous one in any |
| 1771 | // interesting way, so stop here. |
| 1772 | break; |
| 1773 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1774 | foundW = wb; |
| 1775 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1776 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1777 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1778 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1779 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1780 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1781 | if (foundW == null && topCurW != null) { |
| 1782 | // There is no wallpaper target, so it goes at the bottom. |
| 1783 | // We will assume it is the same place as last time, if known. |
| 1784 | foundW = topCurW; |
| 1785 | foundI = topCurI+1; |
| 1786 | } else { |
| 1787 | // Okay i is the position immediately above the wallpaper. Look at |
| 1788 | // what is below it for later. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1789 | foundW = foundI > 0 ? windows.get(foundI-1) : null; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1790 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1791 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1792 | if (visible) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1793 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1794 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1795 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1796 | } |
| 1797 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1798 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1799 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1800 | } |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1801 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1802 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1803 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1804 | // are correctly placed. |
| 1805 | int curTokenIndex = mWallpaperTokens.size(); |
| 1806 | while (curTokenIndex > 0) { |
| 1807 | curTokenIndex--; |
| 1808 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1809 | if (token.hidden == visible) { |
| 1810 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1811 | token.hidden = !visible; |
| 1812 | // Need to do a layout to ensure the wallpaper now has the |
| 1813 | // correct size. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 1814 | getDefaultDisplayContentLocked().layoutNeeded = true; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1815 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1816 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1817 | int curWallpaperIndex = token.windows.size(); |
| 1818 | while (curWallpaperIndex > 0) { |
| 1819 | curWallpaperIndex--; |
| 1820 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1821 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1822 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1823 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1824 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1825 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1826 | // First, make sure the client has the current visibility |
| 1827 | // state. |
Craig Mautner | 507a2ee | 2012-06-13 08:39:38 -0700 | [diff] [blame] | 1828 | dispatchWallpaperVisibility(wallpaper, visible); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1829 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1830 | wallpaper.mWinAnimator.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 1831 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "adjustWallpaper win " |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1832 | + wallpaper + " anim layer: " + wallpaper.mWinAnimator.mAnimLayer); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1833 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1834 | // First, if this window is at the current index, then all |
| 1835 | // is well. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1836 | if (wallpaper == foundW) { |
| 1837 | foundI--; |
| 1838 | foundW = foundI > 0 |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1839 | ? windows.get(foundI-1) : null; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1840 | continue; |
| 1841 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1842 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1843 | // The window didn't match... the current wallpaper window, |
| 1844 | // wherever it is, is in the wrong place, so make sure it is |
| 1845 | // not in the list. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1846 | int oldIndex = windows.indexOf(wallpaper); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1847 | if (oldIndex >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1848 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1849 | + oldIndex + ": " + wallpaper); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1850 | windows.remove(oldIndex); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1851 | mWindowsChanged = true; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1852 | if (oldIndex < foundI) { |
| 1853 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1854 | } |
| 1855 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1856 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1857 | // Now stick it in. |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1858 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 1859 | Slog.v(TAG, "Moving wallpaper " + wallpaper |
| 1860 | + " from " + oldIndex + " to " + foundI); |
| 1861 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1862 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1863 | windows.add(foundI, wallpaper); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1864 | mWindowsChanged = true; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1865 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1866 | } |
| 1867 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1868 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1869 | return changed; |
| 1870 | } |
| 1871 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1872 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1873 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1874 | "Setting wallpaper layer adj to " + adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1875 | mWallpaperAnimLayerAdjustment = adj; |
| 1876 | int curTokenIndex = mWallpaperTokens.size(); |
| 1877 | while (curTokenIndex > 0) { |
| 1878 | curTokenIndex--; |
| 1879 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1880 | int curWallpaperIndex = token.windows.size(); |
| 1881 | while (curWallpaperIndex > 0) { |
| 1882 | curWallpaperIndex--; |
| 1883 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1884 | wallpaper.mWinAnimator.mAnimLayer = wallpaper.mLayer + adj; |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 1885 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "setWallpaper win " |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1886 | + wallpaper + " anim layer: " + wallpaper.mWinAnimator.mAnimLayer); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1887 | } |
| 1888 | } |
| 1889 | } |
| 1890 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1891 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 1892 | boolean sync) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1893 | boolean changed = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1894 | boolean rawChanged = false; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1895 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1896 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 1897 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1898 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 1899 | changed = wallpaperWin.mXOffset != offset; |
| 1900 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1901 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1902 | + wallpaperWin + " x: " + offset); |
| 1903 | wallpaperWin.mXOffset = offset; |
| 1904 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1905 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1906 | wallpaperWin.mWallpaperX = wpx; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1907 | wallpaperWin.mWallpaperXStep = wpxs; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1908 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1909 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1910 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1911 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1912 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1913 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 1914 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 1915 | if (wallpaperWin.mYOffset != offset) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1916 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1917 | + wallpaperWin + " y: " + offset); |
| 1918 | changed = true; |
| 1919 | wallpaperWin.mYOffset = offset; |
| 1920 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1921 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1922 | wallpaperWin.mWallpaperY = wpy; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1923 | wallpaperWin.mWallpaperYStep = wpys; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1924 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1925 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1926 | |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 1927 | if (rawChanged && (wallpaperWin.mAttrs.privateFlags & |
Chet Haase | a8e5a2b | 2011-10-28 13:18:16 -0700 | [diff] [blame] | 1928 | WindowManager.LayoutParams.PRIVATE_FLAG_WANTS_OFFSET_NOTIFICATIONS) != 0) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1929 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1930 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1931 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 1932 | + " y=" + wallpaperWin.mWallpaperY); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1933 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1934 | mWaitingOnWallpaper = wallpaperWin; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1935 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1936 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1937 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 1938 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1939 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1940 | if (mWaitingOnWallpaper != null) { |
| 1941 | long start = SystemClock.uptimeMillis(); |
| 1942 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 1943 | < start) { |
| 1944 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1945 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1946 | "Waiting for offset complete..."); |
| 1947 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 1948 | } catch (InterruptedException e) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1949 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1950 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1951 | if ((start+WALLPAPER_TIMEOUT) |
| 1952 | < SystemClock.uptimeMillis()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1953 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1954 | + wallpaperWin); |
| 1955 | mLastWallpaperTimeoutTime = start; |
| 1956 | } |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1957 | } |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1958 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1959 | } |
| 1960 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1961 | } catch (RemoteException e) { |
| 1962 | } |
| 1963 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1964 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1965 | return changed; |
| 1966 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1967 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1968 | void wallpaperOffsetsComplete(IBinder window) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1969 | synchronized (mWindowMap) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1970 | if (mWaitingOnWallpaper != null && |
| 1971 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 1972 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1973 | mWindowMap.notifyAll(); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1974 | } |
| 1975 | } |
| 1976 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1977 | |
Chet Haase | a8e5a2b | 2011-10-28 13:18:16 -0700 | [diff] [blame] | 1978 | void updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1979 | final DisplayContent displayContent = changingTarget.mDisplayContent; |
| 1980 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
| 1981 | final int dw = displayInfo.appWidth; |
| 1982 | final int dh = displayInfo.appHeight; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1983 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1984 | WindowState target = mWallpaperTarget; |
| 1985 | if (target != null) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1986 | if (target.mWallpaperX >= 0) { |
| 1987 | mLastWallpaperX = target.mWallpaperX; |
| 1988 | } else if (changingTarget.mWallpaperX >= 0) { |
| 1989 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 1990 | } |
| 1991 | if (target.mWallpaperY >= 0) { |
| 1992 | mLastWallpaperY = target.mWallpaperY; |
| 1993 | } else if (changingTarget.mWallpaperY >= 0) { |
| 1994 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 1995 | } |
| 1996 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1997 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1998 | int curTokenIndex = mWallpaperTokens.size(); |
| 1999 | while (curTokenIndex > 0) { |
| 2000 | curTokenIndex--; |
| 2001 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2002 | int curWallpaperIndex = token.windows.size(); |
| 2003 | while (curWallpaperIndex > 0) { |
| 2004 | curWallpaperIndex--; |
| 2005 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2006 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2007 | WindowStateAnimator winAnimator = wallpaper.mWinAnimator; |
| 2008 | winAnimator.computeShownFrameLocked(); |
Chet Haase | a8e5a2b | 2011-10-28 13:18:16 -0700 | [diff] [blame] | 2009 | // No need to lay out the windows - we can just set the wallpaper position |
| 2010 | // directly. |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 2011 | // TODO(cmautner): Don't move this from here, just lock the WindowAnimator. |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2012 | if (winAnimator.mSurfaceX != wallpaper.mShownFrame.left |
| 2013 | || winAnimator.mSurfaceY != wallpaper.mShownFrame.top) { |
Craig Mautner | 12670b5 | 2012-07-03 19:15:35 -0700 | [diff] [blame] | 2014 | winAnimator.setWallpaperOffset((int) wallpaper.mShownFrame.left, |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 2015 | (int) wallpaper.mShownFrame.top); |
Chet Haase | a8e5a2b | 2011-10-28 13:18:16 -0700 | [diff] [blame] | 2016 | } |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2017 | // We only want to be synchronous with one wallpaper. |
| 2018 | sync = false; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2019 | } |
| 2020 | } |
| 2021 | } |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2022 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2023 | |
Craig Mautner | 507a2ee | 2012-06-13 08:39:38 -0700 | [diff] [blame] | 2024 | /** |
| 2025 | * Check wallpaper for visiblity change and notify window if so. |
| 2026 | * @param wallpaper The wallpaper to test and notify. |
| 2027 | * @param visible Current visibility. |
| 2028 | */ |
| 2029 | void dispatchWallpaperVisibility(final WindowState wallpaper, final boolean visible) { |
| 2030 | if (wallpaper.mWallpaperVisible != visible) { |
| 2031 | wallpaper.mWallpaperVisible = visible; |
| 2032 | try { |
| 2033 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| 2034 | "Updating visibility of wallpaper " + wallpaper |
| 2035 | + ": " + visible + " Callers=" + Debug.getCallers(2)); |
| 2036 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 2037 | } catch (RemoteException e) { |
| 2038 | } |
| 2039 | } |
| 2040 | } |
| 2041 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2042 | void updateWallpaperVisibilityLocked() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2043 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2044 | final DisplayContent displayContent = mWallpaperTarget.mDisplayContent; |
| 2045 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
| 2046 | final int dw = displayInfo.appWidth; |
| 2047 | final int dh = displayInfo.appHeight; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2048 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2049 | int curTokenIndex = mWallpaperTokens.size(); |
| 2050 | while (curTokenIndex > 0) { |
| 2051 | curTokenIndex--; |
| 2052 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2053 | if (token.hidden == visible) { |
| 2054 | token.hidden = !visible; |
| 2055 | // Need to do a layout to ensure the wallpaper now has the |
| 2056 | // correct size. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 2057 | getDefaultDisplayContentLocked().layoutNeeded = true; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2058 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2059 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2060 | int curWallpaperIndex = token.windows.size(); |
| 2061 | while (curWallpaperIndex > 0) { |
| 2062 | curWallpaperIndex--; |
| 2063 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2064 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2065 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2066 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2067 | |
Craig Mautner | 507a2ee | 2012-06-13 08:39:38 -0700 | [diff] [blame] | 2068 | dispatchWallpaperVisibility(wallpaper, visible); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2069 | } |
| 2070 | } |
| 2071 | } |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 2072 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2073 | public int addWindow(Session session, IWindow client, int seq, |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 2074 | WindowManager.LayoutParams attrs, int viewVisibility, int displayId, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2075 | Rect outContentInsets, InputChannel outInputChannel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2076 | int res = mPolicy.checkAddPermission(attrs); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2077 | if (res != WindowManagerGlobal.ADD_OKAY) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2078 | return res; |
| 2079 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2080 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2081 | boolean reportNewConfig = false; |
| 2082 | WindowState attachedWindow = null; |
| 2083 | WindowState win = null; |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2084 | long origId; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2085 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2086 | synchronized(mWindowMap) { |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 2087 | if (!mDisplayReady) { |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2088 | throw new IllegalStateException("Display has not been initialialized"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2089 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2090 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2091 | if (mWindowMap.containsKey(client.asBinder())) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2092 | Slog.w(TAG, "Window " + client + " is already added"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2093 | return WindowManagerGlobal.ADD_DUPLICATE_ADD; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2094 | } |
| 2095 | |
| 2096 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2097 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2098 | if (attachedWindow == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2099 | 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] | 2100 | + attrs.token + ". Aborting."); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2101 | return WindowManagerGlobal.ADD_BAD_SUBWINDOW_TOKEN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2102 | } |
| 2103 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 2104 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2105 | 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] | 2106 | + attrs.token + ". Aborting."); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2107 | return WindowManagerGlobal.ADD_BAD_SUBWINDOW_TOKEN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2108 | } |
| 2109 | } |
| 2110 | |
| 2111 | boolean addToken = false; |
| 2112 | WindowToken token = mTokenMap.get(attrs.token); |
| 2113 | if (token == null) { |
| 2114 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2115 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2116 | 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] | 2117 | + attrs.token + ". Aborting."); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2118 | return WindowManagerGlobal.ADD_BAD_APP_TOKEN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2119 | } |
| 2120 | if (attrs.type == TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2121 | 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] | 2122 | + attrs.token + ". Aborting."); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2123 | return WindowManagerGlobal.ADD_BAD_APP_TOKEN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2124 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2125 | if (attrs.type == TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2126 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2127 | + attrs.token + ". Aborting."); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2128 | return WindowManagerGlobal.ADD_BAD_APP_TOKEN; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2129 | } |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 2130 | if (attrs.type == TYPE_DREAM) { |
| 2131 | Slog.w(TAG, "Attempted to add Dream window with unknown token " |
| 2132 | + attrs.token + ". Aborting."); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2133 | return WindowManagerGlobal.ADD_BAD_APP_TOKEN; |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 2134 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2135 | token = new WindowToken(this, attrs.token, -1, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2136 | addToken = true; |
| 2137 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2138 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 2139 | AppWindowToken atoken = token.appWindowToken; |
| 2140 | if (atoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2141 | 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] | 2142 | + token + ". Aborting."); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2143 | return WindowManagerGlobal.ADD_NOT_APP_TOKEN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2144 | } else if (atoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2145 | 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] | 2146 | + token + ". Aborting."); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2147 | return WindowManagerGlobal.ADD_APP_EXITING; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2148 | } |
| 2149 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 2150 | // No need for this guy! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2151 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2152 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2153 | return WindowManagerGlobal.ADD_STARTING_NOT_NEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2154 | } |
| 2155 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 2156 | if (token.windowType != TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2157 | 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] | 2158 | + attrs.token + ". Aborting."); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2159 | return WindowManagerGlobal.ADD_BAD_APP_TOKEN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2160 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2161 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 2162 | if (token.windowType != TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2163 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2164 | + attrs.token + ". Aborting."); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2165 | return WindowManagerGlobal.ADD_BAD_APP_TOKEN; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2166 | } |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 2167 | } else if (attrs.type == TYPE_DREAM) { |
| 2168 | if (token.windowType != TYPE_DREAM) { |
| 2169 | Slog.w(TAG, "Attempted to add Dream window with bad token " |
| 2170 | + attrs.token + ". Aborting."); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2171 | return WindowManagerGlobal.ADD_BAD_APP_TOKEN; |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 2172 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2173 | } |
| 2174 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 2175 | final DisplayContent displayContent = getDisplayContentLocked(displayId); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2176 | win = new WindowState(this, session, client, token, |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2177 | attachedWindow, seq, attrs, viewVisibility, displayContent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2178 | if (win.mDeathRecipient == null) { |
| 2179 | // Client has apparently died, so there is no reason to |
| 2180 | // continue. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2181 | Slog.w(TAG, "Adding window client " + client.asBinder() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2182 | + " that is dead, aborting."); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2183 | return WindowManagerGlobal.ADD_APP_EXITING; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2184 | } |
| 2185 | |
| 2186 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2187 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2188 | res = mPolicy.prepareAddWindowLw(win, attrs); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2189 | if (res != WindowManagerGlobal.ADD_OKAY) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2190 | return res; |
| 2191 | } |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 2192 | |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2193 | if (outInputChannel != null && (attrs.inputFeatures |
| 2194 | & WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL) == 0) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2195 | String name = win.makeInputChannelName(); |
| 2196 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2197 | win.setInputChannel(inputChannels[0]); |
Jeff Brown | 0a0ab12 | 2011-08-12 18:08:08 -0700 | [diff] [blame] | 2198 | inputChannels[1].transferTo(outInputChannel); |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 2199 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 2200 | mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2201 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2202 | |
| 2203 | // From now on, no exceptions or errors allowed! |
| 2204 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2205 | res = WindowManagerGlobal.ADD_OKAY; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2206 | |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2207 | origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2208 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2209 | if (addToken) { |
| 2210 | mTokenMap.put(attrs.token, token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2211 | } |
| 2212 | win.attach(); |
| 2213 | mWindowMap.put(client.asBinder(), win); |
| 2214 | |
| 2215 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 2216 | token.appWindowToken != null) { |
| 2217 | token.appWindowToken.startingWindow = win; |
Craig Mautner | 38b2478 | 2012-07-02 16:21:28 -0700 | [diff] [blame] | 2218 | if (DEBUG_STARTING_WINDOW) Slog.v (TAG, "addWindow: " + token.appWindowToken |
| 2219 | + " startingWindow=" + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2220 | } |
| 2221 | |
| 2222 | boolean imMayMove = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2223 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2224 | if (attrs.type == TYPE_INPUT_METHOD) { |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 2225 | win.mGivenInsetsPending = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2226 | mInputMethodWindow = win; |
| 2227 | addInputMethodWindowToListLocked(win); |
| 2228 | imMayMove = false; |
| 2229 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2230 | mInputMethodDialogs.add(win); |
| 2231 | addWindowToListInOrderLocked(win, true); |
| 2232 | adjustInputMethodDialogsLocked(); |
| 2233 | imMayMove = false; |
| 2234 | } else { |
| 2235 | addWindowToListInOrderLocked(win, true); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2236 | if (attrs.type == TYPE_WALLPAPER) { |
| 2237 | mLastWallpaperTimeoutTime = 0; |
| 2238 | adjustWallpaperWindowsLocked(); |
| 2239 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2240 | adjustWallpaperWindowsLocked(); |
| 2241 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2242 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2243 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2244 | win.mWinAnimator.mEnterAnimationPending = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2245 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2246 | if (displayContent.isDefaultDisplay) { |
| 2247 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
| 2248 | } else { |
| 2249 | outContentInsets.setEmpty(); |
| 2250 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2251 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2252 | if (mInTouchMode) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2253 | res |= WindowManagerGlobal.ADD_FLAG_IN_TOUCH_MODE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2254 | } |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 2255 | if (win.mAppToken == null || !win.mAppToken.clientHidden) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2256 | res |= WindowManagerGlobal.ADD_FLAG_APP_VISIBLE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2257 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2258 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2259 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 2260 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2261 | boolean focusChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2262 | if (win.canReceiveKeys()) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2263 | focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS, |
| 2264 | false /*updateInputWindows*/); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2265 | if (focusChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2266 | imMayMove = false; |
| 2267 | } |
| 2268 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2269 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2270 | if (imMayMove) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2271 | moveInputMethodWindowsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2272 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2273 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2274 | assignLayersLocked(displayContent.getWindowList()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2275 | // Don't do layout here, the window must call |
| 2276 | // relayout to be displayed, so we'll do it there. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2277 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2278 | //dump(); |
| 2279 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2280 | if (focusChanged) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2281 | finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2282 | } |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2283 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2284 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2285 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2286 | TAG, "New client " + client.asBinder() |
| 2287 | + ": window=" + win); |
Craig Mautner | 9e80944 | 2012-06-22 17:13:04 -0700 | [diff] [blame] | 2288 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2289 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2290 | reportNewConfig = true; |
| 2291 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2292 | } |
| 2293 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2294 | if (reportNewConfig) { |
| 2295 | sendNewConfiguration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2296 | } |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2297 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2298 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2299 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2300 | return res; |
| 2301 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2302 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2303 | public void removeWindow(Session session, IWindow client) { |
| 2304 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2305 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2306 | if (win == null) { |
| 2307 | return; |
| 2308 | } |
| 2309 | removeWindowLocked(session, win); |
| 2310 | } |
| 2311 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2312 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2313 | public void removeWindowLocked(Session session, WindowState win) { |
| 2314 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2315 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2316 | TAG, "Remove " + win + " client=" |
| 2317 | + Integer.toHexString(System.identityHashCode( |
| 2318 | win.mClient.asBinder())) |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2319 | + ", surface=" + win.mWinAnimator.mSurface); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2320 | |
| 2321 | final long origId = Binder.clearCallingIdentity(); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 2322 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2323 | win.disposeInputChannel(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2324 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2325 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2326 | TAG, "Remove " + win + ": mSurface=" + win.mWinAnimator.mSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2327 | + " mExiting=" + win.mExiting |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 2328 | + " isAnimating=" + win.mWinAnimator.isAnimating() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2329 | + " app-animation=" |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 2330 | + (win.mAppToken != null ? win.mAppToken.mAppAnimator.animation : null) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2331 | + " inPendingTransaction=" |
| 2332 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2333 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2334 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2335 | boolean wasVisible = false; |
| 2336 | // First, see if we need to run an animation. If we do, we have |
| 2337 | // to hold off on removing the window until the animation is done. |
| 2338 | // If the display is frozen, just remove immediately, since the |
| 2339 | // animation wouldn't be seen. |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 2340 | if (win.mHasSurface && okToDisplay()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2341 | // If we are not currently running the exit animation, we |
| 2342 | // need to see about starting one. |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 2343 | wasVisible = win.isWinVisibleLw(); |
| 2344 | if (wasVisible) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2345 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2346 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 2347 | if (win.mAttrs.type == TYPE_APPLICATION_STARTING) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2348 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2349 | } |
| 2350 | // Try starting an animation. |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2351 | if (win.mWinAnimator.applyAnimationLocked(transit, false)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2352 | win.mExiting = true; |
| 2353 | } |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 2354 | scheduleNotifyWindowTranstionIfNeededLocked(win, transit); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2355 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 2356 | if (win.mExiting || win.mWinAnimator.isAnimating()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2357 | // The exit animation is running... wait for it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2358 | //Slog.i(TAG, "*** Running exit animation..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2359 | win.mExiting = true; |
| 2360 | win.mRemoveOnExit = true; |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 2361 | win.mDisplayContent.layoutNeeded = true; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2362 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 2363 | false /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2364 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2365 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2366 | if (win.mAppToken != null) { |
| 2367 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2368 | } |
| 2369 | //dump(); |
| 2370 | Binder.restoreCallingIdentity(origId); |
| 2371 | return; |
| 2372 | } |
| 2373 | } |
| 2374 | |
| 2375 | removeWindowInnerLocked(session, win); |
| 2376 | // Removing a visible window will effect the computed orientation |
| 2377 | // So just update orientation if needed. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2378 | if (wasVisible && computeForcedAppOrientationLocked() |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2379 | != mForcedAppOrientation |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2380 | && updateOrientationFromAppTokensLocked(false)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2381 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2382 | } |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2383 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2384 | Binder.restoreCallingIdentity(origId); |
| 2385 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2386 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2387 | private void removeWindowInnerLocked(Session session, WindowState win) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2388 | if (win.mRemoved) { |
| 2389 | // Nothing to do. |
| 2390 | return; |
| 2391 | } |
| 2392 | |
| 2393 | for (int i=win.mChildWindows.size()-1; i>=0; i--) { |
| 2394 | WindowState cwin = win.mChildWindows.get(i); |
| 2395 | Slog.w(TAG, "Force-removing child win " + cwin + " from container " |
| 2396 | + win); |
| 2397 | removeWindowInnerLocked(cwin.mSession, cwin); |
| 2398 | } |
| 2399 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2400 | win.mRemoved = 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 | if (mInputMethodTarget == win) { |
| 2403 | moveInputMethodWindowsIfNeededLocked(false); |
| 2404 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2405 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2406 | if (false) { |
| 2407 | RuntimeException e = new RuntimeException("here"); |
| 2408 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2409 | Slog.w(TAG, "Removing window " + win, e); |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2410 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2411 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2412 | mPolicy.removeWindowLw(win); |
| 2413 | win.removeLocked(); |
| 2414 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2415 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2416 | mWindowMap.remove(win.mClient.asBinder()); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2417 | |
| 2418 | final WindowList windows = win.getWindowList(); |
| 2419 | windows.remove(win); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2420 | mPendingRemove.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2421 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2422 | 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] | 2423 | |
| 2424 | if (mInputMethodWindow == win) { |
| 2425 | mInputMethodWindow = null; |
| 2426 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2427 | mInputMethodDialogs.remove(win); |
| 2428 | } |
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 | final WindowToken token = win.mToken; |
| 2431 | final AppWindowToken atoken = win.mAppToken; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2432 | 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] | 2433 | token.windows.remove(win); |
| 2434 | if (atoken != null) { |
| 2435 | atoken.allAppWindows.remove(win); |
| 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, "**** Removing window " + win + ": count=" |
| 2439 | + token.windows.size()); |
| 2440 | if (token.windows.size() == 0) { |
| 2441 | if (!token.explicit) { |
| 2442 | mTokenMap.remove(token.token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2443 | } else if (atoken != null) { |
| 2444 | atoken.firstWindowDrawn = false; |
| 2445 | } |
| 2446 | } |
| 2447 | |
| 2448 | if (atoken != null) { |
| 2449 | if (atoken.startingWindow == win) { |
Craig Mautner | 38b2478 | 2012-07-02 16:21:28 -0700 | [diff] [blame] | 2450 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Nulling startingWindow " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2451 | atoken.startingWindow = null; |
| 2452 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2453 | // If this is the last window and we had requested a starting |
| 2454 | // transition window, well there is no point now. |
Craig Mautner | 38b2478 | 2012-07-02 16:21:28 -0700 | [diff] [blame] | 2455 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Nulling last startingWindow"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2456 | atoken.startingData = null; |
| 2457 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2458 | // If this is the last window except for a starting transition |
| 2459 | // window, we need to get rid of the starting transition. |
| 2460 | if (DEBUG_STARTING_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2461 | Slog.v(TAG, "Schedule remove starting " + token |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2462 | + ": no more real windows"); |
| 2463 | } |
| 2464 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2465 | mH.sendMessage(m); |
| 2466 | } |
| 2467 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2468 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2469 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2470 | mLastWallpaperTimeoutTime = 0; |
| 2471 | adjustWallpaperWindowsLocked(); |
| 2472 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2473 | adjustWallpaperWindowsLocked(); |
| 2474 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2475 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2476 | if (!mInLayout) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2477 | assignLayersLocked(windows); |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 2478 | win.mDisplayContent.layoutNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2479 | performLayoutAndPlaceSurfacesLocked(); |
| 2480 | if (win.mAppToken != null) { |
| 2481 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2482 | } |
| 2483 | } |
Craig Mautner | 9e80944 | 2012-06-22 17:13:04 -0700 | [diff] [blame] | 2484 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2485 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2486 | } |
| 2487 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2488 | static void logSurface(WindowState w, String msg, RuntimeException where) { |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 2489 | String str = " SURFACE " + msg + ": " + w; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2490 | if (where != null) { |
| 2491 | Slog.i(TAG, str, where); |
| 2492 | } else { |
| 2493 | Slog.i(TAG, str); |
| 2494 | } |
| 2495 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2496 | |
| 2497 | static void logSurface(Surface s, String title, String msg, RuntimeException where) { |
| 2498 | String str = " SURFACE " + s + ": " + msg + " / " + title; |
| 2499 | if (where != null) { |
| 2500 | Slog.i(TAG, str, where); |
| 2501 | } else { |
| 2502 | Slog.i(TAG, str); |
| 2503 | } |
| 2504 | } |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 2505 | |
| 2506 | // TODO(cmautner): Move to WindowStateAnimator. |
| 2507 | void setTransparentRegionHint(final WindowStateAnimator winAnimator, final Region region) { |
| 2508 | mH.sendMessage(mH.obtainMessage(H.SET_TRANSPARENT_REGION, |
| 2509 | new Pair<WindowStateAnimator, Region>(winAnimator, region))); |
| 2510 | } |
| 2511 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2512 | void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2513 | long origId = Binder.clearCallingIdentity(); |
| 2514 | try { |
| 2515 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2516 | WindowState w = windowForClientLocked(session, client, false); |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 2517 | if ((w != null) && w.mHasSurface) { |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 2518 | setTransparentRegionHint(w.mWinAnimator, region); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2519 | } |
| 2520 | } |
| 2521 | } finally { |
| 2522 | Binder.restoreCallingIdentity(origId); |
| 2523 | } |
| 2524 | } |
| 2525 | |
| 2526 | void setInsetsWindow(Session session, IWindow client, |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2527 | int touchableInsets, Rect contentInsets, |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2528 | Rect visibleInsets, Region touchableRegion) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2529 | long origId = Binder.clearCallingIdentity(); |
| 2530 | try { |
| 2531 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2532 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2533 | if (w != null) { |
| 2534 | w.mGivenInsetsPending = false; |
| 2535 | w.mGivenContentInsets.set(contentInsets); |
| 2536 | w.mGivenVisibleInsets.set(visibleInsets); |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2537 | w.mGivenTouchableRegion.set(touchableRegion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2538 | w.mTouchableInsets = touchableInsets; |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 2539 | if (w.mGlobalScale != 1) { |
| 2540 | w.mGivenContentInsets.scale(w.mGlobalScale); |
| 2541 | w.mGivenVisibleInsets.scale(w.mGlobalScale); |
| 2542 | w.mGivenTouchableRegion.scale(w.mGlobalScale); |
| 2543 | } |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 2544 | w.mDisplayContent.layoutNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2545 | performLayoutAndPlaceSurfacesLocked(); |
| 2546 | } |
| 2547 | } |
| 2548 | } finally { |
| 2549 | Binder.restoreCallingIdentity(origId); |
| 2550 | } |
| 2551 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2552 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2553 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2554 | Rect outDisplayFrame) { |
| 2555 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2556 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2557 | if (win == null) { |
| 2558 | outDisplayFrame.setEmpty(); |
| 2559 | return; |
| 2560 | } |
| 2561 | outDisplayFrame.set(win.mDisplayFrame); |
| 2562 | } |
| 2563 | } |
| 2564 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2565 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2566 | float xStep, float yStep) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2567 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2568 | window.mWallpaperX = x; |
| 2569 | window.mWallpaperY = y; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2570 | window.mWallpaperXStep = xStep; |
| 2571 | window.mWallpaperYStep = yStep; |
Chet Haase | a8e5a2b | 2011-10-28 13:18:16 -0700 | [diff] [blame] | 2572 | updateWallpaperOffsetLocked(window, true); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2573 | } |
| 2574 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2575 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2576 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2577 | synchronized (mWindowMap) { |
| 2578 | if (mWaitingOnWallpaper != null && |
| 2579 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2580 | mWaitingOnWallpaper = null; |
| 2581 | mWindowMap.notifyAll(); |
| 2582 | } |
| 2583 | } |
| 2584 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2585 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2586 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2587 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2588 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2589 | || window == mUpperWallpaperTarget) { |
| 2590 | boolean doWait = sync; |
| 2591 | int curTokenIndex = mWallpaperTokens.size(); |
| 2592 | while (curTokenIndex > 0) { |
| 2593 | curTokenIndex--; |
| 2594 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2595 | int curWallpaperIndex = token.windows.size(); |
| 2596 | while (curWallpaperIndex > 0) { |
| 2597 | curWallpaperIndex--; |
| 2598 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2599 | try { |
| 2600 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2601 | x, y, z, extras, sync); |
| 2602 | // We only want to be synchronous with one wallpaper. |
| 2603 | sync = false; |
| 2604 | } catch (RemoteException e) { |
| 2605 | } |
| 2606 | } |
| 2607 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2608 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2609 | if (doWait) { |
| 2610 | // XXX Need to wait for result. |
| 2611 | } |
| 2612 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2613 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2614 | return null; |
| 2615 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2616 | |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 2617 | public void setUniverseTransformLocked(WindowState window, float alpha, |
| 2618 | float offx, float offy, float dsdx, float dtdx, float dsdy, float dtdy) { |
| 2619 | Transformation transform = window.mWinAnimator.mUniverseTransform; |
| 2620 | transform.setAlpha(alpha); |
| 2621 | Matrix matrix = transform.getMatrix(); |
| 2622 | matrix.getValues(mTmpFloats); |
| 2623 | mTmpFloats[Matrix.MTRANS_X] = offx; |
| 2624 | mTmpFloats[Matrix.MTRANS_Y] = offy; |
| 2625 | mTmpFloats[Matrix.MSCALE_X] = dsdx; |
| 2626 | mTmpFloats[Matrix.MSKEW_Y] = dtdx; |
| 2627 | mTmpFloats[Matrix.MSKEW_X] = dsdy; |
| 2628 | mTmpFloats[Matrix.MSCALE_Y] = dtdy; |
| 2629 | matrix.setValues(mTmpFloats); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2630 | final DisplayInfo displayInfo = window.mDisplayContent.getDisplayInfo(); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 2631 | final RectF dispRect = new RectF(0, 0, |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2632 | displayInfo.logicalWidth, displayInfo.logicalHeight); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 2633 | matrix.mapRect(dispRect); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 2634 | window.mGivenTouchableRegion.set(0, 0, |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2635 | displayInfo.logicalWidth, displayInfo.logicalHeight); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 2636 | window.mGivenTouchableRegion.op((int)dispRect.left, (int)dispRect.top, |
| 2637 | (int)dispRect.right, (int)dispRect.bottom, Region.Op.DIFFERENCE); |
| 2638 | window.mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION; |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 2639 | window.mDisplayContent.layoutNeeded = true; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 2640 | performLayoutAndPlaceSurfacesLocked(); |
| 2641 | } |
| 2642 | |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 2643 | public void onRectangleOnScreenRequested(IBinder token, Rect rectangle, boolean immediate) { |
| 2644 | synchronized (mWindowMap) { |
| 2645 | WindowState window = mWindowMap.get(token); |
| 2646 | if (window != null) { |
| 2647 | scheduleNotifyRectangleOnScreenRequestedIfNeededLocked(window, rectangle, |
| 2648 | immediate); |
| 2649 | } |
| 2650 | } |
| 2651 | } |
| 2652 | |
| 2653 | private void scheduleNotifyRectangleOnScreenRequestedIfNeededLocked(WindowState window, |
| 2654 | Rect rectangle, boolean immediate) { |
| 2655 | DisplayContent displayContent = window.mDisplayContent; |
| 2656 | if (displayContent.mDisplayContentChangeListeners != null |
| 2657 | && displayContent.mDisplayContentChangeListeners.getRegisteredCallbackCount() > 0) { |
| 2658 | mH.obtainMessage(H.NOTIFY_RECTANGLE_ON_SCREEN_REQUESTED, displayContent.getDisplayId(), |
| 2659 | immediate? 1 : 0, new Rect(rectangle)).sendToTarget(); |
| 2660 | } |
| 2661 | } |
| 2662 | |
| 2663 | private void handleNotifyRectangleOnScreenRequested(int displayId, Rect rectangle, |
| 2664 | boolean immediate) { |
| 2665 | RemoteCallbackList<IDisplayContentChangeListener> callbacks = null; |
| 2666 | synchronized (mWindowMap) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 2667 | DisplayContent displayContent = getDisplayContentLocked(displayId); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 2668 | if (displayContent == null) { |
| 2669 | return; |
| 2670 | } |
| 2671 | callbacks = displayContent.mDisplayContentChangeListeners; |
| 2672 | if (callbacks == null) { |
| 2673 | return; |
| 2674 | } |
| 2675 | } |
| 2676 | final int callbackCount = callbacks.beginBroadcast(); |
| 2677 | try { |
| 2678 | for (int i = 0; i < callbackCount; i++) { |
| 2679 | try { |
| 2680 | callbacks.getBroadcastItem(i).onRectangleOnScreenRequested(displayId, |
| 2681 | rectangle, immediate); |
| 2682 | } catch (RemoteException re) { |
| 2683 | /* ignore */ |
| 2684 | } |
| 2685 | } |
| 2686 | } finally { |
| 2687 | callbacks.finishBroadcast(); |
| 2688 | } |
| 2689 | } |
| 2690 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2691 | public int relayoutWindow(Session session, IWindow client, int seq, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2692 | WindowManager.LayoutParams attrs, int requestedWidth, |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 2693 | int requestedHeight, int viewVisibility, int flags, |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 2694 | Rect outFrame, Rect outContentInsets, |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 2695 | Rect outVisibleInsets, Configuration outConfig, Surface outSurface) { |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2696 | boolean toBeDisplayed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2697 | boolean inTouchMode; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2698 | boolean configChanged; |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 2699 | boolean surfaceChanged = false; |
Dianne Hackborn | 12d3a94 | 2012-04-27 14:16:30 -0700 | [diff] [blame] | 2700 | boolean animating; |
Joe Onorato | ac0ee89 | 2011-01-30 15:38:30 -0800 | [diff] [blame] | 2701 | |
| 2702 | // if they don't have this permission, mask out the status bar bits |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2703 | int systemUiVisibility = 0; |
Joe Onorato | ac0ee89 | 2011-01-30 15:38:30 -0800 | [diff] [blame] | 2704 | if (attrs != null) { |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2705 | systemUiVisibility = (attrs.systemUiVisibility|attrs.subtreeSystemUiVisibility); |
| 2706 | if ((systemUiVisibility & StatusBarManager.DISABLE_MASK) != 0) { |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 2707 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR) |
| 2708 | != PackageManager.PERMISSION_GRANTED) { |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2709 | systemUiVisibility &= ~StatusBarManager.DISABLE_MASK; |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 2710 | } |
Joe Onorato | ac0ee89 | 2011-01-30 15:38:30 -0800 | [diff] [blame] | 2711 | } |
| 2712 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2713 | long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2714 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2715 | synchronized(mWindowMap) { |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 2716 | // TODO(cmautner): synchronize on mAnimator or win.mWinAnimator. |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2717 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2718 | if (win == null) { |
| 2719 | return 0; |
| 2720 | } |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 2721 | WindowStateAnimator winAnimator = win.mWinAnimator; |
Dianne Hackborn | b7ff51b | 2012-01-23 19:15:27 -0800 | [diff] [blame] | 2722 | if (win.mRequestedWidth != requestedWidth |
| 2723 | || win.mRequestedHeight != requestedHeight) { |
| 2724 | win.mLayoutNeeded = true; |
| 2725 | win.mRequestedWidth = requestedWidth; |
| 2726 | win.mRequestedHeight = requestedHeight; |
| 2727 | } |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2728 | if (attrs != null && seq == win.mSeq) { |
| 2729 | win.mSystemUiVisibility = systemUiVisibility; |
| 2730 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2731 | |
| 2732 | if (attrs != null) { |
| 2733 | mPolicy.adjustWindowParamsLw(attrs); |
| 2734 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2735 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2736 | winAnimator.mSurfaceDestroyDeferred = |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2737 | (flags&WindowManagerGlobal.RELAYOUT_DEFER_SURFACE_DESTROY) != 0; |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 2738 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2739 | int attrChanges = 0; |
| 2740 | int flagChanges = 0; |
| 2741 | if (attrs != null) { |
Dianne Hackborn | 0e60db2 | 2011-09-01 11:17:57 -0700 | [diff] [blame] | 2742 | if (win.mAttrs.type != attrs.type) { |
| 2743 | throw new IllegalArgumentException( |
| 2744 | "Window type can not be changed after the window is added."); |
| 2745 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2746 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2747 | attrChanges = win.mAttrs.copyFrom(attrs); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2748 | if ((attrChanges & (WindowManager.LayoutParams.LAYOUT_CHANGED |
| 2749 | | WindowManager.LayoutParams.SYSTEM_UI_VISIBILITY_CHANGED)) != 0) { |
Dianne Hackborn | b7ff51b | 2012-01-23 19:15:27 -0800 | [diff] [blame] | 2750 | win.mLayoutNeeded = true; |
| 2751 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2752 | } |
| 2753 | |
Craig Mautner | c36c49e | 2012-09-29 16:02:43 -0700 | [diff] [blame] | 2754 | if (DEBUG_LAYOUT |
| 2755 | // TODO: Remove once b/7094175 is fixed |
| 2756 | || ((String)win.mAttrs.getTitle()).contains("Keyguard") |
| 2757 | ) Slog.v(TAG, "Relayout " + win + ": viewVisibility=" + viewVisibility |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 2758 | + " " + requestedWidth + "x" + requestedHeight + " " + win.mAttrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2759 | |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2760 | win.mEnforceSizeCompat = (win.mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0; |
| 2761 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2762 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2763 | winAnimator.mAlpha = attrs.alpha; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2764 | } |
| 2765 | |
| 2766 | final boolean scaledWindow = |
| 2767 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2768 | |
| 2769 | if (scaledWindow) { |
| 2770 | // requested{Width|Height} Surface's physical size |
| 2771 | // attrs.{width|height} Size on screen |
| 2772 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2773 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2774 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2775 | (attrs.height / (float)requestedHeight) : 1.0f; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2776 | } else { |
| 2777 | win.mHScale = win.mVScale = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2778 | } |
| 2779 | |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 2780 | boolean imMayMove = (flagChanges & (FLAG_ALT_FOCUSABLE_IM | FLAG_NOT_FOCUSABLE)) != 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2781 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2782 | final boolean isDefaultDisplay = win.isDefaultDisplay(); |
| 2783 | boolean focusMayChange = isDefaultDisplay && (win.mViewVisibility != viewVisibility |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 2784 | || ((flagChanges & FLAG_NOT_FOCUSABLE) != 0) |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2785 | || (!win.mRelayoutCalled)); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2786 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2787 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2788 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
Dianne Hackborn | 9e4e727 | 2011-08-30 14:06:51 -0700 | [diff] [blame] | 2789 | wallpaperMayMove |= (flagChanges & FLAG_SHOW_WALLPAPER) != 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2790 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2791 | win.mRelayoutCalled = true; |
| 2792 | final int oldVisibility = win.mViewVisibility; |
| 2793 | win.mViewVisibility = viewVisibility; |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 2794 | if (DEBUG_SCREEN_ON) { |
| 2795 | RuntimeException stack = new RuntimeException(); |
| 2796 | stack.fillInStackTrace(); |
| 2797 | Slog.i(TAG, "Relayout " + win + ": oldVis=" + oldVisibility |
| 2798 | + " newVis=" + viewVisibility, stack); |
| 2799 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2800 | if (viewVisibility == View.VISIBLE && |
| 2801 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2802 | toBeDisplayed = !win.isVisibleLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2803 | if (win.mExiting) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2804 | winAnimator.cancelExitAnimationForNextAnimationLocked(); |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 2805 | win.mExiting = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2806 | } |
| 2807 | if (win.mDestroying) { |
| 2808 | win.mDestroying = false; |
| 2809 | mDestroySurface.remove(win); |
| 2810 | } |
| 2811 | if (oldVisibility == View.GONE) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2812 | winAnimator.mEnterAnimationPending = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2813 | } |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2814 | if (toBeDisplayed) { |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 2815 | if (win.isDrawnLw() && okToDisplay()) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2816 | winAnimator.applyEnterAnimationLocked(); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2817 | } |
| 2818 | if ((win.mAttrs.flags |
| 2819 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2820 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2821 | "Relayout window turning screen on: " + win); |
| 2822 | win.mTurnOnScreen = true; |
| 2823 | } |
| 2824 | int diff = 0; |
| 2825 | if (win.mConfiguration != mCurConfiguration |
| 2826 | && (win.mConfiguration == null |
| 2827 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2828 | win.mConfiguration = mCurConfiguration; |
| 2829 | if (DEBUG_CONFIGURATION) { |
| 2830 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2831 | + win.mConfiguration + " / 0x" |
| 2832 | + Integer.toHexString(diff)); |
| 2833 | } |
| 2834 | outConfig.setTo(mCurConfiguration); |
| 2835 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2836 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2837 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2838 | // To change the format, we need to re-build the surface. |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2839 | winAnimator.destroySurfaceLocked(); |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2840 | toBeDisplayed = true; |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 2841 | surfaceChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2842 | } |
| 2843 | try { |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 2844 | if (!win.mHasSurface) { |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 2845 | surfaceChanged = true; |
| 2846 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2847 | Surface surface = winAnimator.createSurfaceLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2848 | if (surface != null) { |
| 2849 | outSurface.copyFrom(surface); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2850 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2851 | " OUT SURFACE " + outSurface + ": copied"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2852 | } else { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2853 | // For some reason there isn't a surface. Clear the |
| 2854 | // caller's object so they see the same state. |
| 2855 | outSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2856 | } |
| 2857 | } catch (Exception e) { |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2858 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
Craig Mautner | 9e80944 | 2012-06-22 17:13:04 -0700 | [diff] [blame] | 2859 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2860 | Slog.w(TAG, "Exception thrown when creating surface for client " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2861 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2862 | e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2863 | Binder.restoreCallingIdentity(origId); |
| 2864 | return 0; |
| 2865 | } |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2866 | if (toBeDisplayed) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2867 | focusMayChange = isDefaultDisplay; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2868 | } |
| 2869 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2870 | && mInputMethodWindow == null) { |
| 2871 | mInputMethodWindow = win; |
| 2872 | imMayMove = true; |
| 2873 | } |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2874 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2875 | && win.mAppToken != null |
| 2876 | && win.mAppToken.startingWindow != null) { |
| 2877 | // Special handling of starting window over the base |
| 2878 | // window of the app: propagate lock screen flags to it, |
| 2879 | // to provide the correct semantics while starting. |
| 2880 | final int mask = |
| 2881 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2882 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2883 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2884 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2885 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2886 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2887 | } else { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2888 | winAnimator.mEnterAnimationPending = false; |
| 2889 | if (winAnimator.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2890 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2891 | + ": mExiting=" + win.mExiting); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2892 | // If we are not currently running the exit animation, we |
| 2893 | // need to see about starting one. |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2894 | if (!win.mExiting) { |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 2895 | surfaceChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2896 | // Try starting an animation; if there isn't one, we |
| 2897 | // can destroy the surface right away. |
| 2898 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 2899 | if (win.mAttrs.type == TYPE_APPLICATION_STARTING) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2900 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2901 | } |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2902 | if (win.isWinVisibleLw() && |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2903 | winAnimator.applyAnimationLocked(transit, false)) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2904 | focusMayChange = isDefaultDisplay; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2905 | win.mExiting = true; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 2906 | } else if (win.mWinAnimator.isAnimating()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2907 | // Currently in a hide animation... turn this into |
| 2908 | // an exit. |
| 2909 | win.mExiting = true; |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2910 | } else if (win == mWallpaperTarget) { |
| 2911 | // If the wallpaper is currently behind this |
| 2912 | // window, we need to change both of them inside |
| 2913 | // of a transaction to avoid artifacts. |
| 2914 | win.mExiting = true; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 2915 | win.mWinAnimator.mAnimating = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2916 | } else { |
| 2917 | if (mInputMethodWindow == win) { |
| 2918 | mInputMethodWindow = null; |
| 2919 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2920 | winAnimator.destroySurfaceLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2921 | } |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 2922 | scheduleNotifyWindowTranstionIfNeededLocked(win, transit); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2923 | } |
| 2924 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2925 | |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2926 | outSurface.release(); |
| 2927 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2928 | } |
| 2929 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2930 | if (focusMayChange) { |
| 2931 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2932 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 2933 | false /*updateInputWindows*/)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2934 | imMayMove = false; |
| 2935 | } |
| 2936 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2937 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2938 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2939 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2940 | // reassign them at this point if the IM window state gets shuffled |
| 2941 | boolean assignLayers = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2942 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2943 | if (imMayMove) { |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2944 | if (moveInputMethodWindowsIfNeededLocked(false) || toBeDisplayed) { |
Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2945 | // Little hack here -- we -should- be able to rely on the |
| 2946 | // function to return true if the IME has moved and needs |
| 2947 | // its layer recomputed. However, if the IME was hidden |
| 2948 | // and isn't actually moved in the list, its layer may be |
| 2949 | // 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] | 2950 | assignLayers = true; |
| 2951 | } |
| 2952 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2953 | if (wallpaperMayMove) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2954 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2955 | assignLayers = true; |
| 2956 | } |
| 2957 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2958 | |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 2959 | win.mDisplayContent.layoutNeeded = true; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2960 | win.mGivenInsetsPending = (flags&WindowManagerGlobal.RELAYOUT_INSETS_PENDING) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2961 | if (assignLayers) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2962 | assignLayersLocked(win.getWindowList()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2963 | } |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2964 | configChanged = updateOrientationFromAppTokensLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2965 | performLayoutAndPlaceSurfacesLocked(); |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 2966 | if (toBeDisplayed && win.mIsWallpaper) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 2967 | DisplayInfo displayInfo = getDefaultDisplayInfoLocked(); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 2968 | updateWallpaperOffsetLocked(win, |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2969 | displayInfo.appWidth, displayInfo.appHeight, false); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2970 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2971 | if (win.mAppToken != null) { |
| 2972 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2973 | } |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 2974 | outFrame.set(win.mCompatFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2975 | outContentInsets.set(win.mContentInsets); |
| 2976 | outVisibleInsets.set(win.mVisibleInsets); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2977 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2978 | TAG, "Relayout given client " + client.asBinder() |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2979 | + ", requestedWidth=" + requestedWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2980 | + ", requestedHeight=" + requestedHeight |
| 2981 | + ", viewVisibility=" + viewVisibility |
| 2982 | + "\nRelayout returning frame=" + outFrame |
| 2983 | + ", surface=" + outSurface); |
| 2984 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2985 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2986 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2987 | |
| 2988 | inTouchMode = mInTouchMode; |
Dianne Hackborn | 12d3a94 | 2012-04-27 14:16:30 -0700 | [diff] [blame] | 2989 | animating = mAnimator.mAnimating; |
| 2990 | if (animating && !mRelayoutWhileAnimating.contains(win)) { |
| 2991 | mRelayoutWhileAnimating.add(win); |
| 2992 | } |
| 2993 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2994 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2995 | } |
| 2996 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2997 | if (configChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2998 | sendNewConfiguration(); |
| 2999 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3000 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3001 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3002 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3003 | return (inTouchMode ? WindowManagerGlobal.RELAYOUT_RES_IN_TOUCH_MODE : 0) |
| 3004 | | (toBeDisplayed ? WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME : 0) |
| 3005 | | (surfaceChanged ? WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED : 0) |
| 3006 | | (animating ? WindowManagerGlobal.RELAYOUT_RES_ANIMATING : 0); |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 3007 | } |
| 3008 | |
| 3009 | public void performDeferredDestroyWindow(Session session, IWindow client) { |
| 3010 | long origId = Binder.clearCallingIdentity(); |
| 3011 | |
| 3012 | try { |
| 3013 | synchronized(mWindowMap) { |
| 3014 | WindowState win = windowForClientLocked(session, client, false); |
| 3015 | if (win == null) { |
| 3016 | return; |
| 3017 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 3018 | win.mWinAnimator.destroyDeferredSurfaceLocked(); |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 3019 | } |
| 3020 | } finally { |
| 3021 | Binder.restoreCallingIdentity(origId); |
| 3022 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3023 | } |
| 3024 | |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 3025 | public boolean outOfMemoryWindow(Session session, IWindow client) { |
| 3026 | long origId = Binder.clearCallingIdentity(); |
| 3027 | |
| 3028 | try { |
| 3029 | synchronized(mWindowMap) { |
| 3030 | WindowState win = windowForClientLocked(session, client, false); |
| 3031 | if (win == null) { |
| 3032 | return false; |
| 3033 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 3034 | return reclaimSomeSurfaceMemoryLocked(win.mWinAnimator, "from-client", false); |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 3035 | } |
| 3036 | } finally { |
| 3037 | Binder.restoreCallingIdentity(origId); |
| 3038 | } |
| 3039 | } |
| 3040 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3041 | public void finishDrawingWindow(Session session, IWindow client) { |
| 3042 | final long origId = Binder.clearCallingIdentity(); |
| 3043 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3044 | WindowState win = windowForClientLocked(session, client, false); |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 3045 | if (win != null && win.mWinAnimator.finishDrawingLocked()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 3046 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 3047 | adjustWallpaperWindowsLocked(); |
| 3048 | } |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 3049 | win.mDisplayContent.layoutNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3050 | performLayoutAndPlaceSurfacesLocked(); |
| 3051 | } |
| 3052 | } |
| 3053 | Binder.restoreCallingIdentity(origId); |
| 3054 | } |
| 3055 | |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 3056 | @Override |
Svetoslav Ganov | 7961be7 | 2011-06-21 12:31:56 -0700 | [diff] [blame] | 3057 | public float getWindowCompatibilityScale(IBinder windowToken) { |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 3058 | if (!checkCallingPermission(android.Manifest.permission.RETRIEVE_WINDOW_INFO, |
| 3059 | "getWindowCompatibilityScale()")) { |
| 3060 | throw new SecurityException("Requires RETRIEVE_WINDOW_INFO permission."); |
| 3061 | } |
Svetoslav Ganov | 7961be7 | 2011-06-21 12:31:56 -0700 | [diff] [blame] | 3062 | synchronized (mWindowMap) { |
| 3063 | WindowState windowState = mWindowMap.get(windowToken); |
| 3064 | return (windowState != null) ? windowState.mGlobalScale : 1.0f; |
| 3065 | } |
| 3066 | } |
| 3067 | |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 3068 | @Override |
| 3069 | public WindowInfo getWindowInfo(IBinder token) { |
| 3070 | if (!checkCallingPermission(android.Manifest.permission.RETRIEVE_WINDOW_INFO, |
| 3071 | "getWindowInfo()")) { |
| 3072 | throw new SecurityException("Requires RETRIEVE_WINDOW_INFO permission."); |
| 3073 | } |
| 3074 | synchronized (mWindowMap) { |
| 3075 | WindowState window = mWindowMap.get(token); |
| 3076 | if (window != null) { |
| 3077 | return getWindowInfoForWindowStateLocked(window); |
| 3078 | } |
| 3079 | return null; |
| 3080 | } |
| 3081 | } |
| 3082 | |
| 3083 | @Override |
| 3084 | public void getVisibleWindowsForDisplay(int displayId, List<WindowInfo> outInfos) { |
| 3085 | if (!checkCallingPermission(android.Manifest.permission.RETRIEVE_WINDOW_INFO, |
| 3086 | "getWindowInfos()")) { |
| 3087 | throw new SecurityException("Requires RETRIEVE_WINDOW_INFO permission."); |
| 3088 | } |
| 3089 | synchronized (mWindowMap) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3090 | DisplayContent displayContent = getDisplayContentLocked(displayId); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 3091 | if (displayContent == null) { |
| 3092 | return; |
| 3093 | } |
| 3094 | WindowList windows = displayContent.getWindowList(); |
| 3095 | final int windowCount = windows.size(); |
| 3096 | for (int i = 0; i < windowCount; i++) { |
| 3097 | WindowState window = windows.get(i); |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 3098 | if (window.isVisibleLw() || window.mAttrs.type == TYPE_UNIVERSE_BACKGROUND) { |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 3099 | WindowInfo info = getWindowInfoForWindowStateLocked(window); |
| 3100 | outInfos.add(info); |
| 3101 | } |
| 3102 | } |
| 3103 | } |
| 3104 | } |
| 3105 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3106 | @Override |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 3107 | public void magnifyDisplay(int displayId, float scale, float offsetX, float offsetY) { |
| 3108 | if (!checkCallingPermission( |
| 3109 | android.Manifest.permission.MAGNIFY_DISPLAY, "magnifyDisplay()")) { |
| 3110 | throw new SecurityException("Requires MAGNIFY_DISPLAY permission"); |
| 3111 | } |
| 3112 | synchronized (mWindowMap) { |
| 3113 | MagnificationSpec spec = getDisplayMagnificationSpecLocked(displayId); |
| 3114 | if (spec != null) { |
| 3115 | final boolean scaleChanged = spec.mScale != scale; |
| 3116 | final boolean offsetChanged = spec.mOffsetX != offsetX || spec.mOffsetY != offsetY; |
| 3117 | if (!scaleChanged && !offsetChanged) { |
| 3118 | return; |
| 3119 | } |
| 3120 | spec.initialize(scale, offsetX, offsetY); |
| 3121 | // If the offset has changed we need to re-add the input windows |
| 3122 | // since the offsets have to be propagated to the input system. |
| 3123 | if (offsetChanged) { |
| 3124 | // TODO(multidisplay): Input only occurs on the default display. |
| 3125 | if (displayId == Display.DEFAULT_DISPLAY) { |
| 3126 | mInputMonitor.updateInputWindowsLw(true); |
| 3127 | } |
| 3128 | } |
| 3129 | scheduleAnimationLocked(); |
| 3130 | } |
| 3131 | } |
| 3132 | } |
| 3133 | |
| 3134 | MagnificationSpec getDisplayMagnificationSpecLocked(int displayId) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3135 | DisplayContent displayContent = getDisplayContentLocked(displayId); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 3136 | if (displayContent != null) { |
| 3137 | if (displayContent.mMagnificationSpec == null) { |
| 3138 | displayContent.mMagnificationSpec = new MagnificationSpec(); |
| 3139 | } |
| 3140 | return displayContent.mMagnificationSpec; |
| 3141 | } |
| 3142 | return null; |
| 3143 | } |
| 3144 | |
| 3145 | private WindowInfo getWindowInfoForWindowStateLocked(WindowState window) { |
| 3146 | WindowInfo info = WindowInfo.obtain(); |
| 3147 | info.token = window.mToken.token; |
| 3148 | info.frame.set(window.mFrame); |
| 3149 | info.type = window.mAttrs.type; |
| 3150 | info.displayId = window.getDisplayId(); |
| 3151 | info.compatibilityScale = window.mGlobalScale; |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 3152 | info.visible = window.isVisibleLw() || info.type == TYPE_UNIVERSE_BACKGROUND; |
Svetoslav Ganov | 9b4125e | 2012-09-11 15:36:44 -0700 | [diff] [blame] | 3153 | info.layer = window.mLayer; |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 3154 | window.getTouchableRegion(mTempRegion); |
| 3155 | mTempRegion.getBounds(info.touchableRegion); |
| 3156 | return info; |
| 3157 | } |
| 3158 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3159 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 3160 | 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] | 3161 | + (lp != null ? lp.packageName : null) |
| 3162 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 3163 | if (lp != null && lp.windowAnimations != 0) { |
| 3164 | // If this is a system resource, don't try to load it from the |
| 3165 | // application resources. It is nice to avoid loading application |
| 3166 | // resources if we can. |
| 3167 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 3168 | int resId = lp.windowAnimations; |
| 3169 | if ((resId&0xFF000000) == 0x01000000) { |
| 3170 | packageName = "android"; |
| 3171 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3172 | 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] | 3173 | + packageName); |
| 3174 | return AttributeCache.instance().get(packageName, resId, |
| 3175 | com.android.internal.R.styleable.WindowAnimation); |
| 3176 | } |
| 3177 | return null; |
| 3178 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3179 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3180 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 3181 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3182 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 3183 | if (packageName != null) { |
| 3184 | if ((resId&0xFF000000) == 0x01000000) { |
| 3185 | packageName = "android"; |
| 3186 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3187 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3188 | + packageName); |
| 3189 | return AttributeCache.instance().get(packageName, resId, |
| 3190 | com.android.internal.R.styleable.WindowAnimation); |
| 3191 | } |
| 3192 | return null; |
| 3193 | } |
| 3194 | |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 3195 | Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3196 | int anim = 0; |
| 3197 | Context context = mContext; |
| 3198 | if (animAttr >= 0) { |
| 3199 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 3200 | if (ent != null) { |
| 3201 | context = ent.context; |
| 3202 | anim = ent.array.getResourceId(animAttr, 0); |
| 3203 | } |
| 3204 | } |
| 3205 | if (anim != 0) { |
| 3206 | return AnimationUtils.loadAnimation(context, anim); |
| 3207 | } |
| 3208 | return null; |
| 3209 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3210 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3211 | private Animation loadAnimation(String packageName, int resId) { |
| 3212 | int anim = 0; |
| 3213 | Context context = mContext; |
| 3214 | if (resId >= 0) { |
| 3215 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 3216 | if (ent != null) { |
| 3217 | context = ent.context; |
| 3218 | anim = resId; |
| 3219 | } |
| 3220 | } |
| 3221 | if (anim != 0) { |
| 3222 | return AnimationUtils.loadAnimation(context, anim); |
| 3223 | } |
| 3224 | return null; |
| 3225 | } |
| 3226 | |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3227 | private Animation createExitAnimationLocked(int transit, int duration) { |
| 3228 | if (transit == WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN || |
| 3229 | transit == WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE) { |
| 3230 | // If we are on top of the wallpaper, we need an animation that |
| 3231 | // correctly handles the wallpaper staying static behind all of |
| 3232 | // the animated elements. To do this, will just have the existing |
| 3233 | // element fade out. |
| 3234 | Animation a = new AlphaAnimation(1, 0); |
| 3235 | a.setDetachWallpaper(true); |
| 3236 | a.setDuration(duration); |
| 3237 | return a; |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3238 | } |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 3239 | // For normal animations, the exiting element just holds in place. |
| 3240 | Animation a = new AlphaAnimation(1, 1); |
| 3241 | a.setDuration(duration); |
| 3242 | return a; |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3243 | } |
| 3244 | |
| 3245 | /** |
| 3246 | * Compute the pivot point for an animation that is scaling from a small |
| 3247 | * rect on screen to a larger rect. The pivot point varies depending on |
| 3248 | * the distance between the inner and outer edges on both sides. This |
| 3249 | * function computes the pivot point for one dimension. |
| 3250 | * @param startPos Offset from left/top edge of outer rectangle to |
| 3251 | * left/top edge of inner rectangle. |
| 3252 | * @param finalScale The scaling factor between the size of the outer |
| 3253 | * and inner rectangles. |
| 3254 | */ |
| 3255 | private static float computePivot(int startPos, float finalScale) { |
| 3256 | final float denom = finalScale-1; |
| 3257 | if (Math.abs(denom) < .0001f) { |
| 3258 | return startPos; |
| 3259 | } |
| 3260 | return -startPos / denom; |
| 3261 | } |
| 3262 | |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 3263 | private Animation createScaleUpAnimationLocked(int transit, boolean enter) { |
| 3264 | Animation a; |
| 3265 | // Pick the desired duration. If this is an inter-activity transition, |
| 3266 | // it is the standard duration for that. Otherwise we use the longer |
| 3267 | // task transition duration. |
| 3268 | int duration; |
| 3269 | switch (transit) { |
| 3270 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 3271 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 3272 | duration = mContext.getResources().getInteger( |
| 3273 | com.android.internal.R.integer.config_shortAnimTime); |
| 3274 | break; |
| 3275 | default: |
Winson Chung | dc6f79b | 2012-04-17 17:27:31 -0700 | [diff] [blame] | 3276 | duration = 300; |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 3277 | break; |
| 3278 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 3279 | // TODO(multidisplay): For now assume all app animation is on main display. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3280 | final DisplayInfo displayInfo = getDefaultDisplayInfoLocked(); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 3281 | if (enter) { |
| 3282 | // Entering app zooms out from the center of the initial rect. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 3283 | float scaleW = mNextAppTransitionStartWidth / (float) displayInfo.appWidth; |
| 3284 | float scaleH = mNextAppTransitionStartHeight / (float) displayInfo.appHeight; |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3285 | Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1, |
| 3286 | computePivot(mNextAppTransitionStartX, scaleW), |
| 3287 | computePivot(mNextAppTransitionStartY, scaleH)); |
| 3288 | scale.setDuration(duration); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 3289 | AnimationSet set = new AnimationSet(true); |
| 3290 | Animation alpha = new AlphaAnimation(0, 1); |
| 3291 | scale.setDuration(duration); |
| 3292 | set.addAnimation(scale); |
| 3293 | alpha.setDuration(duration); |
| 3294 | set.addAnimation(alpha); |
Craig Mautner | a803371 | 2012-06-12 15:50:45 -0700 | [diff] [blame] | 3295 | set.setDetachWallpaper(true); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 3296 | a = set; |
| 3297 | } else { |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3298 | a = createExitAnimationLocked(transit, duration); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 3299 | } |
| 3300 | a.setFillAfter(true); |
| 3301 | final Interpolator interpolator = AnimationUtils.loadInterpolator(mContext, |
Winson Chung | dc6f79b | 2012-04-17 17:27:31 -0700 | [diff] [blame] | 3302 | com.android.internal.R.interpolator.decelerate_cubic); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 3303 | a.setInterpolator(interpolator); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 3304 | a.initialize(displayInfo.appWidth, displayInfo.appHeight, |
| 3305 | displayInfo.appWidth, displayInfo.appHeight); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 3306 | return a; |
| 3307 | } |
| 3308 | |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3309 | private Animation createThumbnailAnimationLocked(int transit, |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 3310 | boolean enter, boolean thumb, boolean scaleUp) { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3311 | Animation a; |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3312 | final int thumbWidthI = mNextAppTransitionThumbnail.getWidth(); |
| 3313 | final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1; |
| 3314 | final int thumbHeightI = mNextAppTransitionThumbnail.getHeight(); |
| 3315 | final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3316 | // Pick the desired duration. If this is an inter-activity transition, |
| 3317 | // it is the standard duration for that. Otherwise we use the longer |
| 3318 | // task transition duration. |
| 3319 | int duration; |
| 3320 | switch (transit) { |
| 3321 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 3322 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 3323 | duration = mContext.getResources().getInteger( |
| 3324 | com.android.internal.R.integer.config_shortAnimTime); |
| 3325 | break; |
| 3326 | default: |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 3327 | duration = 250; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3328 | break; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3329 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 3330 | // TOOD(multidisplay): For now assume all app animation is on the main screen. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3331 | DisplayInfo displayInfo = getDefaultDisplayInfoLocked(); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3332 | if (thumb) { |
| 3333 | // Animation for zooming thumbnail from its initial size to |
| 3334 | // filling the screen. |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 3335 | if (scaleUp) { |
| 3336 | float scaleW = displayInfo.appWidth / thumbWidth; |
| 3337 | float scaleH = displayInfo.appHeight / thumbHeight; |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 3338 | |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 3339 | Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH, |
| 3340 | computePivot(mNextAppTransitionStartX, 1 / scaleW), |
| 3341 | computePivot(mNextAppTransitionStartY, 1 / scaleH)); |
| 3342 | AnimationSet set = new AnimationSet(true); |
| 3343 | Animation alpha = new AlphaAnimation(1, 0); |
| 3344 | scale.setDuration(duration); |
| 3345 | scale.setInterpolator( |
| 3346 | new DecelerateInterpolator(THUMBNAIL_ANIMATION_DECELERATE_FACTOR)); |
| 3347 | set.addAnimation(scale); |
| 3348 | alpha.setDuration(duration); |
| 3349 | set.addAnimation(alpha); |
| 3350 | set.setFillBefore(true); |
| 3351 | a = set; |
| 3352 | } else { |
| 3353 | float scaleW = displayInfo.appWidth / thumbWidth; |
| 3354 | float scaleH = displayInfo.appHeight / thumbHeight; |
| 3355 | |
| 3356 | Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1, |
| 3357 | computePivot(mNextAppTransitionStartX, 1 / scaleW), |
| 3358 | computePivot(mNextAppTransitionStartY, 1 / scaleH)); |
| 3359 | AnimationSet set = new AnimationSet(true); |
| 3360 | Animation alpha = new AlphaAnimation(1, 1); |
| 3361 | scale.setDuration(duration); |
| 3362 | scale.setInterpolator( |
| 3363 | new DecelerateInterpolator(THUMBNAIL_ANIMATION_DECELERATE_FACTOR)); |
| 3364 | set.addAnimation(scale); |
| 3365 | alpha.setDuration(duration); |
| 3366 | set.addAnimation(alpha); |
| 3367 | set.setFillBefore(true); |
| 3368 | |
| 3369 | a = set; |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 3370 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3371 | } else if (enter) { |
| 3372 | // Entering app zooms out from the center of the thumbnail. |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 3373 | if (scaleUp) { |
| 3374 | float scaleW = thumbWidth / displayInfo.appWidth; |
| 3375 | float scaleH = thumbHeight / displayInfo.appHeight; |
| 3376 | Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1, |
| 3377 | computePivot(mNextAppTransitionStartX, scaleW), |
| 3378 | computePivot(mNextAppTransitionStartY, scaleH)); |
| 3379 | scale.setDuration(duration); |
| 3380 | scale.setInterpolator( |
| 3381 | new DecelerateInterpolator(THUMBNAIL_ANIMATION_DECELERATE_FACTOR)); |
| 3382 | scale.setFillBefore(true); |
| 3383 | a = scale; |
Michael Jurka | d5895a7 | 2012-05-12 13:24:58 -0700 | [diff] [blame] | 3384 | } else { |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 3385 | // noop animation |
| 3386 | a = new AlphaAnimation(1, 1); |
| 3387 | a.setDuration(duration); |
| 3388 | } |
| 3389 | } else { |
| 3390 | // Exiting app |
| 3391 | if (scaleUp) { |
| 3392 | // noop animation |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 3393 | a = new AlphaAnimation(1, 0); |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 3394 | a.setDuration(duration); |
| 3395 | } else { |
| 3396 | float scaleW = thumbWidth / displayInfo.appWidth; |
| 3397 | float scaleH = thumbHeight / displayInfo.appHeight; |
| 3398 | Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH, |
| 3399 | computePivot(mNextAppTransitionStartX, scaleW), |
| 3400 | computePivot(mNextAppTransitionStartY, scaleH)); |
| 3401 | scale.setDuration(duration); |
| 3402 | scale.setInterpolator( |
| 3403 | new DecelerateInterpolator(THUMBNAIL_ANIMATION_DECELERATE_FACTOR)); |
| 3404 | scale.setFillBefore(true); |
| 3405 | AnimationSet set = new AnimationSet(true); |
| 3406 | Animation alpha = new AlphaAnimation(1, 0); |
| 3407 | set.addAnimation(scale); |
| 3408 | alpha.setDuration(duration); |
| 3409 | alpha.setInterpolator(new DecelerateInterpolator( |
| 3410 | THUMBNAIL_ANIMATION_DECELERATE_FACTOR)); |
| 3411 | set.addAnimation(alpha); |
| 3412 | set.setFillBefore(true); |
| 3413 | set.setZAdjustment(Animation.ZORDER_TOP); |
| 3414 | a = set; |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 3415 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3416 | } |
| 3417 | a.setFillAfter(true); |
| 3418 | final Interpolator interpolator = AnimationUtils.loadInterpolator(mContext, |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3419 | com.android.internal.R.interpolator.decelerate_quad); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3420 | a.setInterpolator(interpolator); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 3421 | a.initialize(displayInfo.appWidth, displayInfo.appHeight, |
| 3422 | displayInfo.appWidth, displayInfo.appHeight); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3423 | return a; |
| 3424 | } |
| 3425 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3426 | private boolean applyAnimationLocked(AppWindowToken atoken, |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 3427 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3428 | // Only apply an animation if the display isn't frozen. If it is |
| 3429 | // frozen, there is no reason to animate and it can cause strange |
| 3430 | // artifacts when we unfreeze the display if some different animation |
| 3431 | // is running. |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 3432 | if (okToDisplay()) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3433 | Animation a; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3434 | boolean initialized = false; |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 3435 | if (mNextAppTransitionType == ActivityOptions.ANIM_CUSTOM) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3436 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 3437 | mNextAppTransitionEnter : mNextAppTransitionExit); |
Daniel Sandler | ab886f5 | 2012-06-04 14:36:25 -0400 | [diff] [blame] | 3438 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3439 | "applyAnimation: atoken=" + atoken |
Craig Mautner | 83339b4 | 2012-05-01 22:13:23 -0700 | [diff] [blame] | 3440 | + " anim=" + a + " nextAppTransition=ANIM_CUSTOM" |
Craig Mautner | dc5a638 | 2012-09-13 16:34:41 -0700 | [diff] [blame] | 3441 | + " transit=" + transit + " isEntrance=" + enter |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 3442 | + " Callers=" + Debug.getCallers(3)); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 3443 | } else if (mNextAppTransitionType == ActivityOptions.ANIM_SCALE_UP) { |
| 3444 | a = createScaleUpAnimationLocked(transit, enter); |
| 3445 | initialized = true; |
Daniel Sandler | ab886f5 | 2012-06-04 14:36:25 -0400 | [diff] [blame] | 3446 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3447 | "applyAnimation: atoken=" + atoken |
Craig Mautner | 83339b4 | 2012-05-01 22:13:23 -0700 | [diff] [blame] | 3448 | + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP" |
Craig Mautner | dc5a638 | 2012-09-13 16:34:41 -0700 | [diff] [blame] | 3449 | + " transit=" + transit + " isEntrance=" + enter |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 3450 | + " Callers=" + Debug.getCallers(3)); |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 3451 | } else if (mNextAppTransitionType == ActivityOptions.ANIM_THUMBNAIL_SCALE_UP || |
| 3452 | mNextAppTransitionType == ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN) { |
| 3453 | boolean scaleUp = (mNextAppTransitionType == ActivityOptions.ANIM_THUMBNAIL_SCALE_UP); |
| 3454 | a = createThumbnailAnimationLocked(transit, enter, false, scaleUp); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 3455 | initialized = true; |
Daniel Sandler | ab886f5 | 2012-06-04 14:36:25 -0400 | [diff] [blame] | 3456 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) { |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 3457 | String animName = scaleUp ? "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN"; |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3458 | Slog.v(TAG, "applyAnimation: atoken=" + atoken |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 3459 | + " anim=" + a + " nextAppTransition=" + animName |
Craig Mautner | dc5a638 | 2012-09-13 16:34:41 -0700 | [diff] [blame] | 3460 | + " transit=" + transit + " isEntrance=" + enter |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 3461 | + " Callers=" + Debug.getCallers(3)); |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 3462 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3463 | } else { |
| 3464 | int animAttr = 0; |
| 3465 | switch (transit) { |
| 3466 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 3467 | animAttr = enter |
| 3468 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 3469 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 3470 | break; |
| 3471 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 3472 | animAttr = enter |
| 3473 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 3474 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 3475 | break; |
| 3476 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 3477 | animAttr = enter |
| 3478 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 3479 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 3480 | break; |
| 3481 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 3482 | animAttr = enter |
| 3483 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 3484 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 3485 | break; |
| 3486 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 3487 | animAttr = enter |
| 3488 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 3489 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 3490 | break; |
| 3491 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 3492 | animAttr = enter |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 3493 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3494 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 3495 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3496 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3497 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3498 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 3499 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3500 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3501 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3502 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3503 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 3504 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 3505 | break; |
| 3506 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 3507 | animAttr = enter |
| 3508 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 3509 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 3510 | break; |
| 3511 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 3512 | animAttr = enter |
| 3513 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 3514 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3515 | break; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3516 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3517 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
Daniel Sandler | ab886f5 | 2012-06-04 14:36:25 -0400 | [diff] [blame] | 3518 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3519 | "applyAnimation: atoken=" + atoken |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3520 | + " anim=" + a |
| 3521 | + " animAttr=0x" + Integer.toHexString(animAttr) |
Craig Mautner | dc5a638 | 2012-09-13 16:34:41 -0700 | [diff] [blame] | 3522 | + " transit=" + transit + " isEntrance=" + enter |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 3523 | + " Callers=" + Debug.getCallers(3)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3524 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3525 | if (a != null) { |
| 3526 | if (DEBUG_ANIM) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3527 | RuntimeException e = null; |
| 3528 | if (!HIDE_STACK_CRAWLS) { |
| 3529 | e = new RuntimeException(); |
| 3530 | e.fillInStackTrace(); |
| 3531 | } |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3532 | Slog.v(TAG, "Loaded animation " + a + " for " + atoken, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3533 | } |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3534 | atoken.mAppAnimator.setAnimation(a, initialized); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3535 | } |
| 3536 | } else { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3537 | atoken.mAppAnimator.clearAnimation(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3538 | } |
| 3539 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3540 | return atoken.mAppAnimator.animation != null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3541 | } |
| 3542 | |
| 3543 | // ------------------------------------------------------------- |
| 3544 | // Application Window Tokens |
| 3545 | // ------------------------------------------------------------- |
| 3546 | |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3547 | public void validateAppTokens(List<IBinder> tokens) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3548 | int v = tokens.size()-1; |
| 3549 | int m = mAppTokens.size()-1; |
| 3550 | while (v >= 0 && m >= 0) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3551 | AppWindowToken atoken = mAppTokens.get(m); |
| 3552 | if (atoken.removed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3553 | m--; |
| 3554 | continue; |
| 3555 | } |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3556 | if (tokens.get(v) != atoken.token) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3557 | Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v) |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3558 | + " @ " + v + ", internal is " + atoken.token + " @ " + m); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3559 | } |
| 3560 | v--; |
| 3561 | m--; |
| 3562 | } |
| 3563 | while (v >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3564 | 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] | 3565 | v--; |
| 3566 | } |
| 3567 | while (m >= 0) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3568 | AppWindowToken atoken = mAppTokens.get(m); |
| 3569 | if (!atoken.removed) { |
| 3570 | Slog.w(TAG, "Invalid internal atoken: " + atoken.token + " @ " + m); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3571 | } |
| 3572 | m--; |
| 3573 | } |
| 3574 | } |
| 3575 | |
| 3576 | boolean checkCallingPermission(String permission, String func) { |
| 3577 | // Quick check: if the calling permission is me, it's all okay. |
| 3578 | if (Binder.getCallingPid() == Process.myPid()) { |
| 3579 | return true; |
| 3580 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3581 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3582 | if (mContext.checkCallingPermission(permission) |
| 3583 | == PackageManager.PERMISSION_GRANTED) { |
| 3584 | return true; |
| 3585 | } |
| 3586 | String msg = "Permission Denial: " + func + " from pid=" |
| 3587 | + Binder.getCallingPid() |
| 3588 | + ", uid=" + Binder.getCallingUid() |
| 3589 | + " requires " + permission; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3590 | Slog.w(TAG, msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3591 | return false; |
| 3592 | } |
Craig Mautner | 9e80944 | 2012-06-22 17:13:04 -0700 | [diff] [blame] | 3593 | |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 3594 | boolean okToDisplay() { |
| 3595 | return !mDisplayFrozen && mDisplayEnabled && mPolicy.isScreenOnFully(); |
| 3596 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3597 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3598 | AppWindowToken findAppWindowToken(IBinder token) { |
| 3599 | WindowToken wtoken = mTokenMap.get(token); |
| 3600 | if (wtoken == null) { |
| 3601 | return null; |
| 3602 | } |
| 3603 | return wtoken.appWindowToken; |
| 3604 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3605 | |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 3606 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3607 | public void addWindowToken(IBinder token, int type) { |
| 3608 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3609 | "addWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3610 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3611 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3612 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3613 | synchronized(mWindowMap) { |
| 3614 | WindowToken wtoken = mTokenMap.get(token); |
| 3615 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3616 | 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] | 3617 | return; |
| 3618 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3619 | wtoken = new WindowToken(this, token, type, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3620 | mTokenMap.put(token, wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3621 | if (type == TYPE_WALLPAPER) { |
| 3622 | mWallpaperTokens.add(wtoken); |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 3623 | updateLayoutToAnimWallpaperTokens(); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3624 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3625 | } |
| 3626 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3627 | |
Craig Mautner | 9e80944 | 2012-06-22 17:13:04 -0700 | [diff] [blame] | 3628 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3629 | public void removeWindowToken(IBinder token) { |
| 3630 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3631 | "removeWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3632 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3633 | } |
| 3634 | |
| 3635 | final long origId = Binder.clearCallingIdentity(); |
| 3636 | synchronized(mWindowMap) { |
| 3637 | WindowToken wtoken = mTokenMap.remove(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3638 | if (wtoken != null) { |
| 3639 | boolean delayed = false; |
| 3640 | if (!wtoken.hidden) { |
| 3641 | wtoken.hidden = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3642 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3643 | final int N = wtoken.windows.size(); |
| 3644 | boolean changed = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3645 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3646 | for (int i=0; i<N; i++) { |
| 3647 | WindowState win = wtoken.windows.get(i); |
| 3648 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 3649 | if (win.mWinAnimator.isAnimating()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3650 | delayed = true; |
| 3651 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3652 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3653 | if (win.isVisibleNow()) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 3654 | win.mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, |
| 3655 | false); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 3656 | scheduleNotifyWindowTranstionIfNeededLocked(win, |
| 3657 | WindowManagerPolicy.TRANSIT_EXIT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3658 | changed = true; |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 3659 | win.mDisplayContent.layoutNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3660 | } |
| 3661 | } |
| 3662 | |
| 3663 | if (changed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3664 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3665 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, |
| 3666 | false /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3667 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3668 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3669 | if (delayed) { |
| 3670 | mExitingTokens.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3671 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 3672 | mWallpaperTokens.remove(wtoken); |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 3673 | updateLayoutToAnimWallpaperTokens(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3674 | } |
| 3675 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3676 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 3677 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3678 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3679 | 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] | 3680 | } |
| 3681 | } |
| 3682 | Binder.restoreCallingIdentity(origId); |
| 3683 | } |
| 3684 | |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 3685 | /** |
| 3686 | * Find the location to insert a new AppWindowToken into the window-ordered app token list. |
| 3687 | * Note that mAppTokens.size() == mAnimatingAppTokens.size() + 1. |
| 3688 | * @param addPos The location the token was inserted into in mAppTokens. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3689 | * @param atoken The token to insert. |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 3690 | */ |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3691 | private void addAppTokenToAnimating(final int addPos, final AppWindowToken atoken) { |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 3692 | if (addPos == 0 || addPos == mAnimatingAppTokens.size()) { |
| 3693 | // It was inserted into the beginning or end of mAppTokens. Honor that. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3694 | mAnimatingAppTokens.add(addPos, atoken); |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 3695 | return; |
| 3696 | } |
| 3697 | // Find the item immediately above the mAppTokens insertion point and put the token |
| 3698 | // immediately below that one in mAnimatingAppTokens. |
| 3699 | final AppWindowToken aboveAnchor = mAppTokens.get(addPos + 1); |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3700 | mAnimatingAppTokens.add(mAnimatingAppTokens.indexOf(aboveAnchor), atoken); |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 3701 | } |
| 3702 | |
| 3703 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3704 | public void addAppToken(int addPos, IApplicationToken token, |
| 3705 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 3706 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3707 | "addAppToken()")) { |
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 | } |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 3710 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3711 | // Get the dispatching timeout here while we are not holding any locks so that it |
| 3712 | // can be cached by the AppWindowToken. The timeout value is used later by the |
| 3713 | // input dispatcher in code that does hold locks. If we did not cache the value |
| 3714 | // here we would run the chance of introducing a deadlock between the window manager |
| 3715 | // (which holds locks while updating the input dispatcher state) and the activity manager |
| 3716 | // (which holds locks while querying the application token). |
| 3717 | long inputDispatchingTimeoutNanos; |
| 3718 | try { |
| 3719 | inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L; |
| 3720 | } catch (RemoteException ex) { |
| 3721 | Slog.w(TAG, "Could not get dispatching timeout.", ex); |
| 3722 | inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 3723 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3724 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3725 | synchronized(mWindowMap) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3726 | AppWindowToken atoken = findAppWindowToken(token.asBinder()); |
| 3727 | if (atoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3728 | 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] | 3729 | return; |
| 3730 | } |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3731 | atoken = new AppWindowToken(this, token); |
| 3732 | atoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos; |
| 3733 | atoken.groupId = groupId; |
| 3734 | atoken.appFullscreen = fullscreen; |
| 3735 | atoken.requestedOrientation = requestedOrientation; |
| 3736 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, "addAppToken: " + atoken |
Craig Mautner | 06a94f7 | 2012-05-29 10:46:00 -0700 | [diff] [blame] | 3737 | + " at " + addPos); |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3738 | mAppTokens.add(addPos, atoken); |
| 3739 | addAppTokenToAnimating(addPos, atoken); |
| 3740 | mTokenMap.put(token.asBinder(), atoken); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3741 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3742 | // Application tokens start out hidden. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3743 | atoken.hidden = true; |
| 3744 | atoken.hiddenRequested = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3745 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3746 | //dump(); |
| 3747 | } |
| 3748 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3749 | |
Craig Mautner | 9e80944 | 2012-06-22 17:13:04 -0700 | [diff] [blame] | 3750 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3751 | public void setAppGroupId(IBinder token, int groupId) { |
| 3752 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 3753 | "setAppGroupId()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3754 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3755 | } |
| 3756 | |
| 3757 | synchronized(mWindowMap) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3758 | AppWindowToken atoken = findAppWindowToken(token); |
| 3759 | if (atoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3760 | 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] | 3761 | return; |
| 3762 | } |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3763 | atoken.groupId = groupId; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3764 | } |
| 3765 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3766 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3767 | public int getOrientationFromWindowsLocked() { |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 3768 | if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) { |
| 3769 | // If the display is frozen, some activities may be in the middle |
| 3770 | // of restarting, and thus have removed their old window. If the |
| 3771 | // window has the flag to hide the lock screen, then the lock screen |
| 3772 | // can re-appear and inflict its own orientation on us. Keep the |
| 3773 | // orientation stable until this all settles down. |
| 3774 | return mLastWindowForcedOrientation; |
| 3775 | } |
| 3776 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 3777 | // TODO(multidisplay): Change to the correct display. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3778 | final WindowList windows = getDefaultWindowListLocked(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 3779 | int pos = windows.size() - 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3780 | while (pos >= 0) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 3781 | WindowState wtoken = windows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3782 | pos--; |
| 3783 | if (wtoken.mAppToken != null) { |
| 3784 | // We hit an application window. so the orientation will be determined by the |
| 3785 | // app window. No point in continuing further. |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 3786 | return (mLastWindowForcedOrientation=ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3787 | } |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3788 | if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3789 | continue; |
| 3790 | } |
| 3791 | int req = wtoken.mAttrs.screenOrientation; |
| 3792 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 3793 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 3794 | continue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3795 | } |
Craig Mautner | 9e80944 | 2012-06-22 17:13:04 -0700 | [diff] [blame] | 3796 | |
| 3797 | return (mLastWindowForcedOrientation=req); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3798 | } |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 3799 | return (mLastWindowForcedOrientation=ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3800 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3801 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3802 | public int getOrientationFromAppTokensLocked() { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3803 | int curGroup = 0; |
| 3804 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3805 | boolean findingBehind = false; |
| 3806 | boolean haveGroup = false; |
| 3807 | boolean lastFullscreen = false; |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 3808 | for (int pos = mAppTokens.size() - 1; pos >= 0; pos--) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3809 | AppWindowToken atoken = mAppTokens.get(pos); |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 3810 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3811 | if (DEBUG_APP_ORIENTATION) Slog.v(TAG, "Checking app orientation: " + atoken); |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 3812 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3813 | // if we're about to tear down this window and not seek for |
| 3814 | // the behind activity, don't use it for orientation |
| 3815 | if (!findingBehind |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3816 | && (!atoken.hidden && atoken.hiddenRequested)) { |
| 3817 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping " + atoken |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 3818 | + " -- going to hide"); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3819 | continue; |
| 3820 | } |
| 3821 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3822 | if (haveGroup == true && curGroup != atoken.groupId) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3823 | // If we have hit a new application group, and the bottom |
| 3824 | // of the previous group didn't explicitly say to use |
| 3825 | // the orientation behind it, and the last app was |
| 3826 | // full screen, then we'll stick with the |
| 3827 | // user's orientation. |
| 3828 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3829 | && lastFullscreen) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3830 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Done at " + atoken |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 3831 | + " -- end of group, return " + lastOrientation); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3832 | return lastOrientation; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3833 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3834 | } |
p13451 | 0445bc6 | 2012-04-18 15:13:26 +0900 | [diff] [blame] | 3835 | |
| 3836 | // We ignore any hidden applications on the top. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3837 | if (atoken.hiddenRequested || atoken.willBeHidden) { |
| 3838 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping " + atoken |
p13451 | 0445bc6 | 2012-04-18 15:13:26 +0900 | [diff] [blame] | 3839 | + " -- hidden on top"); |
| 3840 | continue; |
| 3841 | } |
| 3842 | |
| 3843 | if (!haveGroup) { |
| 3844 | haveGroup = true; |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3845 | curGroup = atoken.groupId; |
| 3846 | lastOrientation = atoken.requestedOrientation; |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 3847 | } |
p13451 | 0445bc6 | 2012-04-18 15:13:26 +0900 | [diff] [blame] | 3848 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3849 | int or = atoken.requestedOrientation; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3850 | // If this application is fullscreen, and didn't explicitly say |
| 3851 | // to use the orientation behind it, then just take whatever |
| 3852 | // orientation it has and ignores whatever is under it. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3853 | lastFullscreen = atoken.appFullscreen; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3854 | if (lastFullscreen |
| 3855 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3856 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Done at " + atoken |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 3857 | + " -- full screen, return " + or); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3858 | return or; |
| 3859 | } |
| 3860 | // If this application has requested an explicit orientation, |
| 3861 | // then use it. |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 3862 | if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 3863 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3864 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Done at " + atoken |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 3865 | + " -- explicitly set, return " + or); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3866 | return or; |
| 3867 | } |
| 3868 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| 3869 | } |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 3870 | if (DEBUG_ORIENTATION) Slog.v(TAG, "No app is requesting an orientation"); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3871 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3872 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3873 | |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 3874 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3875 | public Configuration updateOrientationFromAppTokens( |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3876 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3877 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3878 | "updateOrientationFromAppTokens()")) { |
| 3879 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3880 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3881 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3882 | Configuration config = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3883 | long ident = Binder.clearCallingIdentity(); |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 3884 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3885 | synchronized(mWindowMap) { |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 3886 | config = updateOrientationFromAppTokensLocked(currentConfig, |
| 3887 | freezeThisOneIfNeeded); |
| 3888 | } |
| 3889 | |
| 3890 | Binder.restoreCallingIdentity(ident); |
| 3891 | return config; |
| 3892 | } |
| 3893 | |
| 3894 | private Configuration updateOrientationFromAppTokensLocked( |
| 3895 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
| 3896 | Configuration config = null; |
| 3897 | |
| 3898 | if (updateOrientationFromAppTokensLocked(false)) { |
| 3899 | if (freezeThisOneIfNeeded != null) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3900 | AppWindowToken atoken = findAppWindowToken( |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 3901 | freezeThisOneIfNeeded); |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3902 | if (atoken != null) { |
| 3903 | startAppFreezingScreenLocked(atoken, |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 3904 | ActivityInfo.CONFIG_ORIENTATION); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3905 | } |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 3906 | } |
| 3907 | config = computeNewConfigurationLocked(); |
| 3908 | |
| 3909 | } else if (currentConfig != null) { |
| 3910 | // No obvious action we need to take, but if our current |
| 3911 | // state mismatches the activity manager's, update it, |
| 3912 | // disregarding font scale, which should remain set to |
| 3913 | // the value of the previous configuration. |
| 3914 | mTempConfiguration.setToDefaults(); |
| 3915 | mTempConfiguration.fontScale = currentConfig.fontScale; |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 3916 | if (computeScreenConfigurationLocked(mTempConfiguration)) { |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 3917 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3918 | mWaitingForConfig = true; |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3919 | getDefaultDisplayContentLocked().layoutNeeded = true; |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 3920 | startFreezingDisplayLocked(false, 0, 0); |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 3921 | config = new Configuration(mTempConfiguration); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3922 | } |
| 3923 | } |
| 3924 | } |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 3925 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3926 | return config; |
| 3927 | } |
| 3928 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3929 | /* |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3930 | * Determine the new desired orientation of the display, returning |
| 3931 | * a non-null new Configuration if it has changed from the current |
| 3932 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3933 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3934 | * SCREEN. This will typically be done for you if you call |
| 3935 | * sendNewConfiguration(). |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 3936 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3937 | * The orientation is computed from non-application windows first. If none of |
| 3938 | * the non-application windows specify orientation, the orientation is computed from |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3939 | * application tokens. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3940 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3941 | * android.os.IBinder) |
| 3942 | */ |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3943 | boolean updateOrientationFromAppTokensLocked(boolean inTransaction) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3944 | long ident = Binder.clearCallingIdentity(); |
| 3945 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3946 | int req = computeForcedAppOrientationLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3947 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3948 | if (req != mForcedAppOrientation) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3949 | mForcedAppOrientation = req; |
| 3950 | //send a message to Policy indicating orientation change to take |
| 3951 | //action like disabling/enabling sensors etc., |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3952 | mPolicy.setCurrentOrientationLw(req); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 3953 | if (updateRotationUncheckedLocked(inTransaction)) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 3954 | // changed |
| 3955 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3956 | } |
| 3957 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3958 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 3959 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3960 | } finally { |
| 3961 | Binder.restoreCallingIdentity(ident); |
| 3962 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3963 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3964 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3965 | int computeForcedAppOrientationLocked() { |
| 3966 | int req = getOrientationFromWindowsLocked(); |
| 3967 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3968 | req = getOrientationFromAppTokensLocked(); |
| 3969 | } |
| 3970 | return req; |
| 3971 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3972 | |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 3973 | @Override |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3974 | public void setNewConfiguration(Configuration config) { |
| 3975 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3976 | "setNewConfiguration()")) { |
| 3977 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3978 | } |
| 3979 | |
| 3980 | synchronized(mWindowMap) { |
| 3981 | mCurConfiguration = new Configuration(config); |
| 3982 | mWaitingForConfig = false; |
| 3983 | performLayoutAndPlaceSurfacesLocked(); |
| 3984 | } |
| 3985 | } |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 3986 | |
| 3987 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3988 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3989 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3990 | "setAppOrientation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3991 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3992 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3993 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3994 | synchronized(mWindowMap) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 3995 | AppWindowToken atoken = findAppWindowToken(token.asBinder()); |
| 3996 | if (atoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3997 | 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] | 3998 | return; |
| 3999 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4000 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 4001 | atoken.requestedOrientation = requestedOrientation; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4002 | } |
| 4003 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4004 | |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 4005 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4006 | public int getAppOrientation(IApplicationToken token) { |
| 4007 | synchronized(mWindowMap) { |
| 4008 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 4009 | if (wtoken == null) { |
| 4010 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 4011 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4012 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4013 | return wtoken.requestedOrientation; |
| 4014 | } |
| 4015 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4016 | |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 4017 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4018 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 4019 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4020 | "setFocusedApp()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4021 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4022 | } |
| 4023 | |
| 4024 | synchronized(mWindowMap) { |
| 4025 | boolean changed = false; |
| 4026 | if (token == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4027 | 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] | 4028 | changed = mFocusedApp != null; |
| 4029 | mFocusedApp = null; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4030 | if (changed) { |
| 4031 | mInputMonitor.setFocusedAppLw(null); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 4032 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4033 | } else { |
| 4034 | AppWindowToken newFocus = findAppWindowToken(token); |
| 4035 | if (newFocus == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4036 | 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] | 4037 | return; |
| 4038 | } |
| 4039 | changed = mFocusedApp != newFocus; |
| 4040 | mFocusedApp = newFocus; |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 4041 | if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp |
| 4042 | + " moveFocusNow=" + moveFocusNow); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4043 | if (changed) { |
| 4044 | mInputMonitor.setFocusedAppLw(newFocus); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 4045 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4046 | } |
| 4047 | |
| 4048 | if (moveFocusNow && changed) { |
| 4049 | final long origId = Binder.clearCallingIdentity(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4050 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4051 | Binder.restoreCallingIdentity(origId); |
| 4052 | } |
| 4053 | } |
| 4054 | } |
| 4055 | |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 4056 | @Override |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 4057 | public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4058 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4059 | "prepareAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4060 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4061 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4062 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4063 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4064 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4065 | TAG, "Prepare app transition: transit=" + transit |
Craig Mautner | 0afddcb | 2012-05-08 15:38:00 -0700 | [diff] [blame] | 4066 | + " mNextAppTransition=" + mNextAppTransition |
Craig Mautner | 1d961d4 | 2012-05-27 12:02:11 -0700 | [diff] [blame] | 4067 | + " alwaysKeepCurrent=" + alwaysKeepCurrent |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 4068 | + " Callers=" + Debug.getCallers(3)); |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 4069 | if (okToDisplay()) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4070 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 4071 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4072 | mNextAppTransition = transit; |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 4073 | } else if (!alwaysKeepCurrent) { |
| 4074 | if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 4075 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 4076 | // Opening a new task always supersedes a close for the anim. |
| 4077 | mNextAppTransition = transit; |
| 4078 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 4079 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 4080 | // Opening a new activity always supersedes a close for the anim. |
| 4081 | mNextAppTransition = transit; |
| 4082 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4083 | } |
| 4084 | mAppTransitionReady = false; |
| 4085 | mAppTransitionTimeout = false; |
| 4086 | mStartingIconInTransition = false; |
| 4087 | mSkipAppTransitionAnimation = false; |
| 4088 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 4089 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 4090 | 5000); |
| 4091 | } |
| 4092 | } |
| 4093 | } |
| 4094 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 4095 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4096 | public int getPendingAppTransition() { |
| 4097 | return mNextAppTransition; |
| 4098 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4099 | |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 4100 | private void scheduleAnimationCallback(IRemoteCallback cb) { |
| 4101 | if (cb != null) { |
| 4102 | mH.sendMessage(mH.obtainMessage(H.DO_ANIMATION_CALLBACK, cb)); |
| 4103 | } |
| 4104 | } |
| 4105 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 4106 | @Override |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 4107 | public void overridePendingAppTransition(String packageName, |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 4108 | int enterAnim, int exitAnim, IRemoteCallback startedCallback) { |
| 4109 | synchronized(mWindowMap) { |
| 4110 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 4111 | mNextAppTransitionType = ActivityOptions.ANIM_CUSTOM; |
| 4112 | mNextAppTransitionPackage = packageName; |
| 4113 | mNextAppTransitionThumbnail = null; |
| 4114 | mNextAppTransitionEnter = enterAnim; |
| 4115 | mNextAppTransitionExit = exitAnim; |
| 4116 | scheduleAnimationCallback(mNextAppTransitionCallback); |
| 4117 | mNextAppTransitionCallback = startedCallback; |
| 4118 | } else { |
| 4119 | scheduleAnimationCallback(startedCallback); |
| 4120 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 4121 | } |
| 4122 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4123 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 4124 | @Override |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 4125 | public void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth, |
| 4126 | int startHeight) { |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 4127 | synchronized(mWindowMap) { |
| 4128 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 4129 | mNextAppTransitionType = ActivityOptions.ANIM_SCALE_UP; |
| 4130 | mNextAppTransitionPackage = null; |
| 4131 | mNextAppTransitionThumbnail = null; |
| 4132 | mNextAppTransitionStartX = startX; |
| 4133 | mNextAppTransitionStartY = startY; |
| 4134 | mNextAppTransitionStartWidth = startWidth; |
| 4135 | mNextAppTransitionStartHeight = startHeight; |
| 4136 | scheduleAnimationCallback(mNextAppTransitionCallback); |
| 4137 | mNextAppTransitionCallback = null; |
| 4138 | } |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 4139 | } |
| 4140 | } |
| 4141 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 4142 | @Override |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 4143 | public void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 4144 | int startY, IRemoteCallback startedCallback, boolean scaleUp) { |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 4145 | synchronized(mWindowMap) { |
| 4146 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 4147 | mNextAppTransitionType = scaleUp |
| 4148 | ? ActivityOptions.ANIM_THUMBNAIL_SCALE_UP : ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN; |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 4149 | mNextAppTransitionPackage = null; |
| 4150 | mNextAppTransitionThumbnail = srcThumb; |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 4151 | mNextAppTransitionScaleUp = scaleUp; |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 4152 | mNextAppTransitionStartX = startX; |
| 4153 | mNextAppTransitionStartY = startY; |
| 4154 | scheduleAnimationCallback(mNextAppTransitionCallback); |
| 4155 | mNextAppTransitionCallback = startedCallback; |
| 4156 | } else { |
| 4157 | scheduleAnimationCallback(startedCallback); |
| 4158 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 4159 | } |
| 4160 | } |
| 4161 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 4162 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4163 | public void executeAppTransition() { |
| 4164 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4165 | "executeAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4166 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4167 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4168 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4169 | synchronized(mWindowMap) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 4170 | if (DEBUG_APP_TRANSITIONS) { |
| 4171 | RuntimeException e = new RuntimeException("here"); |
| 4172 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4173 | Slog.w(TAG, "Execute app transition: mNextAppTransition=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 4174 | + mNextAppTransition, e); |
| 4175 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4176 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4177 | mAppTransitionReady = true; |
| 4178 | final long origId = Binder.clearCallingIdentity(); |
| 4179 | performLayoutAndPlaceSurfacesLocked(); |
| 4180 | Binder.restoreCallingIdentity(origId); |
| 4181 | } |
| 4182 | } |
| 4183 | } |
| 4184 | |
| 4185 | public void setAppStartingWindow(IBinder token, String pkg, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 4186 | int theme, CompatibilityInfo compatInfo, |
| 4187 | CharSequence nonLocalizedLabel, int labelRes, int icon, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 4188 | int windowFlags, IBinder transferFrom, boolean createIfNeeded) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4189 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 4190 | "setAppStartingWindow()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4191 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4192 | } |
| 4193 | |
| 4194 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4195 | if (DEBUG_STARTING_WINDOW) Slog.v( |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 4196 | TAG, "setAppStartingWindow: token=" + token + " pkg=" + pkg |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4197 | + " transferFrom=" + transferFrom); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4198 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4199 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4200 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4201 | 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] | 4202 | return; |
| 4203 | } |
| 4204 | |
| 4205 | // If the display is frozen, we won't do anything until the |
| 4206 | // actual window is displayed so there is no reason to put in |
| 4207 | // the starting window. |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 4208 | if (!okToDisplay()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4209 | return; |
| 4210 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4211 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4212 | if (wtoken.startingData != null) { |
| 4213 | return; |
| 4214 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4215 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4216 | if (transferFrom != null) { |
| 4217 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 4218 | if (ttoken != null) { |
| 4219 | WindowState startingWindow = ttoken.startingWindow; |
| 4220 | if (startingWindow != null) { |
| 4221 | if (mStartingIconInTransition) { |
| 4222 | // In this case, the starting icon has already |
| 4223 | // been displayed, so start letting windows get |
| 4224 | // shown immediately without any more transitions. |
| 4225 | mSkipAppTransitionAnimation = true; |
| 4226 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4227 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 4228 | "Moving existing starting " + startingWindow + " from " + ttoken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4229 | + " to " + wtoken); |
| 4230 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4231 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4232 | // Transfer the starting window over to the new |
| 4233 | // token. |
| 4234 | wtoken.startingData = ttoken.startingData; |
| 4235 | wtoken.startingView = ttoken.startingView; |
Craig Mautner | f412095 | 2012-06-21 18:25:39 -0700 | [diff] [blame] | 4236 | wtoken.startingDisplayed = ttoken.startingDisplayed; |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 4237 | ttoken.startingDisplayed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4238 | wtoken.startingWindow = startingWindow; |
Craig Mautner | f412095 | 2012-06-21 18:25:39 -0700 | [diff] [blame] | 4239 | wtoken.reportedVisible = ttoken.reportedVisible; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4240 | ttoken.startingData = null; |
| 4241 | ttoken.startingView = null; |
| 4242 | ttoken.startingWindow = null; |
| 4243 | ttoken.startingMoved = true; |
| 4244 | startingWindow.mToken = wtoken; |
Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 4245 | startingWindow.mRootToken = wtoken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4246 | startingWindow.mAppToken = wtoken; |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 4247 | startingWindow.mWinAnimator.mAppAnimator = wtoken.mAppAnimator; |
| 4248 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 4249 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) { |
| 4250 | Slog.v(TAG, "Removing starting window: " + startingWindow); |
| 4251 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4252 | startingWindow.getWindowList().remove(startingWindow); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4253 | mWindowsChanged = true; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 4254 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, |
| 4255 | "Removing starting " + startingWindow + " from " + ttoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4256 | ttoken.windows.remove(startingWindow); |
| 4257 | ttoken.allAppWindows.remove(startingWindow); |
| 4258 | addWindowToListInOrderLocked(startingWindow, true); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4259 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4260 | // Propagate other interesting state between the |
| 4261 | // tokens. If the old token is displayed, we should |
| 4262 | // immediately force the new one to be displayed. If |
| 4263 | // it is animating, we need to move that animation to |
| 4264 | // the new one. |
| 4265 | if (ttoken.allDrawn) { |
| 4266 | wtoken.allDrawn = true; |
| 4267 | } |
| 4268 | if (ttoken.firstWindowDrawn) { |
| 4269 | wtoken.firstWindowDrawn = true; |
| 4270 | } |
| 4271 | if (!ttoken.hidden) { |
| 4272 | wtoken.hidden = false; |
| 4273 | wtoken.hiddenRequested = false; |
| 4274 | wtoken.willBeHidden = false; |
| 4275 | } |
| 4276 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 4277 | wtoken.clientHidden = ttoken.clientHidden; |
| 4278 | wtoken.sendAppVisibilityToClients(); |
| 4279 | } |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4280 | final AppWindowAnimator tAppAnimator = ttoken.mAppAnimator; |
| 4281 | final AppWindowAnimator wAppAnimator = wtoken.mAppAnimator; |
| 4282 | if (tAppAnimator.animation != null) { |
| 4283 | wAppAnimator.animation = tAppAnimator.animation; |
| 4284 | wAppAnimator.animating = tAppAnimator.animating; |
| 4285 | wAppAnimator.animLayerAdjustment = tAppAnimator.animLayerAdjustment; |
| 4286 | tAppAnimator.animation = null; |
| 4287 | tAppAnimator.animLayerAdjustment = 0; |
| 4288 | wAppAnimator.updateLayers(); |
| 4289 | tAppAnimator.updateLayers(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4290 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4291 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4292 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4293 | true /*updateInputWindows*/); |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 4294 | getDefaultDisplayContentLocked().layoutNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4295 | performLayoutAndPlaceSurfacesLocked(); |
| 4296 | Binder.restoreCallingIdentity(origId); |
| 4297 | return; |
| 4298 | } else if (ttoken.startingData != null) { |
| 4299 | // The previous app was getting ready to show a |
| 4300 | // starting window, but hasn't yet done so. Steal it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4301 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4302 | "Moving pending starting from " + ttoken |
| 4303 | + " to " + wtoken); |
| 4304 | wtoken.startingData = ttoken.startingData; |
| 4305 | ttoken.startingData = null; |
| 4306 | ttoken.startingMoved = true; |
| 4307 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 4308 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 4309 | // want to process the message ASAP, before any other queued |
| 4310 | // messages. |
| 4311 | mH.sendMessageAtFrontOfQueue(m); |
| 4312 | return; |
| 4313 | } |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4314 | final AppWindowAnimator tAppAnimator = ttoken.mAppAnimator; |
| 4315 | final AppWindowAnimator wAppAnimator = wtoken.mAppAnimator; |
| 4316 | if (tAppAnimator.thumbnail != null) { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 4317 | // The old token is animating with a thumbnail, transfer |
| 4318 | // that to the new token. |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4319 | if (wAppAnimator.thumbnail != null) { |
| 4320 | wAppAnimator.thumbnail.destroy(); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 4321 | } |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4322 | wAppAnimator.thumbnail = tAppAnimator.thumbnail; |
| 4323 | wAppAnimator.thumbnailX = tAppAnimator.thumbnailX; |
| 4324 | wAppAnimator.thumbnailY = tAppAnimator.thumbnailY; |
| 4325 | wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer; |
| 4326 | wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation; |
| 4327 | tAppAnimator.thumbnail = null; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 4328 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4329 | } |
| 4330 | } |
| 4331 | |
| 4332 | // There is no existing starting window, and the caller doesn't |
| 4333 | // want us to create one, so that's it! |
| 4334 | if (!createIfNeeded) { |
| 4335 | return; |
| 4336 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4337 | |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 4338 | // If this is a translucent window, then don't |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 4339 | // show a starting window -- the current effect (a full-screen |
| 4340 | // opaque starting window that fades away to the real contents |
| 4341 | // when it is ready) does not work for this. |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 4342 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Checking theme of starting window: 0x" |
| 4343 | + Integer.toHexString(theme)); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 4344 | if (theme != 0) { |
| 4345 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 4346 | com.android.internal.R.styleable.Window); |
Dianne Hackborn | 0b80019 | 2012-06-21 15:29:36 -0700 | [diff] [blame] | 4347 | if (ent == null) { |
| 4348 | // Whoops! App doesn't exist. Um. Okay. We'll just |
| 4349 | // pretend like we didn't see that. |
| 4350 | return; |
| 4351 | } |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 4352 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Translucent=" |
| 4353 | + ent.array.getBoolean( |
| 4354 | com.android.internal.R.styleable.Window_windowIsTranslucent, false) |
| 4355 | + " Floating=" |
| 4356 | + ent.array.getBoolean( |
| 4357 | com.android.internal.R.styleable.Window_windowIsFloating, false) |
| 4358 | + " ShowWallpaper=" |
| 4359 | + ent.array.getBoolean( |
| 4360 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 4361 | if (ent.array.getBoolean( |
| 4362 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 4363 | return; |
| 4364 | } |
| 4365 | if (ent.array.getBoolean( |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 4366 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 4367 | return; |
| 4368 | } |
| 4369 | if (ent.array.getBoolean( |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 4370 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 4371 | if (mWallpaperTarget == null) { |
| 4372 | // If this theme is requesting a wallpaper, and the wallpaper |
| 4373 | // is not curently visible, then this effectively serves as |
| 4374 | // an opaque window and our starting window transition animation |
| 4375 | // can still work. We just need to make sure the starting window |
| 4376 | // is also showing the wallpaper. |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 4377 | windowFlags |= FLAG_SHOW_WALLPAPER; |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 4378 | } else { |
| 4379 | return; |
| 4380 | } |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 4381 | } |
| 4382 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4383 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 4384 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Creating StartingData"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4385 | mStartingIconInTransition = true; |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 4386 | wtoken.startingData = new StartingData(pkg, theme, compatInfo, nonLocalizedLabel, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 4387 | labelRes, icon, windowFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4388 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 4389 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 4390 | // want to process the message ASAP, before any other queued |
| 4391 | // messages. |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 4392 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Enqueueing ADD_STARTING"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4393 | mH.sendMessageAtFrontOfQueue(m); |
| 4394 | } |
| 4395 | } |
| 4396 | |
| 4397 | public void setAppWillBeHidden(IBinder token) { |
| 4398 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4399 | "setAppWillBeHidden()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4400 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4401 | } |
| 4402 | |
| 4403 | AppWindowToken wtoken; |
| 4404 | |
| 4405 | synchronized(mWindowMap) { |
| 4406 | wtoken = findAppWindowToken(token); |
| 4407 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4408 | 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] | 4409 | return; |
| 4410 | } |
| 4411 | wtoken.willBeHidden = true; |
| 4412 | } |
| 4413 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4414 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4415 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 4416 | boolean visible, int transit, boolean performLayout) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4417 | boolean delayed = false; |
| 4418 | |
| 4419 | if (wtoken.clientHidden == visible) { |
| 4420 | wtoken.clientHidden = !visible; |
| 4421 | wtoken.sendAppVisibilityToClients(); |
| 4422 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4423 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4424 | wtoken.willBeHidden = false; |
| 4425 | if (wtoken.hidden == visible) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4426 | boolean changed = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4427 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4428 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 4429 | + " performLayout=" + performLayout); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4430 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4431 | boolean runningAppAnimation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4432 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4433 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
Craig Mautner | fbf378c | 2012-04-23 17:24:21 -0700 | [diff] [blame] | 4434 | if (wtoken.mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) { |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4435 | wtoken.mAppAnimator.animation = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4436 | } |
Craig Mautner | f20588f | 2012-04-11 17:06:21 -0700 | [diff] [blame] | 4437 | if (applyAnimationLocked(wtoken, lp, transit, visible)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4438 | delayed = runningAppAnimation = true; |
| 4439 | } |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 4440 | WindowState window = wtoken.findMainWindow(); |
| 4441 | if (window != null) { |
| 4442 | scheduleNotifyWindowTranstionIfNeededLocked(window, transit); |
| 4443 | } |
Craig Mautner | f20588f | 2012-04-11 17:06:21 -0700 | [diff] [blame] | 4444 | changed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4445 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4446 | |
Craig Mautner | f20588f | 2012-04-11 17:06:21 -0700 | [diff] [blame] | 4447 | final int N = wtoken.allAppWindows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4448 | for (int i=0; i<N; i++) { |
| 4449 | WindowState win = wtoken.allAppWindows.get(i); |
| 4450 | if (win == wtoken.startingWindow) { |
| 4451 | continue; |
| 4452 | } |
| 4453 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4454 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4455 | //win.dump(" "); |
| 4456 | if (visible) { |
| 4457 | if (!win.isVisibleNow()) { |
| 4458 | if (!runningAppAnimation) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 4459 | win.mWinAnimator.applyAnimationLocked( |
| 4460 | WindowManagerPolicy.TRANSIT_ENTER, true); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 4461 | scheduleNotifyWindowTranstionIfNeededLocked(win, |
| 4462 | WindowManagerPolicy.TRANSIT_ENTER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4463 | } |
| 4464 | changed = true; |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 4465 | win.mDisplayContent.layoutNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4466 | } |
| 4467 | } else if (win.isVisibleNow()) { |
| 4468 | if (!runningAppAnimation) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 4469 | win.mWinAnimator.applyAnimationLocked( |
| 4470 | WindowManagerPolicy.TRANSIT_EXIT, false); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 4471 | scheduleNotifyWindowTranstionIfNeededLocked(win, |
| 4472 | WindowManagerPolicy.TRANSIT_EXIT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4473 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4474 | changed = true; |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 4475 | win.mDisplayContent.layoutNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4476 | } |
| 4477 | } |
| 4478 | |
| 4479 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 4480 | if (!visible) { |
| 4481 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 4482 | } else { |
| 4483 | // If we are being set visible, and the starting window is |
| 4484 | // not yet displayed, then make sure it doesn't get displayed. |
| 4485 | WindowState swin = wtoken.startingWindow; |
Craig Mautner | bf90eaa | 2012-03-15 11:28:53 -0700 | [diff] [blame] | 4486 | if (swin != null && !swin.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4487 | swin.mPolicyVisibility = false; |
| 4488 | swin.mPolicyVisibilityAfterAnim = false; |
| 4489 | } |
| 4490 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4491 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4492 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4493 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 4494 | + wtoken.hiddenRequested); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4495 | |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 4496 | if (changed) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4497 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 4498 | if (performLayout) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4499 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4500 | false /*updateInputWindows*/); |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 4501 | performLayoutAndPlaceSurfacesLocked(); |
| 4502 | } |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4503 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4504 | } |
| 4505 | } |
| 4506 | |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4507 | if (wtoken.mAppAnimator.animation != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4508 | delayed = true; |
| 4509 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4510 | |
Craig Mautner | f20588f | 2012-04-11 17:06:21 -0700 | [diff] [blame] | 4511 | for (int i = wtoken.allAppWindows.size() - 1; i >= 0 && !delayed; i--) { |
| 4512 | if (wtoken.allAppWindows.get(i).mWinAnimator.isWindowAnimating()) { |
| 4513 | delayed = true; |
| 4514 | } |
| 4515 | } |
| 4516 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4517 | return delayed; |
| 4518 | } |
| 4519 | |
| 4520 | public void setAppVisibility(IBinder token, boolean visible) { |
| 4521 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4522 | "setAppVisibility()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4523 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4524 | } |
| 4525 | |
| 4526 | AppWindowToken wtoken; |
| 4527 | |
| 4528 | synchronized(mWindowMap) { |
| 4529 | wtoken = findAppWindowToken(token); |
| 4530 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4531 | 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] | 4532 | return; |
| 4533 | } |
| 4534 | |
| 4535 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 4536 | RuntimeException e = null; |
| 4537 | if (!HIDE_STACK_CRAWLS) { |
| 4538 | e = new RuntimeException(); |
| 4539 | e.fillInStackTrace(); |
| 4540 | } |
Craig Mautner | 0afddcb | 2012-05-08 15:38:00 -0700 | [diff] [blame] | 4541 | Slog.v(TAG, "setAppVisibility(" + token + ", visible=" + visible |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4542 | + "): mNextAppTransition=" + mNextAppTransition |
| 4543 | + " hidden=" + wtoken.hidden |
| 4544 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 4545 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4546 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4547 | // If we are preparing an app transition, then delay changing |
| 4548 | // the visibility of this token until we execute that transition. |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 4549 | if (okToDisplay() && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4550 | // Already in requested state, don't do anything more. |
| 4551 | if (wtoken.hiddenRequested != visible) { |
| 4552 | return; |
| 4553 | } |
| 4554 | wtoken.hiddenRequested = !visible; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4555 | |
Craig Mautner | f412095 | 2012-06-21 18:25:39 -0700 | [diff] [blame] | 4556 | if (!wtoken.startingDisplayed) { |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 4557 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| 4558 | TAG, "Setting dummy animation on: " + wtoken); |
Craig Mautner | f412095 | 2012-06-21 18:25:39 -0700 | [diff] [blame] | 4559 | wtoken.mAppAnimator.setDummyAnimation(); |
| 4560 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4561 | mOpeningApps.remove(wtoken); |
| 4562 | mClosingApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4563 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4564 | wtoken.inPendingTransaction = true; |
| 4565 | if (visible) { |
| 4566 | mOpeningApps.add(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4567 | wtoken.startingMoved = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4568 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4569 | // If the token is currently hidden (should be the |
| 4570 | // common case), then we need to set up to wait for |
| 4571 | // its windows to be ready. |
| 4572 | if (wtoken.hidden) { |
| 4573 | wtoken.allDrawn = false; |
| 4574 | wtoken.waitingToShow = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4575 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4576 | if (wtoken.clientHidden) { |
| 4577 | // In the case where we are making an app visible |
| 4578 | // but holding off for a transition, we still need |
| 4579 | // to tell the client to make its windows visible so |
| 4580 | // they get drawn. Otherwise, we will wait on |
| 4581 | // performing the transition until all windows have |
| 4582 | // been drawn, they never will be, and we are sad. |
| 4583 | wtoken.clientHidden = false; |
| 4584 | wtoken.sendAppVisibilityToClients(); |
| 4585 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4586 | } |
| 4587 | } else { |
| 4588 | mClosingApps.add(wtoken); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4589 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4590 | // If the token is currently visible (should be the |
| 4591 | // common case), then set up to wait for it to be hidden. |
| 4592 | if (!wtoken.hidden) { |
| 4593 | wtoken.waitingToHide = true; |
| 4594 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4595 | } |
| 4596 | return; |
| 4597 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4598 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4599 | final long origId = Binder.clearCallingIdentity(); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4600 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 4601 | true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4602 | wtoken.updateReportedVisibilityLocked(); |
| 4603 | Binder.restoreCallingIdentity(origId); |
| 4604 | } |
| 4605 | } |
| 4606 | |
| 4607 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4608 | boolean unfreezeSurfaceNow, boolean force) { |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4609 | if (wtoken.mAppAnimator.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4610 | 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] | 4611 | + " force=" + force); |
| 4612 | final int N = wtoken.allAppWindows.size(); |
| 4613 | boolean unfrozeWindows = false; |
| 4614 | for (int i=0; i<N; i++) { |
| 4615 | WindowState w = wtoken.allAppWindows.get(i); |
| 4616 | if (w.mAppFreezing) { |
| 4617 | w.mAppFreezing = false; |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 4618 | if (w.mHasSurface && !w.mOrientationChanging) { |
Dianne Hackborn | 3ec891a | 2011-10-25 13:58:30 -0700 | [diff] [blame] | 4619 | if (DEBUG_ORIENTATION) Slog.v(TAG, "set mOrientationChanging of " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4620 | w.mOrientationChanging = true; |
Craig Mautner | 3255a28 | 2012-04-16 15:42:47 -0700 | [diff] [blame] | 4621 | mInnerFields.mOrientationChangeComplete = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4622 | } |
| 4623 | unfrozeWindows = true; |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 4624 | w.mDisplayContent.layoutNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4625 | } |
| 4626 | } |
| 4627 | if (force || unfrozeWindows) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4628 | if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4629 | wtoken.mAppAnimator.freezingScreen = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4630 | mAppsFreezingScreen--; |
| 4631 | } |
| 4632 | if (unfreezeSurfaceNow) { |
| 4633 | if (unfrozeWindows) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4634 | performLayoutAndPlaceSurfacesLocked(); |
| 4635 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4636 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4637 | } |
| 4638 | } |
| 4639 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4640 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4641 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4642 | int configChanges) { |
| 4643 | if (DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 4644 | RuntimeException e = null; |
| 4645 | if (!HIDE_STACK_CRAWLS) { |
| 4646 | e = new RuntimeException(); |
| 4647 | e.fillInStackTrace(); |
| 4648 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4649 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4650 | + ": hidden=" + wtoken.hidden + " freezing=" |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4651 | + wtoken.mAppAnimator.freezingScreen, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4652 | } |
| 4653 | if (!wtoken.hiddenRequested) { |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4654 | if (!wtoken.mAppAnimator.freezingScreen) { |
| 4655 | wtoken.mAppAnimator.freezingScreen = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4656 | mAppsFreezingScreen++; |
| 4657 | if (mAppsFreezingScreen == 1) { |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 4658 | startFreezingDisplayLocked(false, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4659 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 4660 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 4661 | 5000); |
| 4662 | } |
| 4663 | } |
| 4664 | final int N = wtoken.allAppWindows.size(); |
| 4665 | for (int i=0; i<N; i++) { |
| 4666 | WindowState w = wtoken.allAppWindows.get(i); |
| 4667 | w.mAppFreezing = true; |
| 4668 | } |
| 4669 | } |
| 4670 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4671 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4672 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 4673 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4674 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4675 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4676 | } |
| 4677 | |
| 4678 | synchronized(mWindowMap) { |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 4679 | if (configChanges == 0 && okToDisplay()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4680 | 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] | 4681 | return; |
| 4682 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4683 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4684 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4685 | if (wtoken == null || wtoken.appToken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4686 | 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] | 4687 | return; |
| 4688 | } |
| 4689 | final long origId = Binder.clearCallingIdentity(); |
| 4690 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 4691 | Binder.restoreCallingIdentity(origId); |
| 4692 | } |
| 4693 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4694 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4695 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 4696 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4697 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4698 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4699 | } |
| 4700 | |
| 4701 | synchronized(mWindowMap) { |
| 4702 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4703 | if (wtoken == null || wtoken.appToken == null) { |
| 4704 | return; |
| 4705 | } |
| 4706 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4707 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4708 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.mAppAnimator.freezingScreen); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4709 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 4710 | Binder.restoreCallingIdentity(origId); |
| 4711 | } |
| 4712 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4713 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4714 | public void removeAppToken(IBinder token) { |
| 4715 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4716 | "removeAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4717 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4718 | } |
| 4719 | |
| 4720 | AppWindowToken wtoken = null; |
| 4721 | AppWindowToken startingToken = null; |
| 4722 | boolean delayed = false; |
| 4723 | |
| 4724 | final long origId = Binder.clearCallingIdentity(); |
| 4725 | synchronized(mWindowMap) { |
| 4726 | WindowToken basewtoken = mTokenMap.remove(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4727 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4728 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4729 | delayed = setTokenVisibilityLocked(wtoken, null, false, |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 4730 | WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4731 | wtoken.inPendingTransaction = false; |
| 4732 | mOpeningApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4733 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4734 | if (mClosingApps.contains(wtoken)) { |
| 4735 | delayed = true; |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4736 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4737 | mClosingApps.add(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4738 | wtoken.waitingToHide = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4739 | delayed = true; |
| 4740 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4741 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4742 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4743 | + " animation=" + wtoken.mAppAnimator.animation |
| 4744 | + " animating=" + wtoken.mAppAnimator.animating); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4745 | if (delayed) { |
| 4746 | // 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] | 4747 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4748 | "removeAppToken make exiting: " + wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4749 | mExitingAppTokens.add(wtoken); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 4750 | } else { |
| 4751 | // Make sure there is no animation running on this token, |
| 4752 | // so any windows associated with it will be removed as |
| 4753 | // soon as their animations are complete |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 4754 | wtoken.mAppAnimator.clearAnimation(); |
| 4755 | wtoken.mAppAnimator.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4756 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4757 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4758 | "removeAppToken: " + wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4759 | mAppTokens.remove(wtoken); |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 4760 | mAnimatingAppTokens.remove(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4761 | wtoken.removed = true; |
| 4762 | if (wtoken.startingData != null) { |
| 4763 | startingToken = wtoken; |
| 4764 | } |
| 4765 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 4766 | if (mFocusedApp == wtoken) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4767 | 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] | 4768 | mFocusedApp = null; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4769 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4770 | mInputMonitor.setFocusedAppLw(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4771 | } |
| 4772 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4773 | 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] | 4774 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4775 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4776 | if (!delayed && wtoken != null) { |
| 4777 | wtoken.updateReportedVisibilityLocked(); |
| 4778 | } |
| 4779 | } |
| 4780 | Binder.restoreCallingIdentity(origId); |
| 4781 | |
| 4782 | if (startingToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4783 | 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] | 4784 | + startingToken + ": app token removed"); |
| 4785 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 4786 | mH.sendMessage(m); |
| 4787 | } |
| 4788 | } |
| 4789 | |
| 4790 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 4791 | final int NW = token.windows.size(); |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 4792 | if (NW > 0) { |
| 4793 | mWindowsChanged = true; |
| 4794 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4795 | for (int i=0; i<NW; i++) { |
| 4796 | WindowState win = token.windows.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4797 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4798 | win.getWindowList().remove(win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4799 | int j = win.mChildWindows.size(); |
| 4800 | while (j > 0) { |
| 4801 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4802 | WindowState cwin = win.mChildWindows.get(j); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4803 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4804 | "Tmp removing child window " + cwin); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4805 | cwin.getWindowList().remove(cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4806 | } |
| 4807 | } |
| 4808 | return NW > 0; |
| 4809 | } |
| 4810 | |
| 4811 | void dumpAppTokensLocked() { |
| 4812 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4813 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4814 | } |
| 4815 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4816 | |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 4817 | void dumpAnimatingAppTokensLocked() { |
| 4818 | for (int i=mAnimatingAppTokens.size()-1; i>=0; i--) { |
| 4819 | Slog.v(TAG, " #" + i + ": " + mAnimatingAppTokens.get(i).token); |
| 4820 | } |
| 4821 | } |
| 4822 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4823 | void dumpWindowsLocked() { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4824 | int i = 0; |
| 4825 | final AllWindowsIterator iterator = new AllWindowsIterator(REVERSE_ITERATOR); |
| 4826 | while (iterator.hasNext()) { |
| 4827 | final WindowState w = iterator.next(); |
| 4828 | Slog.v(TAG, " #" + i++ + ": " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4829 | } |
| 4830 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4831 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4832 | private int findWindowOffsetLocked(WindowList windows, int tokenPos) { |
| 4833 | final int NW = windows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4834 | |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 4835 | if (tokenPos >= mAnimatingAppTokens.size()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4836 | int i = NW; |
| 4837 | while (i > 0) { |
| 4838 | i--; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4839 | WindowState win = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4840 | if (win.getAppToken() != null) { |
| 4841 | return i+1; |
| 4842 | } |
| 4843 | } |
| 4844 | } |
| 4845 | |
| 4846 | while (tokenPos > 0) { |
| 4847 | // Find the first app token below the new position that has |
| 4848 | // a window displayed. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4849 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4850 | 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] | 4851 | + tokenPos + " -- " + wtoken.token); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4852 | if (wtoken.sendingToBottom) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4853 | if (DEBUG_REORDER) Slog.v(TAG, |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4854 | "Skipping token -- currently sending to bottom"); |
| 4855 | tokenPos--; |
| 4856 | continue; |
| 4857 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4858 | int i = wtoken.windows.size(); |
| 4859 | while (i > 0) { |
| 4860 | i--; |
| 4861 | WindowState win = wtoken.windows.get(i); |
| 4862 | int j = win.mChildWindows.size(); |
| 4863 | while (j > 0) { |
| 4864 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4865 | WindowState cwin = win.mChildWindows.get(j); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4866 | if (cwin.mSubLayer >= 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4867 | for (int pos=NW-1; pos>=0; pos--) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4868 | if (windows.get(pos) == cwin) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4869 | if (DEBUG_REORDER) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4870 | "Found child win @" + (pos+1)); |
| 4871 | return pos+1; |
| 4872 | } |
| 4873 | } |
| 4874 | } |
| 4875 | } |
| 4876 | for (int pos=NW-1; pos>=0; pos--) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4877 | if (windows.get(pos) == win) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4878 | 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] | 4879 | return pos+1; |
| 4880 | } |
| 4881 | } |
| 4882 | } |
| 4883 | tokenPos--; |
| 4884 | } |
| 4885 | |
| 4886 | return 0; |
| 4887 | } |
| 4888 | |
| 4889 | private final int reAddWindowLocked(int index, WindowState win) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4890 | final WindowList windows = win.getWindowList(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4891 | final int NCW = win.mChildWindows.size(); |
| 4892 | boolean added = false; |
| 4893 | for (int j=0; j<NCW; j++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4894 | WindowState cwin = win.mChildWindows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4895 | if (!added && cwin.mSubLayer >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4896 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4897 | + index + ": " + cwin); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4898 | win.mRebuilding = false; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4899 | windows.add(index, win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4900 | index++; |
| 4901 | added = true; |
| 4902 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4903 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4904 | + index + ": " + cwin); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4905 | cwin.mRebuilding = false; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4906 | windows.add(index, cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4907 | index++; |
| 4908 | } |
| 4909 | if (!added) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4910 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4911 | + index + ": " + win); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4912 | win.mRebuilding = false; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4913 | windows.add(index, win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4914 | index++; |
| 4915 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4916 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4917 | return index; |
| 4918 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4919 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4920 | private final int reAddAppWindowsLocked(final DisplayContent displayContent, int index, |
| 4921 | WindowToken token) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4922 | final int NW = token.windows.size(); |
| 4923 | for (int i=0; i<NW; i++) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4924 | final WindowState win = token.windows.get(i); |
| 4925 | if (win.mDisplayContent == displayContent) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4926 | index = reAddWindowLocked(index, win); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4927 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4928 | } |
| 4929 | return index; |
| 4930 | } |
| 4931 | |
| 4932 | public void moveAppToken(int index, IBinder token) { |
| 4933 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4934 | "moveAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4935 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4936 | } |
| 4937 | |
| 4938 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4939 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4940 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 4941 | final AppWindowToken wtoken = findAppWindowToken(token); |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 4942 | final int oldIndex = mAppTokens.indexOf(wtoken); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4943 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG, |
| 4944 | "Start moving token " + wtoken + " initially at " |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 4945 | + oldIndex); |
| 4946 | if (oldIndex > index && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET |
| 4947 | && !mAppTransitionRunning) { |
| 4948 | // animation towards back has not started, copy old list for duration of animation. |
| 4949 | mAnimatingAppTokens.clear(); |
| 4950 | mAnimatingAppTokens.addAll(mAppTokens); |
| 4951 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4952 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4953 | 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] | 4954 | + token + " (" + wtoken + ")"); |
| 4955 | return; |
| 4956 | } |
| 4957 | mAppTokens.add(index, wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4958 | if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4959 | 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] | 4960 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 4961 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET && !mAppTransitionRunning) { |
| 4962 | // Not animating, bring animating app list in line with mAppTokens. |
| 4963 | mAnimatingAppTokens.clear(); |
| 4964 | mAnimatingAppTokens.addAll(mAppTokens); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4965 | |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 4966 | // Bring window ordering, window focus and input window in line with new app token |
| 4967 | final long origId = Binder.clearCallingIdentity(); |
| 4968 | 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] | 4969 | if (DEBUG_REORDER) dumpWindowsLocked(); |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 4970 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
| 4971 | if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:"); |
| 4972 | if (DEBUG_REORDER) dumpWindowsLocked(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4973 | DisplayContentsIterator iterator = new DisplayContentsIterator(); |
| 4974 | while(iterator.hasNext()) { |
| 4975 | final DisplayContent displayContent = iterator.next(); |
| 4976 | final WindowList windows = displayContent.getWindowList(); |
| 4977 | final int pos = findWindowOffsetLocked(windows, index); |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 4978 | final int newPos = reAddAppWindowsLocked(displayContent, pos, wtoken); |
| 4979 | if (pos != newPos) { |
| 4980 | displayContent.layoutNeeded = true; |
| 4981 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 4982 | } |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 4983 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
| 4984 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4985 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4986 | false /*updateInputWindows*/); |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 4987 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 4988 | performLayoutAndPlaceSurfacesLocked(); |
| 4989 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
| 4990 | } |
| 4991 | Binder.restoreCallingIdentity(origId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4992 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4993 | } |
| 4994 | } |
| 4995 | |
| 4996 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 4997 | // XXX This should be done more efficiently! |
| 4998 | // (take advantage of the fact that both lists should be |
| 4999 | // ordered in the same way.) |
| 5000 | int N = tokens.size(); |
| 5001 | for (int i=0; i<N; i++) { |
| 5002 | IBinder token = tokens.get(i); |
| 5003 | final AppWindowToken wtoken = findAppWindowToken(token); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5004 | if (DEBUG_REORDER || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 5005 | "Temporarily removing " + wtoken + " from " + mAppTokens.indexOf(wtoken)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5006 | if (!mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5007 | 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] | 5008 | + token + " (" + wtoken + ")"); |
| 5009 | i--; |
| 5010 | N--; |
| 5011 | } |
| 5012 | } |
| 5013 | } |
| 5014 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 5015 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 5016 | boolean updateFocusAndLayout) { |
| 5017 | // First remove all of the windows from the list. |
| 5018 | tmpRemoveAppWindowsLocked(wtoken); |
| 5019 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 5020 | // And now add them back at the correct place. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5021 | DisplayContentsIterator iterator = new DisplayContentsIterator(); |
| 5022 | while (iterator.hasNext()) { |
| 5023 | final DisplayContent displayContent = iterator.next(); |
| 5024 | final WindowList windows = displayContent.getWindowList(); |
| 5025 | final int pos = findWindowOffsetLocked(windows, tokenPos); |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 5026 | final int newPos = reAddAppWindowsLocked(displayContent, pos, wtoken); |
| 5027 | if (pos != newPos) { |
| 5028 | displayContent.layoutNeeded = true; |
| 5029 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5030 | |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 5031 | if (updateFocusAndLayout && !updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5032 | false /*updateInputWindows*/)) { |
| 5033 | assignLayersLocked(windows); |
| 5034 | } |
| 5035 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 5036 | |
| 5037 | if (updateFocusAndLayout) { |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 5038 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5039 | |
| 5040 | // Note that the above updateFocusedWindowLocked conditional used to sit here. |
| 5041 | |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 5042 | if (!mInLayout) { |
| 5043 | performLayoutAndPlaceSurfacesLocked(); |
| 5044 | } |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 5045 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 5046 | } |
| 5047 | } |
| 5048 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5049 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 5050 | // First remove all of the windows from the list. |
| 5051 | final int N = tokens.size(); |
| 5052 | int i; |
| 5053 | for (i=0; i<N; i++) { |
| 5054 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 5055 | if (token != null) { |
| 5056 | tmpRemoveAppWindowsLocked(token); |
| 5057 | } |
| 5058 | } |
| 5059 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5060 | // And now add them back at the correct place. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5061 | DisplayContentsIterator iterator = new DisplayContentsIterator(); |
| 5062 | while (iterator.hasNext()) { |
| 5063 | final DisplayContent displayContent = iterator.next(); |
| 5064 | final WindowList windows = displayContent.getWindowList(); |
| 5065 | // Where to start adding? |
| 5066 | int pos = findWindowOffsetLocked(windows, tokenPos); |
| 5067 | for (i=0; i<N; i++) { |
| 5068 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 5069 | if (token != null) { |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 5070 | final int newPos = reAddAppWindowsLocked(displayContent, pos, token); |
| 5071 | if (newPos != pos) { |
| 5072 | displayContent.layoutNeeded = true; |
| 5073 | } |
| 5074 | pos = newPos; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5075 | } |
| 5076 | } |
| 5077 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 5078 | false /*updateInputWindows*/)) { |
| 5079 | assignLayersLocked(windows); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5080 | } |
| 5081 | } |
| 5082 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 5083 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5084 | |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 5085 | // Note that the above updateFocusedWindowLocked used to sit here. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5086 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5087 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 5088 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5089 | |
| 5090 | //dump(); |
| 5091 | } |
| 5092 | |
| 5093 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 5094 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5095 | "moveAppTokensToTop()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5096 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5097 | } |
| 5098 | |
| 5099 | final long origId = Binder.clearCallingIdentity(); |
| 5100 | synchronized(mWindowMap) { |
| 5101 | removeAppTokensLocked(tokens); |
| 5102 | final int N = tokens.size(); |
| 5103 | for (int i=0; i<N; i++) { |
| 5104 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 5105 | if (wt != null) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5106 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG, |
| 5107 | "Adding next to top: " + wt); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5108 | mAppTokens.add(wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 5109 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 5110 | wt.sendingToBottom = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 5111 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5112 | } |
| 5113 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5114 | |
Craig Mautner | 06a94f7 | 2012-05-29 10:46:00 -0700 | [diff] [blame] | 5115 | if (!mAppTransitionRunning) { |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 5116 | mAnimatingAppTokens.clear(); |
| 5117 | mAnimatingAppTokens.addAll(mAppTokens); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 5118 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 5119 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5120 | } |
| 5121 | Binder.restoreCallingIdentity(origId); |
| 5122 | } |
| 5123 | |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 5124 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5125 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 5126 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5127 | "moveAppTokensToBottom()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5128 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5129 | } |
| 5130 | |
| 5131 | final long origId = Binder.clearCallingIdentity(); |
| 5132 | synchronized(mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5133 | final int N = tokens.size(); |
Craig Mautner | 06a94f7 | 2012-05-29 10:46:00 -0700 | [diff] [blame] | 5134 | if (N > 0 && !mAppTransitionRunning) { |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 5135 | // animating towards back, hang onto old list for duration of animation. |
| 5136 | mAnimatingAppTokens.clear(); |
| 5137 | mAnimatingAppTokens.addAll(mAppTokens); |
| 5138 | } |
| 5139 | removeAppTokensLocked(tokens); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5140 | int pos = 0; |
| 5141 | for (int i=0; i<N; i++) { |
| 5142 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 5143 | if (wt != null) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5144 | if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 5145 | "Adding next to bottom: " + wt + " at " + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5146 | mAppTokens.add(pos, wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 5147 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 5148 | wt.sendingToBottom = true; |
| 5149 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5150 | pos++; |
| 5151 | } |
| 5152 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5153 | |
Craig Mautner | 06a94f7 | 2012-05-29 10:46:00 -0700 | [diff] [blame] | 5154 | if (!mAppTransitionRunning) { |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 5155 | mAnimatingAppTokens.clear(); |
| 5156 | mAnimatingAppTokens.addAll(mAppTokens); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 5157 | moveAppWindowsLocked(tokens, 0); |
| 5158 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5159 | } |
| 5160 | Binder.restoreCallingIdentity(origId); |
| 5161 | } |
| 5162 | |
| 5163 | // ------------------------------------------------------------- |
| 5164 | // Misc IWindowSession methods |
| 5165 | // ------------------------------------------------------------- |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5166 | |
Craig Mautner | 5642a48 | 2012-08-23 12:16:53 -0700 | [diff] [blame] | 5167 | @Override |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 5168 | public void startFreezingScreen(int exitAnim, int enterAnim) { |
| 5169 | if (!checkCallingPermission(android.Manifest.permission.FREEZE_SCREEN, |
| 5170 | "startFreezingScreen()")) { |
| 5171 | throw new SecurityException("Requires FREEZE_SCREEN permission"); |
| 5172 | } |
| 5173 | |
| 5174 | synchronized(mWindowMap) { |
| 5175 | if (!mClientFreezingScreen) { |
| 5176 | mClientFreezingScreen = true; |
| 5177 | final long origId = Binder.clearCallingIdentity(); |
| 5178 | try { |
| 5179 | startFreezingDisplayLocked(false, exitAnim, enterAnim); |
| 5180 | mH.removeMessages(H.CLIENT_FREEZE_TIMEOUT); |
| 5181 | mH.sendMessageDelayed(mH.obtainMessage(H.CLIENT_FREEZE_TIMEOUT), |
| 5182 | 5000); |
| 5183 | } finally { |
| 5184 | Binder.restoreCallingIdentity(origId); |
| 5185 | } |
| 5186 | } |
| 5187 | } |
| 5188 | } |
| 5189 | |
| 5190 | @Override |
| 5191 | public void stopFreezingScreen() { |
| 5192 | if (!checkCallingPermission(android.Manifest.permission.FREEZE_SCREEN, |
| 5193 | "stopFreezingScreen()")) { |
| 5194 | throw new SecurityException("Requires FREEZE_SCREEN permission"); |
| 5195 | } |
| 5196 | |
| 5197 | synchronized(mWindowMap) { |
| 5198 | if (mClientFreezingScreen) { |
| 5199 | mClientFreezingScreen = false; |
| 5200 | final long origId = Binder.clearCallingIdentity(); |
| 5201 | try { |
| 5202 | stopFreezingDisplayLocked(); |
| 5203 | } finally { |
| 5204 | Binder.restoreCallingIdentity(origId); |
| 5205 | } |
| 5206 | } |
| 5207 | } |
| 5208 | } |
| 5209 | |
| 5210 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5211 | public void disableKeyguard(IBinder token, String tag) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 5212 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5213 | != PackageManager.PERMISSION_GRANTED) { |
| 5214 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 5215 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 5216 | |
Craig Mautner | 5642a48 | 2012-08-23 12:16:53 -0700 | [diff] [blame] | 5217 | mKeyguardDisableHandler.sendMessage(mKeyguardDisableHandler.obtainMessage( |
| 5218 | KeyguardDisableHandler.KEYGUARD_DISABLE, new Pair<IBinder, String>(token, tag))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5219 | } |
| 5220 | |
Craig Mautner | 5642a48 | 2012-08-23 12:16:53 -0700 | [diff] [blame] | 5221 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5222 | public void reenableKeyguard(IBinder token) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 5223 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5224 | != PackageManager.PERMISSION_GRANTED) { |
| 5225 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 5226 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5227 | |
Craig Mautner | 5642a48 | 2012-08-23 12:16:53 -0700 | [diff] [blame] | 5228 | mKeyguardDisableHandler.sendMessage(mKeyguardDisableHandler.obtainMessage( |
| 5229 | KeyguardDisableHandler.KEYGUARD_REENABLE, token)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5230 | } |
| 5231 | |
| 5232 | /** |
| 5233 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 5234 | */ |
| 5235 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 5236 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5237 | != PackageManager.PERMISSION_GRANTED) { |
| 5238 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 5239 | } |
| 5240 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 5241 | public void onKeyguardExitResult(boolean success) { |
| 5242 | try { |
| 5243 | callback.onKeyguardExitResult(success); |
| 5244 | } catch (RemoteException e) { |
| 5245 | // Client has died, we don't care. |
| 5246 | } |
| 5247 | } |
| 5248 | }); |
| 5249 | } |
| 5250 | |
| 5251 | public boolean inKeyguardRestrictedInputMode() { |
| 5252 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 5253 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5254 | |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5255 | public boolean isKeyguardLocked() { |
| 5256 | return mPolicy.isKeyguardLocked(); |
| 5257 | } |
| 5258 | |
| 5259 | public boolean isKeyguardSecure() { |
| 5260 | return mPolicy.isKeyguardSecure(); |
| 5261 | } |
| 5262 | |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 5263 | public void dismissKeyguard() { |
| 5264 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| 5265 | != PackageManager.PERMISSION_GRANTED) { |
| 5266 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 5267 | } |
| 5268 | synchronized(mWindowMap) { |
| 5269 | mPolicy.dismissKeyguardLw(); |
| 5270 | } |
| 5271 | } |
| 5272 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 5273 | public void closeSystemDialogs(String reason) { |
| 5274 | synchronized(mWindowMap) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5275 | final AllWindowsIterator iterator = new AllWindowsIterator(); |
| 5276 | while (iterator.hasNext()) { |
| 5277 | final WindowState w = iterator.next(); |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 5278 | if (w.mHasSurface) { |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 5279 | try { |
| 5280 | w.mClient.closeSystemDialogs(reason); |
| 5281 | } catch (RemoteException e) { |
| 5282 | } |
| 5283 | } |
| 5284 | } |
| 5285 | } |
| 5286 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5287 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5288 | static float fixScale(float scale) { |
| 5289 | if (scale < 0) scale = 0; |
| 5290 | else if (scale > 20) scale = 20; |
| 5291 | return Math.abs(scale); |
| 5292 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5293 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5294 | public void setAnimationScale(int which, float scale) { |
| 5295 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 5296 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5297 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5298 | } |
| 5299 | |
| 5300 | if (scale < 0) scale = 0; |
| 5301 | else if (scale > 20) scale = 20; |
| 5302 | scale = Math.abs(scale); |
| 5303 | switch (which) { |
| 5304 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 5305 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
Chet Haase | c38fa1f | 2012-02-01 16:37:46 -0800 | [diff] [blame] | 5306 | case 2: mAnimatorDurationScale = fixScale(scale); break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5307 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5308 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5309 | // Persist setting |
| 5310 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 5311 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5312 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5313 | public void setAnimationScales(float[] scales) { |
| 5314 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 5315 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5316 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5317 | } |
| 5318 | |
| 5319 | if (scales != null) { |
| 5320 | if (scales.length >= 1) { |
| 5321 | mWindowAnimationScale = fixScale(scales[0]); |
| 5322 | } |
| 5323 | if (scales.length >= 2) { |
| 5324 | mTransitionAnimationScale = fixScale(scales[1]); |
| 5325 | } |
Chet Haase | c38fa1f | 2012-02-01 16:37:46 -0800 | [diff] [blame] | 5326 | if (scales.length >= 3) { |
Jeff Brown | ff7e6ef | 2012-08-15 02:05:18 -0700 | [diff] [blame] | 5327 | setAnimatorDurationScale(fixScale(scales[2])); |
Chet Haase | c38fa1f | 2012-02-01 16:37:46 -0800 | [diff] [blame] | 5328 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5329 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5330 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5331 | // Persist setting |
| 5332 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 5333 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5334 | |
Jeff Brown | ff7e6ef | 2012-08-15 02:05:18 -0700 | [diff] [blame] | 5335 | private void setAnimatorDurationScale(float scale) { |
| 5336 | mAnimatorDurationScale = scale; |
| 5337 | ValueAnimator.setDurationScale(scale); |
| 5338 | } |
| 5339 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5340 | public float getAnimationScale(int which) { |
| 5341 | switch (which) { |
| 5342 | case 0: return mWindowAnimationScale; |
| 5343 | case 1: return mTransitionAnimationScale; |
Chet Haase | c38fa1f | 2012-02-01 16:37:46 -0800 | [diff] [blame] | 5344 | case 2: return mAnimatorDurationScale; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5345 | } |
| 5346 | return 0; |
| 5347 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5348 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5349 | public float[] getAnimationScales() { |
Chet Haase | c38fa1f | 2012-02-01 16:37:46 -0800 | [diff] [blame] | 5350 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale, |
| 5351 | mAnimatorDurationScale }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5352 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5353 | |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 5354 | // Called by window manager policy. Not exposed externally. |
| 5355 | @Override |
| 5356 | public int getLidState() { |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5357 | int sw = mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, |
| 5358 | InputManagerService.SW_LID); |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 5359 | if (sw > 0) { |
Jeff Brown | 27fd342 | 2012-04-09 11:05:16 -0700 | [diff] [blame] | 5360 | // Switch state: AKEY_STATE_DOWN or AKEY_STATE_VIRTUAL. |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 5361 | return LID_CLOSED; |
Jeff Brown | 27fd342 | 2012-04-09 11:05:16 -0700 | [diff] [blame] | 5362 | } else if (sw == 0) { |
| 5363 | // Switch state: AKEY_STATE_UP. |
| 5364 | return LID_OPEN; |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 5365 | } else { |
Jeff Brown | 27fd342 | 2012-04-09 11:05:16 -0700 | [diff] [blame] | 5366 | // Switch state: AKEY_STATE_UNKNOWN. |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 5367 | return LID_ABSENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5368 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5369 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5370 | |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 5371 | // Called by window manager policy. Not exposed externally. |
| 5372 | @Override |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 5373 | public InputChannel monitorInput(String inputChannelName) { |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 5374 | return mInputManager.monitorInput(inputChannelName); |
| 5375 | } |
| 5376 | |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 5377 | // Called by window manager policy. Not exposed externally. |
| 5378 | @Override |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 5379 | public void switchKeyboardLayout(int deviceId, int direction) { |
| 5380 | mInputManager.switchKeyboardLayout(deviceId, direction); |
| 5381 | } |
| 5382 | |
| 5383 | // Called by window manager policy. Not exposed externally. |
| 5384 | @Override |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 5385 | public void shutdown(boolean confirm) { |
| 5386 | ShutdownThread.shutdown(mContext, confirm); |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 5387 | } |
| 5388 | |
| 5389 | // Called by window manager policy. Not exposed externally. |
| 5390 | @Override |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 5391 | public void rebootSafeMode(boolean confirm) { |
| 5392 | ShutdownThread.rebootSafeMode(mContext, confirm); |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 5393 | } |
| 5394 | |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 5395 | public void setInputFilter(IInputFilter filter) { |
| 5396 | if (!checkCallingPermission(android.Manifest.permission.FILTER_EVENTS, "setInputFilter()")) { |
| 5397 | throw new SecurityException("Requires FILTER_EVENTS permission"); |
| 5398 | } |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 5399 | mInputManager.setInputFilter(filter); |
| 5400 | } |
| 5401 | |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5402 | public void setCurrentUser(final int newUserId) { |
| 5403 | synchronized (mWindowMap) { |
| 5404 | mCurrentUserId = newUserId; |
| 5405 | mPolicy.setCurrentUserLw(newUserId); |
| 5406 | } |
| 5407 | } |
| 5408 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5409 | public void enableScreenAfterBoot() { |
| 5410 | synchronized(mWindowMap) { |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5411 | if (DEBUG_BOOT) { |
| 5412 | RuntimeException here = new RuntimeException("here"); |
| 5413 | here.fillInStackTrace(); |
| 5414 | Slog.i(TAG, "enableScreenAfterBoot: mDisplayEnabled=" + mDisplayEnabled |
| 5415 | + " mForceDisplayEnabled=" + mForceDisplayEnabled |
| 5416 | + " mShowingBootMessages=" + mShowingBootMessages |
| 5417 | + " mSystemBooted=" + mSystemBooted, here); |
| 5418 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5419 | if (mSystemBooted) { |
| 5420 | return; |
| 5421 | } |
| 5422 | mSystemBooted = true; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5423 | hideBootMessagesLocked(); |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5424 | // If the screen still doesn't come up after 30 seconds, give |
| 5425 | // up and turn it on. |
| 5426 | Message msg = mH.obtainMessage(H.BOOT_TIMEOUT); |
| 5427 | mH.sendMessageDelayed(msg, 30*1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5428 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5429 | |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5430 | mPolicy.systemBooted(); |
| 5431 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5432 | performEnableScreen(); |
| 5433 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5434 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5435 | void enableScreenIfNeededLocked() { |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5436 | if (DEBUG_BOOT) { |
| 5437 | RuntimeException here = new RuntimeException("here"); |
| 5438 | here.fillInStackTrace(); |
| 5439 | Slog.i(TAG, "enableScreenIfNeededLocked: mDisplayEnabled=" + mDisplayEnabled |
| 5440 | + " mForceDisplayEnabled=" + mForceDisplayEnabled |
| 5441 | + " mShowingBootMessages=" + mShowingBootMessages |
| 5442 | + " mSystemBooted=" + mSystemBooted, here); |
| 5443 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5444 | if (mDisplayEnabled) { |
| 5445 | return; |
| 5446 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5447 | if (!mSystemBooted && !mShowingBootMessages) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5448 | return; |
| 5449 | } |
| 5450 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 5451 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5452 | |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5453 | public void performBootTimeout() { |
| 5454 | synchronized(mWindowMap) { |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 5455 | if (mDisplayEnabled || mHeadless) { |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5456 | return; |
| 5457 | } |
| 5458 | Slog.w(TAG, "***** BOOT TIMEOUT: forcing display enabled"); |
| 5459 | mForceDisplayEnabled = true; |
| 5460 | } |
| 5461 | performEnableScreen(); |
| 5462 | } |
| 5463 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5464 | public void performEnableScreen() { |
| 5465 | synchronized(mWindowMap) { |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5466 | if (DEBUG_BOOT) { |
| 5467 | RuntimeException here = new RuntimeException("here"); |
| 5468 | here.fillInStackTrace(); |
| 5469 | Slog.i(TAG, "performEnableScreen: mDisplayEnabled=" + mDisplayEnabled |
| 5470 | + " mForceDisplayEnabled=" + mForceDisplayEnabled |
| 5471 | + " mShowingBootMessages=" + mShowingBootMessages |
Jeff Brown | 780c46f | 2012-06-24 12:15:38 -0700 | [diff] [blame] | 5472 | + " mSystemBooted=" + mSystemBooted |
| 5473 | + " mOnlyCore=" + mOnlyCore, here); |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5474 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5475 | if (mDisplayEnabled) { |
| 5476 | return; |
| 5477 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5478 | if (!mSystemBooted && !mShowingBootMessages) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5479 | return; |
| 5480 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5481 | |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5482 | if (!mForceDisplayEnabled) { |
| 5483 | // Don't enable the screen until all existing windows |
| 5484 | // have been drawn. |
| 5485 | boolean haveBootMsg = false; |
| 5486 | boolean haveApp = false; |
Justin Mattson | 4233f26 | 2012-04-09 18:23:16 -0700 | [diff] [blame] | 5487 | // if the wallpaper service is disabled on the device, we're never going to have |
| 5488 | // wallpaper, don't bother waiting for it |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5489 | boolean haveWallpaper = false; |
Justin Mattson | 4233f26 | 2012-04-09 18:23:16 -0700 | [diff] [blame] | 5490 | boolean wallpaperEnabled = mContext.getResources().getBoolean( |
Jeff Brown | 780c46f | 2012-06-24 12:15:38 -0700 | [diff] [blame] | 5491 | com.android.internal.R.bool.config_enableWallpaperService) |
| 5492 | && !mOnlyCore; |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5493 | boolean haveKeyguard = true; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5494 | // TODO(multidisplay): Expand to all displays? |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 5495 | final WindowList windows = getDefaultWindowListLocked(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5496 | final int N = windows.size(); |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5497 | for (int i=0; i<N; i++) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5498 | WindowState w = windows.get(i); |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 5499 | if (w.mAttrs.type == TYPE_KEYGUARD) { |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5500 | // Only if there is a keyguard attached to the window manager |
| 5501 | // will we consider ourselves as having a keyguard. If it |
| 5502 | // isn't attached, we don't know if it wants to be shown or |
| 5503 | // hidden. If it is attached, we will say we have a keyguard |
| 5504 | // if the window doesn't want to be visible, because in that |
| 5505 | // case it explicitly doesn't want to be shown so we should |
| 5506 | // not delay turning the screen on for it. |
| 5507 | boolean vis = w.mViewVisibility == View.VISIBLE |
| 5508 | && w.mPolicyVisibility; |
| 5509 | haveKeyguard = !vis; |
| 5510 | } |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5511 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
| 5512 | return; |
| 5513 | } |
| 5514 | if (w.isDrawnLw()) { |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 5515 | if (w.mAttrs.type == TYPE_BOOT_PROGRESS) { |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5516 | haveBootMsg = true; |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 5517 | } else if (w.mAttrs.type == TYPE_APPLICATION) { |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5518 | haveApp = true; |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 5519 | } else if (w.mAttrs.type == TYPE_WALLPAPER) { |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5520 | haveWallpaper = true; |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 5521 | } else if (w.mAttrs.type == TYPE_KEYGUARD) { |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5522 | haveKeyguard = true; |
| 5523 | } |
| 5524 | } |
| 5525 | } |
| 5526 | |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5527 | if (DEBUG_SCREEN_ON || DEBUG_BOOT) { |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5528 | Slog.i(TAG, "******** booted=" + mSystemBooted + " msg=" + mShowingBootMessages |
| 5529 | + " haveBoot=" + haveBootMsg + " haveApp=" + haveApp |
Justin Mattson | 4233f26 | 2012-04-09 18:23:16 -0700 | [diff] [blame] | 5530 | + " haveWall=" + haveWallpaper + " wallEnabled=" + wallpaperEnabled |
| 5531 | + " haveKeyguard=" + haveKeyguard); |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5532 | } |
| 5533 | |
| 5534 | // If we are turning on the screen to show the boot message, |
| 5535 | // don't do it until the boot message is actually displayed. |
| 5536 | if (!mSystemBooted && !haveBootMsg) { |
| 5537 | return; |
| 5538 | } |
| 5539 | |
| 5540 | // If we are turning on the screen after the boot is completed |
| 5541 | // normally, don't do so until we have the application and |
| 5542 | // wallpaper. |
Justin Mattson | 4233f26 | 2012-04-09 18:23:16 -0700 | [diff] [blame] | 5543 | if (mSystemBooted && ((!haveApp && !haveKeyguard) || |
| 5544 | (wallpaperEnabled && !haveWallpaper))) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5545 | return; |
| 5546 | } |
| 5547 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5548 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5549 | mDisplayEnabled = true; |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5550 | if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG, "******************** ENABLING SCREEN!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5551 | if (false) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5552 | StringWriter sw = new StringWriter(); |
| 5553 | PrintWriter pw = new PrintWriter(sw); |
| 5554 | this.dump(null, pw, null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5555 | Slog.i(TAG, sw.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5556 | } |
| 5557 | try { |
| 5558 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 5559 | if (surfaceFlinger != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5560 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5561 | Parcel data = Parcel.obtain(); |
| 5562 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
Jeff Brown | c042ee2 | 2012-05-08 13:03:42 -0700 | [diff] [blame] | 5563 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, // BOOT_FINISHED |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5564 | data, null, 0); |
| 5565 | data.recycle(); |
| 5566 | } |
| 5567 | } catch (RemoteException ex) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5568 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5569 | } |
Jeff Brown | 08a746a | 2012-06-24 12:14:49 -0700 | [diff] [blame] | 5570 | |
| 5571 | // Enable input dispatch. |
| 5572 | mInputMonitor.setEventDispatchingLw(mEventDispatchingEnabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5573 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5574 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5575 | mPolicy.enableScreenAfterBoot(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5576 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5577 | // Make sure the last requested orientation has been applied. |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5578 | updateRotationUnchecked(false, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5579 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5580 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5581 | public void showBootMessage(final CharSequence msg, final boolean always) { |
| 5582 | boolean first = false; |
| 5583 | synchronized(mWindowMap) { |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5584 | if (DEBUG_BOOT) { |
| 5585 | RuntimeException here = new RuntimeException("here"); |
| 5586 | here.fillInStackTrace(); |
| 5587 | Slog.i(TAG, "showBootMessage: msg=" + msg + " always=" + always |
| 5588 | + " mAllowBootMessages=" + mAllowBootMessages |
| 5589 | + " mShowingBootMessages=" + mShowingBootMessages |
| 5590 | + " mSystemBooted=" + mSystemBooted, here); |
| 5591 | } |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 5592 | if (!mAllowBootMessages) { |
| 5593 | return; |
| 5594 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5595 | if (!mShowingBootMessages) { |
| 5596 | if (!always) { |
| 5597 | return; |
| 5598 | } |
| 5599 | first = true; |
| 5600 | } |
| 5601 | if (mSystemBooted) { |
| 5602 | return; |
| 5603 | } |
| 5604 | mShowingBootMessages = true; |
| 5605 | mPolicy.showBootMessage(msg, always); |
| 5606 | } |
| 5607 | if (first) { |
| 5608 | performEnableScreen(); |
| 5609 | } |
| 5610 | } |
| 5611 | |
| 5612 | public void hideBootMessagesLocked() { |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 5613 | if (DEBUG_BOOT) { |
| 5614 | RuntimeException here = new RuntimeException("here"); |
| 5615 | here.fillInStackTrace(); |
| 5616 | Slog.i(TAG, "hideBootMessagesLocked: mDisplayEnabled=" + mDisplayEnabled |
| 5617 | + " mForceDisplayEnabled=" + mForceDisplayEnabled |
| 5618 | + " mShowingBootMessages=" + mShowingBootMessages |
| 5619 | + " mSystemBooted=" + mSystemBooted, here); |
| 5620 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5621 | if (mShowingBootMessages) { |
| 5622 | mShowingBootMessages = false; |
| 5623 | mPolicy.hideBootMessages(); |
| 5624 | } |
| 5625 | } |
| 5626 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5627 | public void setInTouchMode(boolean mode) { |
| 5628 | synchronized(mWindowMap) { |
| 5629 | mInTouchMode = mode; |
| 5630 | } |
| 5631 | } |
| 5632 | |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5633 | // TODO: more accounting of which pid(s) turned it on, keep count, |
| 5634 | // only allow disables from pids which have count on, etc. |
Craig Mautner | 0447a81 | 2012-05-22 16:01:31 -0700 | [diff] [blame] | 5635 | @Override |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5636 | public void showStrictModeViolation(boolean on) { |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5637 | if (mHeadless) return; |
Craig Mautner | 0447a81 | 2012-05-22 16:01:31 -0700 | [diff] [blame] | 5638 | mH.sendMessage(mH.obtainMessage(H.SHOW_STRICT_MODE_VIOLATION, on ? 1 : 0, 0)); |
| 5639 | } |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5640 | |
Craig Mautner | 0447a81 | 2012-05-22 16:01:31 -0700 | [diff] [blame] | 5641 | private void showStrictModeViolation(int arg) { |
| 5642 | final boolean on = arg != 0; |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5643 | int pid = Binder.getCallingPid(); |
| 5644 | synchronized(mWindowMap) { |
| 5645 | // Ignoring requests to enable the red border from clients |
| 5646 | // which aren't on screen. (e.g. Broadcast Receivers in |
| 5647 | // the background..) |
| 5648 | if (on) { |
| 5649 | boolean isVisible = false; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5650 | final AllWindowsIterator iterator = new AllWindowsIterator(); |
| 5651 | while (iterator.hasNext()) { |
| 5652 | final WindowState ws = iterator.next(); |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5653 | if (ws.mSession.mPid == pid && ws.isVisibleLw()) { |
| 5654 | isVisible = true; |
| 5655 | break; |
| 5656 | } |
| 5657 | } |
| 5658 | if (!isVisible) { |
| 5659 | return; |
| 5660 | } |
| 5661 | } |
| 5662 | |
Dianne Hackborn | 3699174 | 2011-10-11 21:35:26 -0700 | [diff] [blame] | 5663 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
| 5664 | ">>> OPEN TRANSACTION showStrictModeViolation"); |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5665 | Surface.openTransaction(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5666 | try { |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 5667 | // TODO(multi-display): support multiple displays |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5668 | if (mStrictModeFlash == null) { |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 5669 | mStrictModeFlash = new StrictModeFlash( |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 5670 | getDefaultDisplayContentLocked().getDisplay(), mFxSession); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5671 | } |
| 5672 | mStrictModeFlash.setVisibility(on); |
| 5673 | } finally { |
| 5674 | Surface.closeTransaction(); |
Dianne Hackborn | 3699174 | 2011-10-11 21:35:26 -0700 | [diff] [blame] | 5675 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
| 5676 | "<<< CLOSE TRANSACTION showStrictModeViolation"); |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5677 | } |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5678 | } |
| 5679 | } |
| 5680 | |
Brad Fitzpatrick | c1a968a | 2010-11-24 08:56:40 -0800 | [diff] [blame] | 5681 | public void setStrictModeVisualIndicatorPreference(String value) { |
| 5682 | SystemProperties.set(StrictMode.VISUAL_PROPERTY, value); |
| 5683 | } |
| 5684 | |
Jim Miller | e70d506 | 2011-03-08 21:38:39 -0800 | [diff] [blame] | 5685 | /** |
| 5686 | * Takes a snapshot of the screen. In landscape mode this grabs the whole screen. |
| 5687 | * In portrait mode, it grabs the upper region of the screen based on the vertical dimension |
| 5688 | * of the target image. |
| 5689 | * |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5690 | * @param displayId the Display to take a screenshot of. |
Jim Miller | e70d506 | 2011-03-08 21:38:39 -0800 | [diff] [blame] | 5691 | * @param width the width of the target bitmap |
| 5692 | * @param height the height of the target bitmap |
| 5693 | */ |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5694 | public Bitmap screenshotApplications(IBinder appToken, int displayId, int width, int height) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5695 | if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER, |
| 5696 | "screenshotApplications()")) { |
| 5697 | throw new SecurityException("Requires READ_FRAME_BUFFER permission"); |
| 5698 | } |
| 5699 | |
| 5700 | Bitmap rawss; |
| 5701 | |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5702 | int maxLayer = 0; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5703 | final Rect frame = new Rect(); |
| 5704 | |
| 5705 | float scale; |
Jim Miller | e70d506 | 2011-03-08 21:38:39 -0800 | [diff] [blame] | 5706 | int dw, dh; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5707 | int rot; |
| 5708 | |
| 5709 | synchronized(mWindowMap) { |
| 5710 | long ident = Binder.clearCallingIdentity(); |
| 5711 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 5712 | final DisplayContent displayContent = getDisplayContentLocked(displayId); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5713 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
| 5714 | dw = displayInfo.logicalWidth; |
| 5715 | dh = displayInfo.logicalHeight; |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 5716 | |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 5717 | int aboveAppLayer = mPolicy.windowTypeToLayerLw(TYPE_APPLICATION) |
| 5718 | * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5719 | aboveAppLayer += TYPE_LAYER_MULTIPLIER; |
| 5720 | |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 5721 | boolean isImeTarget = mInputMethodTarget != null |
| 5722 | && mInputMethodTarget.mAppToken != null |
| 5723 | && mInputMethodTarget.mAppToken.appToken != null |
| 5724 | && mInputMethodTarget.mAppToken.appToken.asBinder() == appToken; |
| 5725 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5726 | // Figure out the part of the screen that is actually the app. |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 5727 | boolean including = false; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5728 | final WindowList windows = displayContent.getWindowList(); |
| 5729 | for (int i = windows.size() - 1; i >= 0; i--) { |
| 5730 | WindowState ws = windows.get(i); |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 5731 | if (!ws.mHasSurface) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5732 | continue; |
| 5733 | } |
| 5734 | if (ws.mLayer >= aboveAppLayer) { |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5735 | continue; |
| 5736 | } |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 5737 | // When we will skip windows: when we are not including |
| 5738 | // ones behind a window we didn't skip, and we are actually |
| 5739 | // taking a screenshot of a specific app. |
| 5740 | if (!including && appToken != null) { |
| 5741 | // Also, we can possibly skip this window if it is not |
| 5742 | // an IME target or the application for the screenshot |
| 5743 | // is not the current IME target. |
| 5744 | if (!ws.mIsImWindow || !isImeTarget) { |
| 5745 | // And finally, this window is of no interest if it |
| 5746 | // is not associated with the screenshot app. |
| 5747 | if (ws.mAppToken == null || ws.mAppToken.token != appToken) { |
| 5748 | continue; |
| 5749 | } |
| 5750 | } |
| 5751 | } |
| 5752 | |
| 5753 | // We keep on including windows until we go past a full-screen |
| 5754 | // window. |
| 5755 | including = !ws.mIsImWindow && !ws.isFullscreen(dw, dh); |
| 5756 | |
Craig Mautner | 8816568 | 2012-05-31 14:25:31 -0700 | [diff] [blame] | 5757 | if (maxLayer < ws.mWinAnimator.mSurfaceLayer) { |
| 5758 | maxLayer = ws.mWinAnimator.mSurfaceLayer; |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5759 | } |
Jim Miller | 2aded18 | 2011-03-08 15:32:42 -0800 | [diff] [blame] | 5760 | |
| 5761 | // Don't include wallpaper in bounds calculation |
| 5762 | if (!ws.mIsWallpaper) { |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 5763 | final Rect wf = ws.mFrame; |
Jim Miller | 2aded18 | 2011-03-08 15:32:42 -0800 | [diff] [blame] | 5764 | final Rect cr = ws.mContentInsets; |
| 5765 | int left = wf.left + cr.left; |
| 5766 | int top = wf.top + cr.top; |
| 5767 | int right = wf.right - cr.right; |
| 5768 | int bottom = wf.bottom - cr.bottom; |
| 5769 | frame.union(left, top, right, bottom); |
| 5770 | } |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5771 | } |
| 5772 | Binder.restoreCallingIdentity(ident); |
| 5773 | |
Dianne Hackborn | dd962ee | 2011-02-02 11:11:50 -0800 | [diff] [blame] | 5774 | // Constrain frame to the screen size. |
| 5775 | frame.intersect(0, 0, dw, dh); |
Jim Miller | e70d506 | 2011-03-08 21:38:39 -0800 | [diff] [blame] | 5776 | |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5777 | if (frame.isEmpty() || maxLayer == 0) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5778 | return null; |
| 5779 | } |
| 5780 | |
| 5781 | // The screenshot API does not apply the current screen rotation. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 5782 | rot = getDefaultDisplayContentLocked().getDisplay().getRotation(); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5783 | int fw = frame.width(); |
| 5784 | int fh = frame.height(); |
| 5785 | |
Jim Miller | 28637ba | 2011-07-06 19:57:05 -0700 | [diff] [blame] | 5786 | // Constrain thumbnail to smaller of screen width or height. Assumes aspect |
| 5787 | // of thumbnail is the same as the screen (in landscape) or square. |
Michael Jurka | bfd24ac | 2011-11-13 13:50:38 -0800 | [diff] [blame] | 5788 | float targetWidthScale = width / (float) fw; |
| 5789 | float targetHeightScale = height / (float) fh; |
Jim Miller | 28637ba | 2011-07-06 19:57:05 -0700 | [diff] [blame] | 5790 | if (dw <= dh) { |
Michael Jurka | bfd24ac | 2011-11-13 13:50:38 -0800 | [diff] [blame] | 5791 | scale = targetWidthScale; |
| 5792 | // If aspect of thumbnail is the same as the screen (in landscape), |
| 5793 | // select the slightly larger value so we fill the entire bitmap |
| 5794 | if (targetHeightScale > scale && (int) (targetHeightScale * fw) == width) { |
| 5795 | scale = targetHeightScale; |
| 5796 | } |
Jim Miller | 28637ba | 2011-07-06 19:57:05 -0700 | [diff] [blame] | 5797 | } else { |
Michael Jurka | bfd24ac | 2011-11-13 13:50:38 -0800 | [diff] [blame] | 5798 | scale = targetHeightScale; |
| 5799 | // If aspect of thumbnail is the same as the screen (in landscape), |
| 5800 | // select the slightly larger value so we fill the entire bitmap |
| 5801 | if (targetWidthScale > scale && (int) (targetWidthScale * fh) == height) { |
| 5802 | scale = targetWidthScale; |
| 5803 | } |
Jim Miller | 28637ba | 2011-07-06 19:57:05 -0700 | [diff] [blame] | 5804 | } |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5805 | |
| 5806 | // The screen shot will contain the entire screen. |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 5807 | dw = (int)(dw*scale); |
| 5808 | dh = (int)(dh*scale); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5809 | if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) { |
| 5810 | int tmp = dw; |
| 5811 | dw = dh; |
| 5812 | dh = tmp; |
| 5813 | rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90; |
| 5814 | } |
Dianne Hackborn | cfb9f2b | 2011-08-24 10:51:49 -0700 | [diff] [blame] | 5815 | if (DEBUG_SCREENSHOT) { |
| 5816 | Slog.i(TAG, "Screenshot: " + dw + "x" + dh + " from 0 to " + maxLayer); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5817 | for (int i = 0; i < windows.size(); i++) { |
| 5818 | WindowState win = windows.get(i); |
| 5819 | Slog.i(TAG, win + ": " + win.mLayer |
| 5820 | + " animLayer=" + win.mWinAnimator.mAnimLayer |
| 5821 | + " surfaceLayer=" + win.mWinAnimator.mSurfaceLayer); |
Dianne Hackborn | cfb9f2b | 2011-08-24 10:51:49 -0700 | [diff] [blame] | 5822 | } |
| 5823 | } |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5824 | rawss = Surface.screenshot(dw, dh, 0, maxLayer); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5825 | } |
| 5826 | |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5827 | if (rawss == null) { |
Dianne Hackborn | 3ec891a | 2011-10-25 13:58:30 -0700 | [diff] [blame] | 5828 | Slog.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh |
Dianne Hackborn | 88b03bd | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5829 | + ") to layer " + maxLayer); |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5830 | return null; |
| 5831 | } |
Jim Miller | e70d506 | 2011-03-08 21:38:39 -0800 | [diff] [blame] | 5832 | |
| 5833 | Bitmap bm = Bitmap.createBitmap(width, height, rawss.getConfig()); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5834 | Matrix matrix = new Matrix(); |
| 5835 | ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix); |
Michael Jurka | 4accb6a | 2012-03-26 09:18:46 -0700 | [diff] [blame] | 5836 | matrix.postTranslate(-FloatMath.ceil(frame.left*scale), -FloatMath.ceil(frame.top*scale)); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5837 | Canvas canvas = new Canvas(bm); |
| 5838 | canvas.drawBitmap(rawss, matrix, null); |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 5839 | canvas.setBitmap(null); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5840 | |
| 5841 | rawss.recycle(); |
| 5842 | return bm; |
| 5843 | } |
| 5844 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5845 | /** |
| 5846 | * Freeze rotation changes. (Enable "rotation lock".) |
| 5847 | * Persists across reboots. |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 5848 | * @param rotation The desired rotation to freeze to, or -1 to use the |
| 5849 | * current rotation. |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5850 | */ |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 5851 | public void freezeRotation(int rotation) { |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5852 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5853 | "freezeRotation()")) { |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5854 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 5855 | } |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 5856 | if (rotation < -1 || rotation > Surface.ROTATION_270) { |
| 5857 | throw new IllegalArgumentException("Rotation argument must be -1 or a valid " |
| 5858 | + "rotation constant."); |
| 5859 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5860 | |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5861 | if (DEBUG_ORIENTATION) Slog.v(TAG, "freezeRotation: mRotation=" + mRotation); |
| 5862 | |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 5863 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, |
| 5864 | rotation == -1 ? mRotation : rotation); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5865 | updateRotationUnchecked(false, false); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5866 | } |
| 5867 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5868 | /** |
| 5869 | * Thaw rotation changes. (Disable "rotation lock".) |
| 5870 | * Persists across reboots. |
| 5871 | */ |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5872 | public void thawRotation() { |
| 5873 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5874 | "thawRotation()")) { |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5875 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 5876 | } |
| 5877 | |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5878 | if (DEBUG_ORIENTATION) Slog.v(TAG, "thawRotation: mRotation=" + mRotation); |
| 5879 | |
| 5880 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 777); // rot not used |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5881 | updateRotationUnchecked(false, false); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5882 | } |
| 5883 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5884 | /** |
| 5885 | * Recalculate the current rotation. |
| 5886 | * |
| 5887 | * Called by the window manager policy whenever the state of the system changes |
| 5888 | * such that the current rotation might need to be updated, such as when the |
| 5889 | * device is docked or rotated into a new posture. |
| 5890 | */ |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5891 | public void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) { |
| 5892 | updateRotationUnchecked(alwaysSendConfiguration, forceRelayout); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5893 | } |
| 5894 | |
| 5895 | /** |
| 5896 | * Temporarily pauses rotation changes until resumed. |
| 5897 | * |
| 5898 | * This can be used to prevent rotation changes from occurring while the user is |
| 5899 | * performing certain operations, such as drag and drop. |
| 5900 | * |
| 5901 | * This call nests and must be matched by an equal number of calls to {@link #resumeRotation}. |
| 5902 | */ |
| 5903 | void pauseRotationLocked() { |
| 5904 | mDeferredRotationPauseCount += 1; |
| 5905 | } |
| 5906 | |
| 5907 | /** |
| 5908 | * Resumes normal rotation changes after being paused. |
| 5909 | */ |
| 5910 | void resumeRotationLocked() { |
| 5911 | if (mDeferredRotationPauseCount > 0) { |
| 5912 | mDeferredRotationPauseCount -= 1; |
| 5913 | if (mDeferredRotationPauseCount == 0) { |
| 5914 | boolean changed = updateRotationUncheckedLocked(false); |
| 5915 | if (changed) { |
| 5916 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 5917 | } |
| 5918 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5919 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5920 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5921 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5922 | public void updateRotationUnchecked(boolean alwaysSendConfiguration, boolean forceRelayout) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5923 | if(DEBUG_ORIENTATION) Slog.v(TAG, "updateRotationUnchecked(" |
| 5924 | + "alwaysSendConfiguration=" + alwaysSendConfiguration + ")"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5925 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5926 | long origId = Binder.clearCallingIdentity(); |
| 5927 | boolean changed; |
| 5928 | synchronized(mWindowMap) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5929 | changed = updateRotationUncheckedLocked(false); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5930 | if (!changed || forceRelayout) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 5931 | getDefaultDisplayContentLocked().layoutNeeded = true; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5932 | performLayoutAndPlaceSurfacesLocked(); |
| 5933 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5934 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5935 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5936 | if (changed || alwaysSendConfiguration) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5937 | sendNewConfiguration(); |
| 5938 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5939 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5940 | Binder.restoreCallingIdentity(origId); |
| 5941 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5942 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 5943 | // TODO(multidisplay): Rotate any display? |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5944 | /** |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5945 | * Updates the current rotation. |
| 5946 | * |
| 5947 | * Returns true if the rotation has been changed. In this case YOU |
| 5948 | * MUST CALL sendNewConfiguration() TO UNFREEZE THE SCREEN. |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5949 | */ |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5950 | public boolean updateRotationUncheckedLocked(boolean inTransaction) { |
| 5951 | if (mDeferredRotationPauseCount > 0) { |
| 5952 | // Rotation updates have been paused temporarily. Defer the update until |
| 5953 | // updates have been resumed. |
| 5954 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation, rotation is paused."); |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 5955 | return false; |
| 5956 | } |
| 5957 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 5958 | ScreenRotationAnimation screenRotationAnimation = |
| 5959 | mAnimator.getScreenRotationAnimationLocked(Display.DEFAULT_DISPLAY); |
| 5960 | if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5961 | // Rotation updates cannot be performed while the previous rotation change |
| 5962 | // animation is still in progress. Skip this update. We will try updating |
| 5963 | // again after the animation is finished and the display is unfrozen. |
| 5964 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation, animation in progress."); |
| 5965 | return false; |
| 5966 | } |
| 5967 | |
| 5968 | if (!mDisplayEnabled) { |
| 5969 | // No point choosing a rotation if the display is not enabled. |
| 5970 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation, display is not enabled."); |
| 5971 | return false; |
| 5972 | } |
| 5973 | |
| 5974 | // TODO: Implement forced rotation changes. |
| 5975 | // Set mAltOrientation to indicate that the application is receiving |
| 5976 | // an orientation that has different metrics than it expected. |
| 5977 | // eg. Portrait instead of Landscape. |
| 5978 | |
| 5979 | int rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, mRotation); |
| 5980 | boolean altOrientation = !mPolicy.rotationHasCompatibleMetricsLw( |
| 5981 | mForcedAppOrientation, rotation); |
| 5982 | |
| 5983 | if (DEBUG_ORIENTATION) { |
| 5984 | Slog.v(TAG, "Application requested orientation " |
| 5985 | + mForcedAppOrientation + ", got rotation " + rotation |
| 5986 | + " which has " + (altOrientation ? "incompatible" : "compatible") |
| 5987 | + " metrics"); |
| 5988 | } |
| 5989 | |
| 5990 | if (mRotation == rotation && mAltOrientation == altOrientation) { |
| 5991 | // No change. |
| 5992 | return false; |
| 5993 | } |
| 5994 | |
| 5995 | if (DEBUG_ORIENTATION) { |
| 5996 | Slog.v(TAG, |
| 5997 | "Rotation changed to " + rotation + (altOrientation ? " (alt)" : "") |
| 5998 | + " from " + mRotation + (mAltOrientation ? " (alt)" : "") |
| 5999 | + ", forceApp=" + mForcedAppOrientation); |
| 6000 | } |
| 6001 | |
| 6002 | mRotation = rotation; |
| 6003 | mAltOrientation = altOrientation; |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6004 | mPolicy.setRotationLw(mRotation); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6005 | |
| 6006 | mWindowsFreezingScreen = true; |
| 6007 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 6008 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 6009 | mWaitingForConfig = true; |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 6010 | getDefaultDisplayContentLocked().layoutNeeded = true; |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 6011 | startFreezingDisplayLocked(inTransaction, 0, 0); |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 6012 | // startFreezingDisplayLocked can reset the ScreenRotationAnimation. |
| 6013 | screenRotationAnimation = |
| 6014 | mAnimator.getScreenRotationAnimationLocked(Display.DEFAULT_DISPLAY); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6015 | |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6016 | // We need to update our screen size information to match the new |
| 6017 | // rotation. Note that this is redundant with the later call to |
| 6018 | // sendNewConfiguration() that must be called after this function |
| 6019 | // returns... however we need to do the screen size part of that |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 6020 | // before then so we have the correct size to use when initializing |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6021 | // the rotation animation for the new rotation. |
| 6022 | computeScreenConfigurationLocked(null); |
| 6023 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 6024 | final DisplayContent displayContent = getDefaultDisplayContentLocked(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6025 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 6026 | if (!inTransaction) { |
| 6027 | if (SHOW_TRANSACTIONS) { |
| 6028 | Slog.i(TAG, ">>> OPEN TRANSACTION setRotationUnchecked"); |
| 6029 | } |
| 6030 | Surface.openTransaction(); |
| 6031 | } |
Jamie Gennis | e2909e1 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 6032 | try { |
| 6033 | // NOTE: We disable the rotation in the emulator because |
| 6034 | // it doesn't support hardware OpenGL emulation yet. |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 6035 | if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null |
| 6036 | && screenRotationAnimation.hasScreenshot()) { |
| 6037 | if (screenRotationAnimation.setRotationInTransaction( |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 6038 | rotation, mFxSession, |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6039 | MAX_ANIMATION_DURATION, mTransitionAnimationScale, |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6040 | displayInfo.logicalWidth, displayInfo.logicalHeight)) { |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 6041 | updateLayoutToAnimationLocked(); |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6042 | } |
Jamie Gennis | e2909e1 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 6043 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 6044 | |
| 6045 | mDisplayManagerService.performTraversalInTransactionFromWindowManager(); |
Jamie Gennis | e2909e1 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 6046 | } finally { |
| 6047 | if (!inTransaction) { |
| 6048 | Surface.closeTransaction(); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 6049 | if (SHOW_LIGHT_TRANSACTIONS) { |
| 6050 | Slog.i(TAG, "<<< CLOSE TRANSACTION setRotationUnchecked"); |
| 6051 | } |
Jamie Gennis | e2909e1 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 6052 | } |
| 6053 | } |
| 6054 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6055 | final WindowList windows = displayContent.getWindowList(); |
| 6056 | for (int i = windows.size() - 1; i >= 0; i--) { |
| 6057 | WindowState w = windows.get(i); |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 6058 | if (w.mHasSurface) { |
Dianne Hackborn | 3ec891a | 2011-10-25 13:58:30 -0700 | [diff] [blame] | 6059 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Set mOrientationChanging of " + w); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6060 | w.mOrientationChanging = true; |
Craig Mautner | 3255a28 | 2012-04-16 15:42:47 -0700 | [diff] [blame] | 6061 | mInnerFields.mOrientationChangeComplete = false; |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 6062 | } |
| 6063 | } |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 6064 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6065 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 6066 | try { |
| 6067 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 6068 | } catch (RemoteException e) { |
| 6069 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 6070 | } |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 6071 | |
| 6072 | scheduleNotifyRotationChangedIfNeededLocked(displayContent, rotation); |
| 6073 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6074 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6075 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6076 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6077 | public int getRotation() { |
| 6078 | return mRotation; |
| 6079 | } |
| 6080 | |
| 6081 | public int watchRotation(IRotationWatcher watcher) { |
| 6082 | final IBinder watcherBinder = watcher.asBinder(); |
| 6083 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 6084 | public void binderDied() { |
| 6085 | synchronized (mWindowMap) { |
| 6086 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 6087 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 6088 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 6089 | if (removed != null) { |
| 6090 | removed.asBinder().unlinkToDeath(this, 0); |
| 6091 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6092 | i--; |
| 6093 | } |
| 6094 | } |
| 6095 | } |
| 6096 | } |
| 6097 | }; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6098 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6099 | synchronized (mWindowMap) { |
| 6100 | try { |
| 6101 | watcher.asBinder().linkToDeath(dr, 0); |
| 6102 | mRotationWatchers.add(watcher); |
| 6103 | } catch (RemoteException e) { |
| 6104 | // Client died, no cleanup needed. |
| 6105 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6106 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6107 | return mRotation; |
| 6108 | } |
| 6109 | } |
| 6110 | |
| 6111 | /** |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 6112 | * Apps that use the compact menu panel (as controlled by the panelMenuIsCompact |
| 6113 | * theme attribute) on devices that feature a physical options menu key attempt to position |
| 6114 | * their menu panel window along the edge of the screen nearest the physical menu key. |
| 6115 | * This lowers the travel distance between invoking the menu panel and selecting |
| 6116 | * a menu option. |
| 6117 | * |
| 6118 | * This method helps control where that menu is placed. Its current implementation makes |
| 6119 | * assumptions about the menu key and its relationship to the screen based on whether |
| 6120 | * the device's natural orientation is portrait (width < height) or landscape. |
| 6121 | * |
| 6122 | * The menu key is assumed to be located along the bottom edge of natural-portrait |
| 6123 | * devices and along the right edge of natural-landscape devices. If these assumptions |
| 6124 | * do not hold for the target device, this method should be changed to reflect that. |
| 6125 | * |
| 6126 | * @return A {@link Gravity} value for placing the options menu window |
| 6127 | */ |
| 6128 | public int getPreferredOptionsPanelGravity() { |
| 6129 | synchronized (mWindowMap) { |
| 6130 | final int rotation = getRotation(); |
| 6131 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6132 | // TODO(multidisplay): Assume that such devices physical keys are on the main screen. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 6133 | final DisplayContent displayContent = getDefaultDisplayContentLocked(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6134 | if (displayContent.mInitialDisplayWidth < displayContent.mInitialDisplayHeight) { |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 6135 | // On devices with a natural orientation of portrait |
| 6136 | switch (rotation) { |
| 6137 | default: |
| 6138 | case Surface.ROTATION_0: |
| 6139 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 6140 | case Surface.ROTATION_90: |
Adam Powell | 67ed6c7 | 2011-08-28 13:21:56 -0700 | [diff] [blame] | 6141 | return Gravity.RIGHT | Gravity.BOTTOM; |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 6142 | case Surface.ROTATION_180: |
Adam Powell | 67ed6c7 | 2011-08-28 13:21:56 -0700 | [diff] [blame] | 6143 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 6144 | case Surface.ROTATION_270: |
Fabrice Di Meglio | aac0d4e | 2012-07-19 19:21:26 -0700 | [diff] [blame] | 6145 | return Gravity.START | Gravity.BOTTOM; |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 6146 | } |
| 6147 | } else { |
| 6148 | // On devices with a natural orientation of landscape |
| 6149 | switch (rotation) { |
| 6150 | default: |
| 6151 | case Surface.ROTATION_0: |
Adam Powell | 67ed6c7 | 2011-08-28 13:21:56 -0700 | [diff] [blame] | 6152 | return Gravity.RIGHT | Gravity.BOTTOM; |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 6153 | case Surface.ROTATION_90: |
| 6154 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 6155 | case Surface.ROTATION_180: |
Fabrice Di Meglio | aac0d4e | 2012-07-19 19:21:26 -0700 | [diff] [blame] | 6156 | return Gravity.START | Gravity.BOTTOM; |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 6157 | case Surface.ROTATION_270: |
Adam Powell | 67ed6c7 | 2011-08-28 13:21:56 -0700 | [diff] [blame] | 6158 | return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 6159 | } |
| 6160 | } |
| 6161 | } |
| 6162 | } |
| 6163 | |
| 6164 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6165 | * Starts the view server on the specified port. |
| 6166 | * |
| 6167 | * @param port The port to listener to. |
| 6168 | * |
| 6169 | * @return True if the server was successfully started, false otherwise. |
| 6170 | * |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 6171 | * @see com.android.server.wm.ViewServer |
| 6172 | * @see com.android.server.wm.ViewServer#VIEW_SERVER_DEFAULT_PORT |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6173 | */ |
| 6174 | public boolean startViewServer(int port) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6175 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6176 | return false; |
| 6177 | } |
| 6178 | |
| 6179 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 6180 | return false; |
| 6181 | } |
| 6182 | |
| 6183 | if (port < 1024) { |
| 6184 | return false; |
| 6185 | } |
| 6186 | |
| 6187 | if (mViewServer != null) { |
| 6188 | if (!mViewServer.isRunning()) { |
| 6189 | try { |
| 6190 | return mViewServer.start(); |
| 6191 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6192 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6193 | } |
| 6194 | } |
| 6195 | return false; |
| 6196 | } |
| 6197 | |
| 6198 | try { |
| 6199 | mViewServer = new ViewServer(this, port); |
| 6200 | return mViewServer.start(); |
| 6201 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6202 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6203 | } |
| 6204 | return false; |
| 6205 | } |
| 6206 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6207 | private boolean isSystemSecure() { |
| 6208 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 6209 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 6210 | } |
| 6211 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6212 | /** |
| 6213 | * Stops the view server if it exists. |
| 6214 | * |
| 6215 | * @return True if the server stopped, false if it wasn't started or |
| 6216 | * couldn't be stopped. |
| 6217 | * |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 6218 | * @see com.android.server.wm.ViewServer |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6219 | */ |
| 6220 | public boolean stopViewServer() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6221 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6222 | return false; |
| 6223 | } |
| 6224 | |
| 6225 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 6226 | return false; |
| 6227 | } |
| 6228 | |
| 6229 | if (mViewServer != null) { |
| 6230 | return mViewServer.stop(); |
| 6231 | } |
| 6232 | return false; |
| 6233 | } |
| 6234 | |
| 6235 | /** |
| 6236 | * Indicates whether the view server is running. |
| 6237 | * |
| 6238 | * @return True if the server is running, false otherwise. |
| 6239 | * |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 6240 | * @see com.android.server.wm.ViewServer |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6241 | */ |
| 6242 | public boolean isViewServerRunning() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6243 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6244 | return false; |
| 6245 | } |
| 6246 | |
| 6247 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 6248 | return false; |
| 6249 | } |
| 6250 | |
| 6251 | return mViewServer != null && mViewServer.isRunning(); |
| 6252 | } |
| 6253 | |
| 6254 | /** |
| 6255 | * Lists all availble windows in the system. The listing is written in the |
| 6256 | * specified Socket's output stream with the following syntax: |
| 6257 | * windowHashCodeInHexadecimal windowName |
| 6258 | * Each line of the ouput represents a different window. |
| 6259 | * |
| 6260 | * @param client The remote client to send the listing to. |
| 6261 | * @return False if an error occured, true otherwise. |
| 6262 | */ |
| 6263 | boolean viewServerListWindows(Socket client) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6264 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6265 | return false; |
| 6266 | } |
| 6267 | |
| 6268 | boolean result = true; |
| 6269 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6270 | WindowList windows = new WindowList(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6271 | synchronized (mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6272 | //noinspection unchecked |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6273 | DisplayContentsIterator iterator = new DisplayContentsIterator(); |
| 6274 | while(iterator.hasNext()) { |
| 6275 | windows.addAll(iterator.next().getWindowList()); |
| 6276 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6277 | } |
| 6278 | |
| 6279 | BufferedWriter out = null; |
| 6280 | |
| 6281 | // Any uncaught exception will crash the system process |
| 6282 | try { |
| 6283 | OutputStream clientStream = client.getOutputStream(); |
| 6284 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 6285 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6286 | final int count = windows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6287 | for (int i = 0; i < count; i++) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6288 | final WindowState w = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6289 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 6290 | out.write(' '); |
| 6291 | out.append(w.mAttrs.getTitle()); |
| 6292 | out.write('\n'); |
| 6293 | } |
| 6294 | |
| 6295 | out.write("DONE.\n"); |
| 6296 | out.flush(); |
| 6297 | } catch (Exception e) { |
| 6298 | result = false; |
| 6299 | } finally { |
| 6300 | if (out != null) { |
| 6301 | try { |
| 6302 | out.close(); |
| 6303 | } catch (IOException e) { |
| 6304 | result = false; |
| 6305 | } |
| 6306 | } |
| 6307 | } |
| 6308 | |
| 6309 | return result; |
| 6310 | } |
| 6311 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6312 | // TODO(multidisplay): Extend to multiple displays. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6313 | /** |
Konstantin Lopyrev | f962476 | 2010-07-14 17:02:37 -0700 | [diff] [blame] | 6314 | * Returns the focused window in the following format: |
| 6315 | * windowHashCodeInHexadecimal windowName |
| 6316 | * |
| 6317 | * @param client The remote client to send the listing to. |
| 6318 | * @return False if an error occurred, true otherwise. |
| 6319 | */ |
| 6320 | boolean viewServerGetFocusedWindow(Socket client) { |
| 6321 | if (isSystemSecure()) { |
| 6322 | return false; |
| 6323 | } |
| 6324 | |
| 6325 | boolean result = true; |
| 6326 | |
| 6327 | WindowState focusedWindow = getFocusedWindow(); |
| 6328 | |
| 6329 | BufferedWriter out = null; |
| 6330 | |
| 6331 | // Any uncaught exception will crash the system process |
| 6332 | try { |
| 6333 | OutputStream clientStream = client.getOutputStream(); |
| 6334 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 6335 | |
| 6336 | if(focusedWindow != null) { |
| 6337 | out.write(Integer.toHexString(System.identityHashCode(focusedWindow))); |
| 6338 | out.write(' '); |
| 6339 | out.append(focusedWindow.mAttrs.getTitle()); |
| 6340 | } |
| 6341 | out.write('\n'); |
| 6342 | out.flush(); |
| 6343 | } catch (Exception e) { |
| 6344 | result = false; |
| 6345 | } finally { |
| 6346 | if (out != null) { |
| 6347 | try { |
| 6348 | out.close(); |
| 6349 | } catch (IOException e) { |
| 6350 | result = false; |
| 6351 | } |
| 6352 | } |
| 6353 | } |
| 6354 | |
| 6355 | return result; |
| 6356 | } |
| 6357 | |
| 6358 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6359 | * Sends a command to a target window. The result of the command, if any, will be |
| 6360 | * written in the output stream of the specified socket. |
| 6361 | * |
| 6362 | * The parameters must follow this syntax: |
| 6363 | * windowHashcode extra |
| 6364 | * |
| 6365 | * Where XX is the length in characeters of the windowTitle. |
| 6366 | * |
| 6367 | * The first parameter is the target window. The window with the specified hashcode |
| 6368 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 6369 | * will be delivered to the target window and as parameters to the command itself. |
| 6370 | * |
| 6371 | * @param client The remote client to sent the result, if any, to. |
| 6372 | * @param command The command to execute. |
| 6373 | * @param parameters The command parameters. |
| 6374 | * |
| 6375 | * @return True if the command was successfully delivered, false otherwise. This does |
| 6376 | * not indicate whether the command itself was successful. |
| 6377 | */ |
| 6378 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6379 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6380 | return false; |
| 6381 | } |
| 6382 | |
| 6383 | boolean success = true; |
| 6384 | Parcel data = null; |
| 6385 | Parcel reply = null; |
| 6386 | |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 6387 | BufferedWriter out = null; |
| 6388 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6389 | // Any uncaught exception will crash the system process |
| 6390 | try { |
| 6391 | // Find the hashcode of the window |
| 6392 | int index = parameters.indexOf(' '); |
| 6393 | if (index == -1) { |
| 6394 | index = parameters.length(); |
| 6395 | } |
| 6396 | final String code = parameters.substring(0, index); |
Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 6397 | int hashCode = (int) Long.parseLong(code, 16); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6398 | |
| 6399 | // Extract the command's parameter after the window description |
| 6400 | if (index < parameters.length()) { |
| 6401 | parameters = parameters.substring(index + 1); |
| 6402 | } else { |
| 6403 | parameters = ""; |
| 6404 | } |
| 6405 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 6406 | final WindowState window = findWindow(hashCode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6407 | if (window == null) { |
| 6408 | return false; |
| 6409 | } |
| 6410 | |
| 6411 | data = Parcel.obtain(); |
| 6412 | data.writeInterfaceToken("android.view.IWindow"); |
| 6413 | data.writeString(command); |
| 6414 | data.writeString(parameters); |
| 6415 | data.writeInt(1); |
| 6416 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 6417 | |
| 6418 | reply = Parcel.obtain(); |
| 6419 | |
| 6420 | final IBinder binder = window.mClient.asBinder(); |
| 6421 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 6422 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 6423 | |
| 6424 | reply.readException(); |
| 6425 | |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 6426 | if (!client.isOutputShutdown()) { |
| 6427 | out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream())); |
| 6428 | out.write("DONE\n"); |
| 6429 | out.flush(); |
| 6430 | } |
| 6431 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6432 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6433 | 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] | 6434 | success = false; |
| 6435 | } finally { |
| 6436 | if (data != null) { |
| 6437 | data.recycle(); |
| 6438 | } |
| 6439 | if (reply != null) { |
| 6440 | reply.recycle(); |
| 6441 | } |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 6442 | if (out != null) { |
| 6443 | try { |
| 6444 | out.close(); |
| 6445 | } catch (IOException e) { |
| 6446 | |
| 6447 | } |
| 6448 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6449 | } |
| 6450 | |
| 6451 | return success; |
| 6452 | } |
| 6453 | |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 6454 | public void addDisplayContentChangeListener(int displayId, |
| 6455 | IDisplayContentChangeListener listener) { |
| 6456 | if (!checkCallingPermission(android.Manifest.permission.RETRIEVE_WINDOW_INFO, |
| 6457 | "addDisplayContentChangeListener()")) { |
| 6458 | throw new SecurityException("Requires RETRIEVE_WINDOW_INFO permission"); |
| 6459 | } |
| 6460 | synchronized(mWindowMap) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 6461 | DisplayContent displayContent = getDisplayContentLocked(displayId); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 6462 | if (displayContent.mDisplayContentChangeListeners == null) { |
| 6463 | displayContent.mDisplayContentChangeListeners = |
| 6464 | new RemoteCallbackList<IDisplayContentChangeListener>(); |
| 6465 | displayContent.mDisplayContentChangeListeners.register(listener); |
| 6466 | } |
| 6467 | } |
| 6468 | } |
| 6469 | |
| 6470 | public void removeDisplayContentChangeListener(int displayId, |
| 6471 | IDisplayContentChangeListener listener) { |
| 6472 | if (!checkCallingPermission(android.Manifest.permission.RETRIEVE_WINDOW_INFO, |
| 6473 | "removeDisplayContentChangeListener()")) { |
| 6474 | throw new SecurityException("Requires RETRIEVE_WINDOW_INFO permission"); |
| 6475 | } |
| 6476 | synchronized(mWindowMap) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 6477 | DisplayContent displayContent = getDisplayContentLocked(displayId); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 6478 | if (displayContent.mDisplayContentChangeListeners != null) { |
| 6479 | displayContent.mDisplayContentChangeListeners.unregister(listener); |
| 6480 | if (displayContent.mDisplayContentChangeListeners |
| 6481 | .getRegisteredCallbackCount() == 0) { |
| 6482 | displayContent.mDisplayContentChangeListeners = null; |
| 6483 | } |
| 6484 | } |
| 6485 | } |
| 6486 | } |
| 6487 | |
| 6488 | void scheduleNotifyWindowTranstionIfNeededLocked(WindowState window, int transition) { |
| 6489 | DisplayContent displayContent = window.mDisplayContent; |
| 6490 | if (displayContent.mDisplayContentChangeListeners != null) { |
| 6491 | WindowInfo info = getWindowInfoForWindowStateLocked(window); |
| 6492 | mH.obtainMessage(H.NOTIFY_WINDOW_TRANSITION, transition, 0, info).sendToTarget(); |
| 6493 | } |
| 6494 | } |
| 6495 | |
| 6496 | private void handleNotifyWindowTranstion(int transition, WindowInfo info) { |
| 6497 | RemoteCallbackList<IDisplayContentChangeListener> callbacks = null; |
| 6498 | synchronized (mWindowMap) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 6499 | DisplayContent displayContent = getDisplayContentLocked(info.displayId); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 6500 | if (displayContent == null) { |
| 6501 | return; |
| 6502 | } |
| 6503 | callbacks = displayContent.mDisplayContentChangeListeners; |
| 6504 | if (callbacks == null) { |
| 6505 | return; |
| 6506 | } |
| 6507 | } |
| 6508 | final int callbackCount = callbacks.beginBroadcast(); |
| 6509 | try { |
| 6510 | for (int i = 0; i < callbackCount; i++) { |
| 6511 | try { |
| 6512 | callbacks.getBroadcastItem(i).onWindowTransition(info.displayId, |
| 6513 | transition, info); |
| 6514 | } catch (RemoteException re) { |
| 6515 | /* ignore */ |
| 6516 | } |
| 6517 | } |
| 6518 | } finally { |
| 6519 | callbacks.finishBroadcast(); |
| 6520 | } |
| 6521 | } |
| 6522 | |
| 6523 | private void scheduleNotifyRotationChangedIfNeededLocked(DisplayContent displayContent, |
| 6524 | int rotation) { |
| 6525 | if (displayContent.mDisplayContentChangeListeners != null |
| 6526 | && displayContent.mDisplayContentChangeListeners.getRegisteredCallbackCount() > 0) { |
| 6527 | mH.obtainMessage(H.NOTIFY_ROTATION_CHANGED, displayContent.getDisplayId(), |
| 6528 | rotation).sendToTarget(); |
| 6529 | } |
| 6530 | } |
| 6531 | |
| 6532 | private void handleNotifyRotationChanged(int displayId, int rotation) { |
| 6533 | RemoteCallbackList<IDisplayContentChangeListener> callbacks = null; |
| 6534 | synchronized (mWindowMap) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 6535 | DisplayContent displayContent = getDisplayContentLocked(displayId); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 6536 | if (displayContent == null) { |
| 6537 | return; |
| 6538 | } |
| 6539 | callbacks = displayContent.mDisplayContentChangeListeners; |
| 6540 | if (callbacks == null) { |
| 6541 | return; |
| 6542 | } |
| 6543 | } |
| 6544 | try { |
| 6545 | final int watcherCount = callbacks.beginBroadcast(); |
| 6546 | for (int i = 0; i < watcherCount; i++) { |
| 6547 | try { |
| 6548 | callbacks.getBroadcastItem(i).onRotationChanged(rotation); |
| 6549 | } catch (RemoteException re) { |
| 6550 | /* ignore */ |
| 6551 | } |
| 6552 | } |
| 6553 | } finally { |
| 6554 | callbacks.finishBroadcast(); |
| 6555 | } |
| 6556 | } |
| 6557 | |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 6558 | public void addWindowChangeListener(WindowChangeListener listener) { |
| 6559 | synchronized(mWindowMap) { |
| 6560 | mWindowChangeListeners.add(listener); |
| 6561 | } |
| 6562 | } |
| 6563 | |
| 6564 | public void removeWindowChangeListener(WindowChangeListener listener) { |
| 6565 | synchronized(mWindowMap) { |
| 6566 | mWindowChangeListeners.remove(listener); |
| 6567 | } |
| 6568 | } |
| 6569 | |
| 6570 | private void notifyWindowsChanged() { |
| 6571 | WindowChangeListener[] windowChangeListeners; |
| 6572 | synchronized(mWindowMap) { |
| 6573 | if(mWindowChangeListeners.isEmpty()) { |
| 6574 | return; |
| 6575 | } |
| 6576 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 6577 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 6578 | } |
| 6579 | int N = windowChangeListeners.length; |
| 6580 | for(int i = 0; i < N; i++) { |
| 6581 | windowChangeListeners[i].windowsChanged(); |
| 6582 | } |
| 6583 | } |
| 6584 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 6585 | private void notifyFocusChanged() { |
| 6586 | WindowChangeListener[] windowChangeListeners; |
| 6587 | synchronized(mWindowMap) { |
| 6588 | if(mWindowChangeListeners.isEmpty()) { |
| 6589 | return; |
| 6590 | } |
| 6591 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 6592 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 6593 | } |
| 6594 | int N = windowChangeListeners.length; |
| 6595 | for(int i = 0; i < N; i++) { |
| 6596 | windowChangeListeners[i].focusChanged(); |
| 6597 | } |
| 6598 | } |
| 6599 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6600 | private WindowState findWindow(int hashCode) { |
| 6601 | if (hashCode == -1) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6602 | // TODO(multidisplay): Extend to multiple displays. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6603 | return getFocusedWindow(); |
| 6604 | } |
| 6605 | |
| 6606 | synchronized (mWindowMap) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6607 | final AllWindowsIterator iterator = new AllWindowsIterator(); |
| 6608 | while (iterator.hasNext()) { |
| 6609 | final WindowState w = iterator.next(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6610 | if (System.identityHashCode(w) == hashCode) { |
| 6611 | return w; |
| 6612 | } |
| 6613 | } |
| 6614 | } |
| 6615 | |
| 6616 | return null; |
| 6617 | } |
| 6618 | |
| 6619 | /* |
| 6620 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 6621 | * that to config-changed listeners if appropriate. |
| 6622 | */ |
| 6623 | void sendNewConfiguration() { |
| 6624 | try { |
| 6625 | mActivityManager.updateConfiguration(null); |
| 6626 | } catch (RemoteException e) { |
| 6627 | } |
| 6628 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6629 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6630 | public Configuration computeNewConfiguration() { |
| 6631 | synchronized (mWindowMap) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 6632 | Configuration config = computeNewConfigurationLocked(); |
| 6633 | if (config == null && mWaitingForConfig) { |
| 6634 | // Nothing changed but we are waiting for something... stop that! |
| 6635 | mWaitingForConfig = false; |
| 6636 | performLayoutAndPlaceSurfacesLocked(); |
| 6637 | } |
| 6638 | return config; |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 6639 | } |
| 6640 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6641 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 6642 | Configuration computeNewConfigurationLocked() { |
| 6643 | Configuration config = new Configuration(); |
Dianne Hackborn | 09e5b9d | 2011-10-04 16:32:01 -0700 | [diff] [blame] | 6644 | config.fontScale = 0; |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6645 | if (!computeScreenConfigurationLocked(config)) { |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 6646 | return null; |
| 6647 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 6648 | return config; |
| 6649 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6650 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6651 | private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int rotation, int dw, int dh) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 6652 | // TODO: Multidisplay: for now only use with default display. |
Dianne Hackborn | 68c33ca | 2012-04-19 14:51:25 -0700 | [diff] [blame] | 6653 | final int width = mPolicy.getConfigDisplayWidth(dw, dh, rotation); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6654 | if (width < displayInfo.smallestNominalAppWidth) { |
| 6655 | displayInfo.smallestNominalAppWidth = width; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 6656 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6657 | if (width > displayInfo.largestNominalAppWidth) { |
| 6658 | displayInfo.largestNominalAppWidth = width; |
Dianne Hackborn | 68c33ca | 2012-04-19 14:51:25 -0700 | [diff] [blame] | 6659 | } |
| 6660 | final int height = mPolicy.getConfigDisplayHeight(dw, dh, rotation); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6661 | if (height < displayInfo.smallestNominalAppHeight) { |
| 6662 | displayInfo.smallestNominalAppHeight = height; |
Dianne Hackborn | 68c33ca | 2012-04-19 14:51:25 -0700 | [diff] [blame] | 6663 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6664 | if (height > displayInfo.largestNominalAppHeight) { |
| 6665 | displayInfo.largestNominalAppHeight = height; |
Dianne Hackborn | 68c33ca | 2012-04-19 14:51:25 -0700 | [diff] [blame] | 6666 | } |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 6667 | } |
| 6668 | |
Dianne Hackborn | 56b53b5 | 2011-11-10 11:19:57 -0800 | [diff] [blame] | 6669 | private int reduceConfigLayout(int curLayout, int rotation, float density, |
| 6670 | int dw, int dh) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 6671 | // TODO: Multidisplay: for now only use with default display. |
Dianne Hackborn | 56b53b5 | 2011-11-10 11:19:57 -0800 | [diff] [blame] | 6672 | // Get the app screen size at this rotation. |
| 6673 | int w = mPolicy.getNonDecorDisplayWidth(dw, dh, rotation); |
| 6674 | int h = mPolicy.getNonDecorDisplayHeight(dw, dh, rotation); |
| 6675 | |
| 6676 | // Compute the screen layout size class for this rotation. |
Dianne Hackborn | 56b53b5 | 2011-11-10 11:19:57 -0800 | [diff] [blame] | 6677 | int longSize = w; |
| 6678 | int shortSize = h; |
| 6679 | if (longSize < shortSize) { |
| 6680 | int tmp = longSize; |
| 6681 | longSize = shortSize; |
| 6682 | shortSize = tmp; |
| 6683 | } |
| 6684 | longSize = (int)(longSize/density); |
| 6685 | shortSize = (int)(shortSize/density); |
Dianne Hackborn | fe37f8f | 2012-09-30 12:24:33 -0700 | [diff] [blame] | 6686 | return Configuration.reduceScreenLayout(curLayout, longSize, shortSize); |
Dianne Hackborn | 56b53b5 | 2011-11-10 11:19:57 -0800 | [diff] [blame] | 6687 | } |
| 6688 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6689 | private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, boolean rotated, |
| 6690 | int dw, int dh, float density, Configuration outConfig) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 6691 | // TODO: Multidisplay: for now only use with default display. |
| 6692 | |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 6693 | // We need to determine the smallest width that will occur under normal |
| 6694 | // operation. To this, start with the base screen size and compute the |
| 6695 | // width under the different possible rotations. We need to un-rotate |
| 6696 | // the current screen dimensions before doing this. |
| 6697 | int unrotDw, unrotDh; |
| 6698 | if (rotated) { |
| 6699 | unrotDw = dh; |
| 6700 | unrotDh = dw; |
| 6701 | } else { |
| 6702 | unrotDw = dw; |
| 6703 | unrotDh = dh; |
| 6704 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6705 | displayInfo.smallestNominalAppWidth = 1<<30; |
| 6706 | displayInfo.smallestNominalAppHeight = 1<<30; |
| 6707 | displayInfo.largestNominalAppWidth = 0; |
| 6708 | displayInfo.largestNominalAppHeight = 0; |
| 6709 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_0, unrotDw, unrotDh); |
| 6710 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_90, unrotDh, unrotDw); |
| 6711 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_180, unrotDw, unrotDh); |
| 6712 | adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_270, unrotDh, unrotDw); |
Dianne Hackborn | fe37f8f | 2012-09-30 12:24:33 -0700 | [diff] [blame] | 6713 | int sl = Configuration.resetScreenLayout(outConfig.screenLayout); |
Dianne Hackborn | 56b53b5 | 2011-11-10 11:19:57 -0800 | [diff] [blame] | 6714 | sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh); |
| 6715 | sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw); |
| 6716 | sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh); |
| 6717 | sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6718 | outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density); |
Dianne Hackborn | fe37f8f | 2012-09-30 12:24:33 -0700 | [diff] [blame] | 6719 | outConfig.screenLayout = sl; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 6720 | } |
| 6721 | |
Dianne Hackborn | 48a7651 | 2011-06-08 21:51:44 -0700 | [diff] [blame] | 6722 | private int reduceCompatConfigWidthSize(int curSize, int rotation, DisplayMetrics dm, |
| 6723 | int dw, int dh) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 6724 | // TODO: Multidisplay: for now only use with default display. |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 6725 | dm.noncompatWidthPixels = mPolicy.getNonDecorDisplayWidth(dw, dh, rotation); |
| 6726 | dm.noncompatHeightPixels = mPolicy.getNonDecorDisplayHeight(dw, dh, rotation); |
Dianne Hackborn | 48a7651 | 2011-06-08 21:51:44 -0700 | [diff] [blame] | 6727 | float scale = CompatibilityInfo.computeCompatibleScaling(dm, null); |
Dianne Hackborn | 2b31d53 | 2011-06-23 11:58:50 -0700 | [diff] [blame] | 6728 | int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f); |
Dianne Hackborn | 48a7651 | 2011-06-08 21:51:44 -0700 | [diff] [blame] | 6729 | if (curSize == 0 || size < curSize) { |
| 6730 | curSize = size; |
| 6731 | } |
| 6732 | return curSize; |
| 6733 | } |
| 6734 | |
| 6735 | private int computeCompatSmallestWidth(boolean rotated, DisplayMetrics dm, int dw, int dh) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 6736 | // TODO: Multidisplay: for now only use with default display. |
Dianne Hackborn | 48a7651 | 2011-06-08 21:51:44 -0700 | [diff] [blame] | 6737 | mTmpDisplayMetrics.setTo(dm); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 6738 | final DisplayMetrics tmpDm = mTmpDisplayMetrics; |
| 6739 | final int unrotDw, unrotDh; |
Dianne Hackborn | 48a7651 | 2011-06-08 21:51:44 -0700 | [diff] [blame] | 6740 | if (rotated) { |
| 6741 | unrotDw = dh; |
| 6742 | unrotDh = dw; |
| 6743 | } else { |
| 6744 | unrotDw = dw; |
| 6745 | unrotDh = dh; |
| 6746 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 6747 | int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, tmpDm, unrotDw, unrotDh); |
| 6748 | sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, tmpDm, unrotDh, unrotDw); |
| 6749 | sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, tmpDm, unrotDw, unrotDh); |
| 6750 | sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, tmpDm, unrotDh, unrotDw); |
Dianne Hackborn | 48a7651 | 2011-06-08 21:51:44 -0700 | [diff] [blame] | 6751 | return sw; |
| 6752 | } |
| 6753 | |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6754 | boolean computeScreenConfigurationLocked(Configuration config) { |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 6755 | if (!mDisplayReady) { |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 6756 | return false; |
| 6757 | } |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 6758 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6759 | // TODO(multidisplay): For now, apply Configuration to main screen only. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 6760 | final DisplayContent displayContent = getDefaultDisplayContentLocked(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6761 | |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 6762 | // Use the effective "visual" dimensions based on current rotation |
| 6763 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 6764 | || mRotation == Surface.ROTATION_270); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6765 | final int realdw = rotated ? |
| 6766 | displayContent.mBaseDisplayHeight : displayContent.mBaseDisplayWidth; |
| 6767 | final int realdh = rotated ? |
| 6768 | displayContent.mBaseDisplayWidth : displayContent.mBaseDisplayHeight; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 6769 | int dw = realdw; |
| 6770 | int dh = realdh; |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 6771 | |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 6772 | if (mAltOrientation) { |
| 6773 | if (realdw > realdh) { |
| 6774 | // Turn landscape into portrait. |
| 6775 | int maxw = (int)(realdh/1.3f); |
| 6776 | if (maxw < realdw) { |
| 6777 | dw = maxw; |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 6778 | } |
| 6779 | } else { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 6780 | // Turn portrait into landscape. |
| 6781 | int maxh = (int)(realdw/1.3f); |
| 6782 | if (maxh < realdh) { |
| 6783 | dh = maxh; |
| 6784 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 6785 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 6786 | } |
| 6787 | |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6788 | if (config != null) { |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 6789 | config.orientation = (dw <= dh) ? Configuration.ORIENTATION_PORTRAIT : |
| 6790 | Configuration.ORIENTATION_LANDSCAPE; |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 6791 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6792 | |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 6793 | // Update application display metrics. |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 6794 | final int appWidth = mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation); |
| 6795 | final int appHeight = mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6796 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
| 6797 | synchronized(displayContent.mDisplaySizeLock) { |
| 6798 | displayInfo.rotation = mRotation; |
| 6799 | displayInfo.logicalWidth = dw; |
| 6800 | displayInfo.logicalHeight = dh; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 6801 | displayInfo.logicalDensityDpi = displayContent.mBaseDisplayDensity; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6802 | displayInfo.appWidth = appWidth; |
| 6803 | displayInfo.appHeight = appHeight; |
| 6804 | displayInfo.getLogicalMetrics(mRealDisplayMetrics, null); |
| 6805 | displayInfo.getAppMetrics(mDisplayMetrics, null); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 6806 | mDisplayManagerService.setDisplayInfoOverrideFromWindowManager( |
| 6807 | displayContent.getDisplayId(), displayInfo); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 6808 | |
| 6809 | mAnimator.setDisplayDimensions(dw, dh, appWidth, appHeight); |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 6810 | } |
Dianne Hackborn | 3699174 | 2011-10-11 21:35:26 -0700 | [diff] [blame] | 6811 | if (false) { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 6812 | Slog.i(TAG, "Set app display size: " + appWidth + " x " + appHeight); |
Dianne Hackborn | 3699174 | 2011-10-11 21:35:26 -0700 | [diff] [blame] | 6813 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 6814 | |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 6815 | final DisplayMetrics dm = mDisplayMetrics; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 6816 | mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(dm, |
| 6817 | mCompatDisplayMetrics); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6818 | |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6819 | if (config != null) { |
| 6820 | config.screenWidthDp = (int)(mPolicy.getConfigDisplayWidth(dw, dh, mRotation) |
| 6821 | / dm.density); |
| 6822 | config.screenHeightDp = (int)(mPolicy.getConfigDisplayHeight(dw, dh, mRotation) |
| 6823 | / dm.density); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 6824 | computeSizeRangesAndScreenLayout(displayInfo, rotated, dw, dh, dm.density, config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 6825 | |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6826 | config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale); |
| 6827 | config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale); |
| 6828 | config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, dm, dw, dh); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 6829 | config.densityDpi = displayContent.mBaseDisplayDensity; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 6830 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 6831 | // Update the configuration based on available input devices, lid switch, |
| 6832 | // and platform configuration. |
| 6833 | config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH; |
| 6834 | config.keyboard = Configuration.KEYBOARD_NOKEYS; |
| 6835 | config.navigation = Configuration.NAVIGATION_NONAV; |
| 6836 | |
| 6837 | int keyboardPresence = 0; |
| 6838 | int navigationPresence = 0; |
Craig Mautner | 1d961d4 | 2012-05-27 12:02:11 -0700 | [diff] [blame] | 6839 | final InputDevice[] devices = mInputManager.getInputDevices(); |
| 6840 | final int len = devices.length; |
| 6841 | for (int i = 0; i < len; i++) { |
| 6842 | InputDevice device = devices[i]; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 6843 | if (!device.isVirtual()) { |
| 6844 | final int sources = device.getSources(); |
| 6845 | final int presenceFlag = device.isExternal() ? |
| 6846 | WindowManagerPolicy.PRESENCE_EXTERNAL : |
| 6847 | WindowManagerPolicy.PRESENCE_INTERNAL; |
| 6848 | |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 6849 | if (mIsTouchDevice) { |
Jeff Brown | 7e4ff4b | 2012-05-30 14:32:16 -0700 | [diff] [blame] | 6850 | if ((sources & InputDevice.SOURCE_TOUCHSCREEN) == |
| 6851 | InputDevice.SOURCE_TOUCHSCREEN) { |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 6852 | config.touchscreen = Configuration.TOUCHSCREEN_FINGER; |
| 6853 | } |
| 6854 | } else { |
| 6855 | config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 6856 | } |
| 6857 | |
Jeff Brown | 7e4ff4b | 2012-05-30 14:32:16 -0700 | [diff] [blame] | 6858 | if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) { |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 6859 | config.navigation = Configuration.NAVIGATION_TRACKBALL; |
| 6860 | navigationPresence |= presenceFlag; |
Jeff Brown | 7e4ff4b | 2012-05-30 14:32:16 -0700 | [diff] [blame] | 6861 | } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 6862 | && config.navigation == Configuration.NAVIGATION_NONAV) { |
| 6863 | config.navigation = Configuration.NAVIGATION_DPAD; |
| 6864 | navigationPresence |= presenceFlag; |
| 6865 | } |
| 6866 | |
| 6867 | if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) { |
| 6868 | config.keyboard = Configuration.KEYBOARD_QWERTY; |
| 6869 | keyboardPresence |= presenceFlag; |
| 6870 | } |
| 6871 | } |
| 6872 | } |
| 6873 | |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6874 | // Determine whether a hard keyboard is available and enabled. |
| 6875 | boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS; |
| 6876 | if (hardKeyboardAvailable != mHardKeyboardAvailable) { |
| 6877 | mHardKeyboardAvailable = hardKeyboardAvailable; |
| 6878 | mHardKeyboardEnabled = hardKeyboardAvailable; |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6879 | mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
| 6880 | mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
| 6881 | } |
| 6882 | if (!mHardKeyboardEnabled) { |
| 6883 | config.keyboard = Configuration.KEYBOARD_NOKEYS; |
| 6884 | } |
| 6885 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 6886 | // Let the policy update hidden states. |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 6887 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 6888 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 6889 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 6890 | mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence); |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 6891 | } |
Jeff Brown | 597eec8 | 2011-01-31 17:12:25 -0800 | [diff] [blame] | 6892 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 6893 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6894 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6895 | |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 6896 | public boolean isHardKeyboardAvailable() { |
| 6897 | synchronized (mWindowMap) { |
| 6898 | return mHardKeyboardAvailable; |
| 6899 | } |
| 6900 | } |
| 6901 | |
| 6902 | public boolean isHardKeyboardEnabled() { |
| 6903 | synchronized (mWindowMap) { |
| 6904 | return mHardKeyboardEnabled; |
| 6905 | } |
| 6906 | } |
| 6907 | |
| 6908 | public void setHardKeyboardEnabled(boolean enabled) { |
| 6909 | synchronized (mWindowMap) { |
| 6910 | if (mHardKeyboardEnabled != enabled) { |
| 6911 | mHardKeyboardEnabled = enabled; |
| 6912 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 6913 | } |
| 6914 | } |
| 6915 | } |
| 6916 | |
| 6917 | public void setOnHardKeyboardStatusChangeListener( |
| 6918 | OnHardKeyboardStatusChangeListener listener) { |
| 6919 | synchronized (mWindowMap) { |
| 6920 | mHardKeyboardStatusChangeListener = listener; |
| 6921 | } |
| 6922 | } |
| 6923 | |
| 6924 | void notifyHardKeyboardStatusChange() { |
| 6925 | final boolean available, enabled; |
| 6926 | final OnHardKeyboardStatusChangeListener listener; |
| 6927 | synchronized (mWindowMap) { |
| 6928 | listener = mHardKeyboardStatusChangeListener; |
| 6929 | available = mHardKeyboardAvailable; |
| 6930 | enabled = mHardKeyboardEnabled; |
| 6931 | } |
| 6932 | if (listener != null) { |
| 6933 | listener.onHardKeyboardStatusChange(available, enabled); |
| 6934 | } |
| 6935 | } |
| 6936 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6937 | // ------------------------------------------------------------- |
| 6938 | // Drag and drop |
| 6939 | // ------------------------------------------------------------- |
| 6940 | |
| 6941 | IBinder prepareDragSurface(IWindow window, SurfaceSession session, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 6942 | int flags, int width, int height, Surface outSurface) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6943 | if (DEBUG_DRAG) { |
| 6944 | Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 6945 | + " flags=" + Integer.toHexString(flags) + " win=" + window |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6946 | + " asbinder=" + window.asBinder()); |
| 6947 | } |
| 6948 | |
| 6949 | final int callerPid = Binder.getCallingPid(); |
| 6950 | final long origId = Binder.clearCallingIdentity(); |
| 6951 | IBinder token = null; |
| 6952 | |
| 6953 | try { |
| 6954 | synchronized (mWindowMap) { |
| 6955 | try { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6956 | if (mDragState == null) { |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 6957 | // TODO(multi-display): support other displays |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 6958 | final DisplayContent displayContent = getDefaultDisplayContentLocked(); |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 6959 | final Display display = displayContent.getDisplay(); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 6960 | Surface surface = new Surface(session, "drag surface", |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6961 | width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN); |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 6962 | surface.setLayerStack(display.getLayerStack()); |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 6963 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DRAG " |
| 6964 | + surface + ": CREATE"); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6965 | outSurface.copyFrom(surface); |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 6966 | final IBinder winBinder = window.asBinder(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6967 | token = new Binder(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 6968 | mDragState = new DragState(this, token, surface, /*flags*/ 0, winBinder); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6969 | token = mDragState.mToken = new Binder(); |
| 6970 | |
| 6971 | // 5 second timeout for this window to actually begin the drag |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 6972 | mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder); |
| 6973 | Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6974 | mH.sendMessageDelayed(msg, 5000); |
| 6975 | } else { |
| 6976 | Slog.w(TAG, "Drag already in progress"); |
| 6977 | } |
| 6978 | } catch (Surface.OutOfResourcesException e) { |
| 6979 | Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e); |
| 6980 | if (mDragState != null) { |
| 6981 | mDragState.reset(); |
| 6982 | mDragState = null; |
| 6983 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6984 | } |
| 6985 | } |
| 6986 | } finally { |
| 6987 | Binder.restoreCallingIdentity(origId); |
| 6988 | } |
| 6989 | |
| 6990 | return token; |
| 6991 | } |
| 6992 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6993 | // ------------------------------------------------------------- |
| 6994 | // Input Events and Focus Management |
| 6995 | // ------------------------------------------------------------- |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6996 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 6997 | final InputMonitor mInputMonitor = new InputMonitor(this); |
Jeff Brown | 08a746a | 2012-06-24 12:14:49 -0700 | [diff] [blame] | 6998 | private boolean mEventDispatchingEnabled; |
| 6999 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7000 | public void pauseKeyDispatching(IBinder _token) { |
| 7001 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 7002 | "pauseKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 7003 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7004 | } |
| 7005 | |
| 7006 | synchronized (mWindowMap) { |
| 7007 | WindowToken token = mTokenMap.get(_token); |
| 7008 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 7009 | mInputMonitor.pauseDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7010 | } |
| 7011 | } |
| 7012 | } |
| 7013 | |
| 7014 | public void resumeKeyDispatching(IBinder _token) { |
| 7015 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 7016 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 7017 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7018 | } |
| 7019 | |
| 7020 | synchronized (mWindowMap) { |
| 7021 | WindowToken token = mTokenMap.get(_token); |
| 7022 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 7023 | mInputMonitor.resumeDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7024 | } |
| 7025 | } |
| 7026 | } |
| 7027 | |
| 7028 | public void setEventDispatching(boolean enabled) { |
| 7029 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
Craig Mautner | 3d7b7d5 | 2012-05-24 11:28:26 -0700 | [diff] [blame] | 7030 | "setEventDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 7031 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7032 | } |
| 7033 | |
| 7034 | synchronized (mWindowMap) { |
Jeff Brown | 08a746a | 2012-06-24 12:14:49 -0700 | [diff] [blame] | 7035 | mEventDispatchingEnabled = enabled; |
| 7036 | if (mDisplayEnabled) { |
| 7037 | mInputMonitor.setEventDispatchingLw(enabled); |
| 7038 | } |
Craig Mautner | 3d7b7d5 | 2012-05-24 11:28:26 -0700 | [diff] [blame] | 7039 | sendScreenStatusToClientsLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7040 | } |
| 7041 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7042 | |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 7043 | public IBinder getFocusedWindowToken() { |
| 7044 | if (!checkCallingPermission(android.Manifest.permission.RETRIEVE_WINDOW_INFO, |
| 7045 | "getFocusedWindowToken()")) { |
| 7046 | throw new SecurityException("Requires RETRIEVE_WINDOW_INFO permission."); |
| 7047 | } |
Svetoslav Ganov | e15ccb9 | 2012-05-16 15:48:55 -0700 | [diff] [blame] | 7048 | synchronized (mWindowMap) { |
| 7049 | WindowState windowState = getFocusedWindowLocked(); |
| 7050 | if (windowState != null) { |
| 7051 | return windowState.mClient.asBinder(); |
| 7052 | } |
| 7053 | return null; |
| 7054 | } |
| 7055 | } |
| 7056 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7057 | private WindowState getFocusedWindow() { |
| 7058 | synchronized (mWindowMap) { |
| 7059 | return getFocusedWindowLocked(); |
| 7060 | } |
| 7061 | } |
| 7062 | |
| 7063 | private WindowState getFocusedWindowLocked() { |
| 7064 | return mCurrentFocus; |
| 7065 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7066 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7067 | public boolean detectSafeMode() { |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 7068 | if (!mInputMonitor.waitForInputDevicesReady( |
| 7069 | INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) { |
| 7070 | Slog.w(TAG, "Devices still not ready after waiting " |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 7071 | + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS |
| 7072 | + " milliseconds before attempting to detect safe mode."); |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 7073 | } |
| 7074 | |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 7075 | int menuState = mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, |
| 7076 | KeyEvent.KEYCODE_MENU); |
| 7077 | int sState = mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, KeyEvent.KEYCODE_S); |
| 7078 | int dpadState = mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, |
| 7079 | KeyEvent.KEYCODE_DPAD_CENTER); |
| 7080 | int trackballState = mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 7081 | InputManagerService.BTN_MOUSE); |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 7082 | int volumeDownState = mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, |
| 7083 | KeyEvent.KEYCODE_VOLUME_DOWN); |
| 7084 | mSafeMode = menuState > 0 || sState > 0 || dpadState > 0 || trackballState > 0 |
| 7085 | || volumeDownState > 0; |
Dianne Hackborn | 19caadc | 2012-04-20 17:49:10 -0700 | [diff] [blame] | 7086 | try { |
| 7087 | if (SystemProperties.getInt(ShutdownThread.REBOOT_SAFEMODE_PROPERTY, 0) != 0) { |
| 7088 | mSafeMode = true; |
| 7089 | SystemProperties.set(ShutdownThread.REBOOT_SAFEMODE_PROPERTY, ""); |
| 7090 | } |
| 7091 | } catch (IllegalArgumentException e) { |
| 7092 | } |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 7093 | if (mSafeMode) { |
| 7094 | Log.i(TAG, "SAFE MODE ENABLED (menu=" + menuState + " s=" + sState |
| 7095 | + " dpad=" + dpadState + " trackball=" + trackballState + ")"); |
| 7096 | } else { |
| 7097 | Log.i(TAG, "SAFE MODE not enabled"); |
| 7098 | } |
| 7099 | mPolicy.setSafeMode(mSafeMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7100 | return mSafeMode; |
| 7101 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7102 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7103 | public void displayReady() { |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 7104 | displayReady(Display.DEFAULT_DISPLAY); |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 7105 | |
| 7106 | synchronized(mWindowMap) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 7107 | final DisplayContent displayContent = getDefaultDisplayContentLocked(); |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 7108 | final Display display = displayContent.getDisplay(); |
| 7109 | readForcedDisplaySizeAndDensityLocked(displayContent); |
Dianne Hackborn | 5a052a4 | 2012-08-15 18:49:23 -0700 | [diff] [blame] | 7110 | |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 7111 | mDisplayReady = true; |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 7112 | mIsTouchDevice = mContext.getPackageManager().hasSystemFeature( |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 7113 | PackageManager.FEATURE_TOUCHSCREEN); |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 7114 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 7115 | final DisplayInfo displayInfo = getDefaultDisplayInfoLocked(); |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 7116 | mAnimator.setDisplayDimensions( |
| 7117 | displayInfo.logicalWidth, displayInfo.logicalHeight, |
| 7118 | displayInfo.appWidth, displayInfo.appHeight); |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 7119 | |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 7120 | mPolicy.setInitialDisplaySize(displayContent.getDisplay(), |
| 7121 | displayContent.mInitialDisplayWidth, |
| 7122 | displayContent.mInitialDisplayHeight, |
| 7123 | displayContent.mInitialDisplayDensity); |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 7124 | } |
Dianne Hackborn | 5a052a4 | 2012-08-15 18:49:23 -0700 | [diff] [blame] | 7125 | |
| 7126 | try { |
| 7127 | mActivityManager.updateConfiguration(null); |
| 7128 | } catch (RemoteException e) { |
| 7129 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7130 | } |
| 7131 | |
| 7132 | public void displayReady(int displayId) { |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 7133 | synchronized(mWindowMap) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 7134 | final DisplayContent displayContent = getDisplayContentLocked(displayId); |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 7135 | final DisplayInfo displayInfo; |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 7136 | mAnimator.addDisplayLocked(displayId); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7137 | synchronized(displayContent.mDisplaySizeLock) { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 7138 | // Bootstrap the default logical display from the display manager. |
Craig Mautner | 4f67ba6 | 2012-08-02 11:23:00 -0700 | [diff] [blame] | 7139 | displayInfo = displayContent.getDisplayInfo(); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 7140 | DisplayInfo newDisplayInfo = mDisplayManagerService.getDisplayInfo(displayId); |
| 7141 | if (newDisplayInfo != null) { |
| 7142 | displayInfo.copyFrom(newDisplayInfo); |
| 7143 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7144 | displayContent.mInitialDisplayWidth = displayInfo.logicalWidth; |
| 7145 | displayContent.mInitialDisplayHeight = displayInfo.logicalHeight; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7146 | displayContent.mInitialDisplayDensity = displayInfo.logicalDensityDpi; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7147 | displayContent.mBaseDisplayWidth = displayContent.mInitialDisplayWidth; |
| 7148 | displayContent.mBaseDisplayHeight = displayContent.mInitialDisplayHeight; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7149 | displayContent.mBaseDisplayDensity = displayContent.mInitialDisplayDensity; |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 7150 | } |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 7151 | } |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 7152 | } |
| 7153 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 7154 | public void systemReady() { |
| 7155 | mPolicy.systemReady(); |
| 7156 | } |
| 7157 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7158 | // TODO(multidisplay): Call isScreenOn for each display. |
Craig Mautner | 3d7b7d5 | 2012-05-24 11:28:26 -0700 | [diff] [blame] | 7159 | private void sendScreenStatusToClientsLocked() { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7160 | final boolean on = mPowerManager.isScreenOn(); |
| 7161 | final AllWindowsIterator iterator = new AllWindowsIterator(); |
| 7162 | while (iterator.hasNext()) { |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 7163 | try { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7164 | iterator.next().mClient.dispatchScreenState(on); |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 7165 | } catch (RemoteException e) { |
| 7166 | // Ignored |
| 7167 | } |
| 7168 | } |
| 7169 | } |
| 7170 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7171 | // ------------------------------------------------------------- |
| 7172 | // Async Handler |
| 7173 | // ------------------------------------------------------------- |
| 7174 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 7175 | final class H extends Handler { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7176 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 7177 | public static final int REPORT_LOSING_FOCUS = 3; |
Dianne Hackborn | 8bcd54b | 2012-01-31 19:04:53 -0800 | [diff] [blame] | 7178 | public static final int DO_TRAVERSAL = 4; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7179 | public static final int ADD_STARTING = 5; |
| 7180 | public static final int REMOVE_STARTING = 6; |
| 7181 | public static final int FINISHED_STARTING = 7; |
| 7182 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 7183 | public static final int REPORT_APPLICATION_TOKEN_DRAWN = 9; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7184 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
Craig Mautner | 259328c | 2012-08-21 19:30:58 -0700 | [diff] [blame] | 7185 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7186 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 7187 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 7188 | public static final int FORCE_GC = 15; |
| 7189 | public static final int ENABLE_SCREEN = 16; |
| 7190 | public static final int APP_FREEZE_TIMEOUT = 17; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7191 | public static final int SEND_NEW_CONFIGURATION = 18; |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 7192 | public static final int REPORT_WINDOWS_CHANGE = 19; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7193 | public static final int DRAG_START_TIMEOUT = 20; |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 7194 | public static final int DRAG_END_TIMEOUT = 21; |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 7195 | public static final int REPORT_HARD_KEYBOARD_STATUS_CHANGE = 22; |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 7196 | public static final int BOOT_TIMEOUT = 23; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 7197 | public static final int WAITING_FOR_DRAWN_TIMEOUT = 24; |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 7198 | public static final int UPDATE_ANIM_PARAMETERS = 25; |
Craig Mautner | 0447a81 | 2012-05-22 16:01:31 -0700 | [diff] [blame] | 7199 | public static final int SHOW_STRICT_MODE_VIOLATION = 26; |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 7200 | public static final int DO_ANIMATION_CALLBACK = 27; |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 7201 | public static final int NOTIFY_ROTATION_CHANGED = 28; |
| 7202 | public static final int NOTIFY_WINDOW_TRANSITION = 29; |
| 7203 | public static final int NOTIFY_RECTANGLE_ON_SCREEN_REQUESTED = 30; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7204 | |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 7205 | public static final int DO_DISPLAY_ADDED = 31; |
| 7206 | public static final int DO_DISPLAY_REMOVED = 32; |
| 7207 | public static final int DO_DISPLAY_CHANGED = 33; |
| 7208 | |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 7209 | public static final int CLIENT_FREEZE_TIMEOUT = 34; |
| 7210 | |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 7211 | public static final int ANIMATOR_WHAT_OFFSET = 100000; |
| 7212 | public static final int SET_TRANSPARENT_REGION = ANIMATOR_WHAT_OFFSET + 1; |
Craig Mautner | 12670b5 | 2012-07-03 19:15:35 -0700 | [diff] [blame] | 7213 | public static final int CLEAR_PENDING_ACTIONS = ANIMATOR_WHAT_OFFSET + 2; |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 7214 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7215 | public H() { |
| 7216 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7217 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7218 | @Override |
| 7219 | public void handleMessage(Message msg) { |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 7220 | if (DEBUG_WINDOW_TRACE) { |
| 7221 | Slog.v(TAG, "handleMessage: entry what=" + msg.what); |
| 7222 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7223 | switch (msg.what) { |
| 7224 | case REPORT_FOCUS_CHANGE: { |
| 7225 | WindowState lastFocus; |
| 7226 | WindowState newFocus; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7227 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7228 | synchronized(mWindowMap) { |
| 7229 | lastFocus = mLastFocus; |
| 7230 | newFocus = mCurrentFocus; |
| 7231 | if (lastFocus == newFocus) { |
| 7232 | // Focus is not changing, so nothing to do. |
| 7233 | return; |
| 7234 | } |
| 7235 | mLastFocus = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7236 | //Slog.i(TAG, "Focus moving from " + lastFocus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7237 | // + " to " + newFocus); |
| 7238 | if (newFocus != null && lastFocus != null |
| 7239 | && !newFocus.isDisplayedLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7240 | //Slog.i(TAG, "Delaying loss of focus..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7241 | mLosingFocus.add(lastFocus); |
| 7242 | lastFocus = null; |
| 7243 | } |
| 7244 | } |
| 7245 | |
| 7246 | if (lastFocus != newFocus) { |
| 7247 | //System.out.println("Changing focus from " + lastFocus |
| 7248 | // + " to " + newFocus); |
| 7249 | if (newFocus != null) { |
| 7250 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7251 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7252 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 7253 | } catch (RemoteException e) { |
| 7254 | // Ignore if process has died. |
| 7255 | } |
Konstantin Lopyrev | 5e7833a | 2010-08-09 17:01:11 -0700 | [diff] [blame] | 7256 | notifyFocusChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7257 | } |
| 7258 | |
| 7259 | if (lastFocus != null) { |
| 7260 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7261 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7262 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 7263 | } catch (RemoteException e) { |
| 7264 | // Ignore if process has died. |
| 7265 | } |
| 7266 | } |
| 7267 | } |
| 7268 | } break; |
| 7269 | |
| 7270 | case REPORT_LOSING_FOCUS: { |
| 7271 | ArrayList<WindowState> losers; |
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 | synchronized(mWindowMap) { |
| 7274 | losers = mLosingFocus; |
| 7275 | mLosingFocus = new ArrayList<WindowState>(); |
| 7276 | } |
| 7277 | |
| 7278 | final int N = losers.size(); |
| 7279 | for (int i=0; i<N; i++) { |
| 7280 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7281 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7282 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 7283 | } catch (RemoteException e) { |
| 7284 | // Ignore if process has died. |
| 7285 | } |
| 7286 | } |
| 7287 | } break; |
| 7288 | |
Dianne Hackborn | 8bcd54b | 2012-01-31 19:04:53 -0800 | [diff] [blame] | 7289 | case DO_TRAVERSAL: { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7290 | synchronized(mWindowMap) { |
Dianne Hackborn | 8bcd54b | 2012-01-31 19:04:53 -0800 | [diff] [blame] | 7291 | mTraversalScheduled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7292 | performLayoutAndPlaceSurfacesLocked(); |
| 7293 | } |
| 7294 | } break; |
| 7295 | |
| 7296 | case ADD_STARTING: { |
| 7297 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7298 | final StartingData sd = wtoken.startingData; |
| 7299 | |
| 7300 | if (sd == null) { |
| 7301 | // Animation has been canceled... do nothing. |
| 7302 | return; |
| 7303 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7304 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7305 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7306 | + wtoken + ": pkg=" + sd.pkg); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7307 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7308 | View view = null; |
| 7309 | try { |
| 7310 | view = mPolicy.addStartingWindow( |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 7311 | wtoken.token, sd.pkg, sd.theme, sd.compatInfo, |
| 7312 | sd.nonLocalizedLabel, sd.labelRes, sd.icon, sd.windowFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7313 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7314 | Slog.w(TAG, "Exception when adding starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7315 | } |
| 7316 | |
| 7317 | if (view != null) { |
| 7318 | boolean abort = false; |
| 7319 | |
| 7320 | synchronized(mWindowMap) { |
| 7321 | if (wtoken.removed || wtoken.startingData == null) { |
| 7322 | // If the window was successfully added, then |
| 7323 | // we need to remove it. |
| 7324 | if (wtoken.startingWindow != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7325 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7326 | "Aborted starting " + wtoken |
| 7327 | + ": removed=" + wtoken.removed |
| 7328 | + " startingData=" + wtoken.startingData); |
| 7329 | wtoken.startingWindow = null; |
| 7330 | wtoken.startingData = null; |
| 7331 | abort = true; |
| 7332 | } |
| 7333 | } else { |
| 7334 | wtoken.startingView = view; |
| 7335 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7336 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7337 | "Added starting " + wtoken |
| 7338 | + ": startingWindow=" |
| 7339 | + wtoken.startingWindow + " startingView=" |
| 7340 | + wtoken.startingView); |
| 7341 | } |
| 7342 | |
| 7343 | if (abort) { |
| 7344 | try { |
| 7345 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 7346 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7347 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7348 | } |
| 7349 | } |
| 7350 | } |
| 7351 | } break; |
| 7352 | |
| 7353 | case REMOVE_STARTING: { |
| 7354 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7355 | IBinder token = null; |
| 7356 | View view = null; |
| 7357 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7358 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7359 | + wtoken + ": startingWindow=" |
| 7360 | + wtoken.startingWindow + " startingView=" |
| 7361 | + wtoken.startingView); |
| 7362 | if (wtoken.startingWindow != null) { |
| 7363 | view = wtoken.startingView; |
| 7364 | token = wtoken.token; |
| 7365 | wtoken.startingData = null; |
| 7366 | wtoken.startingView = null; |
| 7367 | wtoken.startingWindow = null; |
Craig Mautner | 38b2478 | 2012-07-02 16:21:28 -0700 | [diff] [blame] | 7368 | wtoken.startingDisplayed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7369 | } |
| 7370 | } |
| 7371 | if (view != null) { |
| 7372 | try { |
| 7373 | mPolicy.removeStartingWindow(token, view); |
| 7374 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7375 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7376 | } |
| 7377 | } |
| 7378 | } break; |
| 7379 | |
| 7380 | case FINISHED_STARTING: { |
| 7381 | IBinder token = null; |
| 7382 | View view = null; |
| 7383 | while (true) { |
| 7384 | synchronized (mWindowMap) { |
| 7385 | final int N = mFinishedStarting.size(); |
| 7386 | if (N <= 0) { |
| 7387 | break; |
| 7388 | } |
| 7389 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 7390 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7391 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7392 | "Finished starting " + wtoken |
| 7393 | + ": startingWindow=" + wtoken.startingWindow |
| 7394 | + " startingView=" + wtoken.startingView); |
| 7395 | |
| 7396 | if (wtoken.startingWindow == null) { |
| 7397 | continue; |
| 7398 | } |
| 7399 | |
| 7400 | view = wtoken.startingView; |
| 7401 | token = wtoken.token; |
| 7402 | wtoken.startingData = null; |
| 7403 | wtoken.startingView = null; |
| 7404 | wtoken.startingWindow = null; |
Craig Mautner | 38b2478 | 2012-07-02 16:21:28 -0700 | [diff] [blame] | 7405 | wtoken.startingDisplayed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7406 | } |
| 7407 | |
| 7408 | try { |
| 7409 | mPolicy.removeStartingWindow(token, view); |
| 7410 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7411 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7412 | } |
| 7413 | } |
| 7414 | } break; |
| 7415 | |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 7416 | case REPORT_APPLICATION_TOKEN_DRAWN: { |
| 7417 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7418 | |
| 7419 | try { |
| 7420 | if (DEBUG_VISIBILITY) Slog.v( |
| 7421 | TAG, "Reporting drawn in " + wtoken); |
| 7422 | wtoken.appToken.windowsDrawn(); |
| 7423 | } catch (RemoteException ex) { |
| 7424 | } |
| 7425 | } break; |
| 7426 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7427 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 7428 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7429 | |
| 7430 | boolean nowVisible = msg.arg1 != 0; |
| 7431 | boolean nowGone = msg.arg2 != 0; |
| 7432 | |
| 7433 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7434 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7435 | TAG, "Reporting visible in " + wtoken |
| 7436 | + " visible=" + nowVisible |
| 7437 | + " gone=" + nowGone); |
| 7438 | if (nowVisible) { |
| 7439 | wtoken.appToken.windowsVisible(); |
| 7440 | } else { |
| 7441 | wtoken.appToken.windowsGone(); |
| 7442 | } |
| 7443 | } catch (RemoteException ex) { |
| 7444 | } |
| 7445 | } break; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7446 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7447 | case WINDOW_FREEZE_TIMEOUT: { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7448 | // TODO(multidisplay): Can non-default displays rotate? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7449 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7450 | Slog.w(TAG, "Window freeze timeout expired."); |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 7451 | final WindowList windows = getDefaultWindowListLocked(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7452 | int i = windows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7453 | while (i > 0) { |
| 7454 | i--; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7455 | WindowState w = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7456 | if (w.mOrientationChanging) { |
| 7457 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7458 | Slog.w(TAG, "Force clearing orientation change: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7459 | } |
| 7460 | } |
| 7461 | performLayoutAndPlaceSurfacesLocked(); |
| 7462 | } |
| 7463 | break; |
| 7464 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7465 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7466 | case APP_TRANSITION_TIMEOUT: { |
| 7467 | synchronized (mWindowMap) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 7468 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7469 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7470 | "*** APP TRANSITION TIMEOUT"); |
| 7471 | mAppTransitionReady = true; |
| 7472 | mAppTransitionTimeout = true; |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 7473 | mAnimatingAppTokens.clear(); |
| 7474 | mAnimatingAppTokens.addAll(mAppTokens); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7475 | performLayoutAndPlaceSurfacesLocked(); |
| 7476 | } |
| 7477 | } |
| 7478 | break; |
| 7479 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7480 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7481 | case PERSIST_ANIMATION_SCALE: { |
| 7482 | Settings.System.putFloat(mContext.getContentResolver(), |
| 7483 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 7484 | Settings.System.putFloat(mContext.getContentResolver(), |
| 7485 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
Chet Haase | c38fa1f | 2012-02-01 16:37:46 -0800 | [diff] [blame] | 7486 | Settings.System.putFloat(mContext.getContentResolver(), |
| 7487 | Settings.System.ANIMATOR_DURATION_SCALE, mAnimatorDurationScale); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7488 | break; |
| 7489 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7490 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7491 | case FORCE_GC: { |
Craig Mautner | 1caa399 | 2012-06-22 09:46:48 -0700 | [diff] [blame] | 7492 | synchronized (mWindowMap) { |
| 7493 | synchronized (mAnimator) { |
| 7494 | // Since we're holding both mWindowMap and mAnimator we don't need to |
| 7495 | // hold mAnimator.mLayoutToAnim. |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 7496 | if (mAnimator.mAnimating || mLayoutToAnim.mAnimationScheduled) { |
Craig Mautner | 1caa399 | 2012-06-22 09:46:48 -0700 | [diff] [blame] | 7497 | // If we are animating, don't do the gc now but |
| 7498 | // delay a bit so we don't interrupt the animation. |
| 7499 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 7500 | 2000); |
| 7501 | return; |
| 7502 | } |
| 7503 | // If we are currently rotating the display, it will |
| 7504 | // schedule a new message when done. |
| 7505 | if (mDisplayFrozen) { |
| 7506 | return; |
| 7507 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7508 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7509 | } |
| 7510 | Runtime.getRuntime().gc(); |
| 7511 | break; |
| 7512 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7513 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7514 | case ENABLE_SCREEN: { |
| 7515 | performEnableScreen(); |
| 7516 | break; |
| 7517 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7518 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7519 | case APP_FREEZE_TIMEOUT: { |
| 7520 | synchronized (mWindowMap) { |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 7521 | synchronized (mAnimator) { |
| 7522 | Slog.w(TAG, "App freeze timeout expired."); |
| 7523 | int i = mAppTokens.size(); |
| 7524 | while (i > 0) { |
| 7525 | i--; |
| 7526 | AppWindowToken tok = mAppTokens.get(i); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 7527 | if (tok.mAppAnimator.freezingScreen) { |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 7528 | Slog.w(TAG, "Force clearing freeze: " + tok); |
| 7529 | unsetAppFreezingScreenLocked(tok, true, true); |
| 7530 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7531 | } |
| 7532 | } |
| 7533 | } |
| 7534 | break; |
| 7535 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7536 | |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 7537 | case CLIENT_FREEZE_TIMEOUT: { |
| 7538 | synchronized (mWindowMap) { |
| 7539 | if (mClientFreezingScreen) { |
| 7540 | mClientFreezingScreen = false; |
| 7541 | stopFreezingDisplayLocked(); |
| 7542 | } |
| 7543 | } |
| 7544 | break; |
| 7545 | } |
| 7546 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7547 | case SEND_NEW_CONFIGURATION: { |
| 7548 | removeMessages(SEND_NEW_CONFIGURATION); |
| 7549 | sendNewConfiguration(); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 7550 | break; |
| 7551 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7552 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 7553 | case REPORT_WINDOWS_CHANGE: { |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 7554 | if (mWindowsChanged) { |
| 7555 | synchronized (mWindowMap) { |
| 7556 | mWindowsChanged = false; |
| 7557 | } |
| 7558 | notifyWindowsChanged(); |
| 7559 | } |
| 7560 | break; |
| 7561 | } |
| 7562 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7563 | case DRAG_START_TIMEOUT: { |
| 7564 | IBinder win = (IBinder)msg.obj; |
| 7565 | if (DEBUG_DRAG) { |
| 7566 | Slog.w(TAG, "Timeout starting drag by win " + win); |
| 7567 | } |
| 7568 | synchronized (mWindowMap) { |
| 7569 | // !!! TODO: ANR the app that has failed to start the drag in time |
| 7570 | if (mDragState != null) { |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 7571 | mDragState.unregister(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 7572 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7573 | mDragState.reset(); |
| 7574 | mDragState = null; |
| 7575 | } |
| 7576 | } |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 7577 | break; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7578 | } |
| 7579 | |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 7580 | case DRAG_END_TIMEOUT: { |
| 7581 | IBinder win = (IBinder)msg.obj; |
| 7582 | if (DEBUG_DRAG) { |
| 7583 | Slog.w(TAG, "Timeout ending drag to win " + win); |
| 7584 | } |
| 7585 | synchronized (mWindowMap) { |
| 7586 | // !!! TODO: ANR the drag-receiving app |
Christopher Tate | d9be36c | 2011-08-16 16:09:33 -0700 | [diff] [blame] | 7587 | if (mDragState != null) { |
| 7588 | mDragState.mDragResult = false; |
| 7589 | mDragState.endDragLw(); |
| 7590 | } |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 7591 | } |
| 7592 | break; |
| 7593 | } |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 7594 | |
| 7595 | case REPORT_HARD_KEYBOARD_STATUS_CHANGE: { |
| 7596 | notifyHardKeyboardStatusChange(); |
| 7597 | break; |
| 7598 | } |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 7599 | |
| 7600 | case BOOT_TIMEOUT: { |
| 7601 | performBootTimeout(); |
| 7602 | break; |
| 7603 | } |
| 7604 | |
| 7605 | case WAITING_FOR_DRAWN_TIMEOUT: { |
| 7606 | Pair<WindowState, IRemoteCallback> pair; |
| 7607 | synchronized (mWindowMap) { |
| 7608 | pair = (Pair<WindowState, IRemoteCallback>)msg.obj; |
| 7609 | Slog.w(TAG, "Timeout waiting for drawn: " + pair.first); |
| 7610 | if (!mWaitingForDrawn.remove(pair)) { |
| 7611 | return; |
| 7612 | } |
| 7613 | } |
| 7614 | try { |
| 7615 | pair.second.sendResult(null); |
| 7616 | } catch (RemoteException e) { |
| 7617 | } |
| 7618 | break; |
| 7619 | } |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 7620 | |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 7621 | case UPDATE_ANIM_PARAMETERS: { |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 7622 | // Used to send multiple changes from the animation side to the layout side. |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 7623 | synchronized (mWindowMap) { |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 7624 | if (copyAnimToLayoutParamsLocked()) { |
| 7625 | mH.sendEmptyMessage(CLEAR_PENDING_ACTIONS); |
| 7626 | performLayoutAndPlaceSurfacesLocked(); |
Craig Mautner | 73850cb | 2012-04-10 12:56:27 -0700 | [diff] [blame] | 7627 | } |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 7628 | } |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 7629 | break; |
| 7630 | } |
| 7631 | |
Craig Mautner | 0447a81 | 2012-05-22 16:01:31 -0700 | [diff] [blame] | 7632 | case SHOW_STRICT_MODE_VIOLATION: { |
| 7633 | showStrictModeViolation(msg.arg1); |
| 7634 | break; |
| 7635 | } |
| 7636 | |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 7637 | // Animation messages. Move to Window{State}Animator |
| 7638 | case SET_TRANSPARENT_REGION: { |
Craig Mautner | bec53f7 | 2012-04-05 11:49:05 -0700 | [diff] [blame] | 7639 | Pair<WindowStateAnimator, Region> pair = |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 7640 | (Pair<WindowStateAnimator, Region>) msg.obj; |
Craig Mautner | bec53f7 | 2012-04-05 11:49:05 -0700 | [diff] [blame] | 7641 | final WindowStateAnimator winAnimator = pair.first; |
| 7642 | winAnimator.setTransparentRegionHint(pair.second); |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 7643 | break; |
| 7644 | } |
| 7645 | |
Craig Mautner | 4d7349b | 2012-04-20 14:52:47 -0700 | [diff] [blame] | 7646 | case CLEAR_PENDING_ACTIONS: { |
| 7647 | mAnimator.clearPendingActions(); |
| 7648 | break; |
| 7649 | } |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 7650 | |
| 7651 | case DO_ANIMATION_CALLBACK: { |
| 7652 | try { |
| 7653 | ((IRemoteCallback)msg.obj).sendResult(null); |
| 7654 | } catch (RemoteException e) { |
| 7655 | } |
| 7656 | break; |
| 7657 | } |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 7658 | |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 7659 | case NOTIFY_ROTATION_CHANGED: { |
| 7660 | final int displayId = msg.arg1; |
| 7661 | final int rotation = msg.arg2; |
| 7662 | handleNotifyRotationChanged(displayId, rotation); |
| 7663 | break; |
| 7664 | } |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 7665 | |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 7666 | case NOTIFY_WINDOW_TRANSITION: { |
| 7667 | final int transition = msg.arg1; |
| 7668 | WindowInfo info = (WindowInfo) msg.obj; |
| 7669 | handleNotifyWindowTranstion(transition, info); |
| 7670 | break; |
| 7671 | } |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 7672 | |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 7673 | case NOTIFY_RECTANGLE_ON_SCREEN_REQUESTED: { |
| 7674 | final int displayId = msg.arg1; |
| 7675 | final boolean immediate = (msg.arg2 == 1); |
| 7676 | Rect rectangle = (Rect) msg.obj; |
| 7677 | handleNotifyRectangleOnScreenRequested(displayId, rectangle, immediate); |
| 7678 | break; |
| 7679 | } |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 7680 | |
| 7681 | case DO_DISPLAY_ADDED: |
| 7682 | synchronized (mWindowMap) { |
| 7683 | handleDisplayAddedLocked(msg.arg1); |
| 7684 | } |
| 7685 | break; |
| 7686 | |
| 7687 | case DO_DISPLAY_REMOVED: |
| 7688 | synchronized (mWindowMap) { |
| 7689 | handleDisplayRemovedLocked(msg.arg1); |
| 7690 | } |
| 7691 | break; |
| 7692 | |
| 7693 | case DO_DISPLAY_CHANGED: |
| 7694 | synchronized (mWindowMap) { |
| 7695 | handleDisplayChangedLocked(msg.arg1); |
| 7696 | } |
| 7697 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7698 | } |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 7699 | if (DEBUG_WINDOW_TRACE) { |
| 7700 | Slog.v(TAG, "handleMessage: exit"); |
| 7701 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7702 | } |
| 7703 | } |
| 7704 | |
| 7705 | // ------------------------------------------------------------- |
| 7706 | // IWindowManager API |
| 7707 | // ------------------------------------------------------------- |
| 7708 | |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 7709 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7710 | public IWindowSession openSession(IInputMethodClient client, |
| 7711 | IInputContext inputContext) { |
| 7712 | if (client == null) throw new IllegalArgumentException("null client"); |
| 7713 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 7714 | Session session = new Session(this, client, inputContext); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7715 | return session; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7716 | } |
| 7717 | |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 7718 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7719 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 7720 | synchronized (mWindowMap) { |
| 7721 | // The focus for the client is the window immediately below |
| 7722 | // where we would place the input method window. |
| 7723 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7724 | if (idx > 0) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7725 | // TODO(multidisplay): IMEs are only supported on the default display. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 7726 | WindowState imFocus = getDefaultWindowListLocked().get(idx-1); |
Dianne Hackborn | ac92087 | 2012-05-22 11:49:49 -0700 | [diff] [blame] | 7727 | if (DEBUG_INPUT_METHOD) { |
| 7728 | Slog.i(TAG, "Desired input method target: " + imFocus); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7729 | Slog.i(TAG, "Current focus: " + mCurrentFocus); |
| 7730 | Slog.i(TAG, "Last focus: " + mLastFocus); |
Dianne Hackborn | ac92087 | 2012-05-22 11:49:49 -0700 | [diff] [blame] | 7731 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7732 | if (imFocus != null) { |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 7733 | // This may be a starting window, in which case we still want |
| 7734 | // to count it as okay. |
| 7735 | if (imFocus.mAttrs.type == LayoutParams.TYPE_APPLICATION_STARTING |
| 7736 | && imFocus.mAppToken != null) { |
| 7737 | // The client has definitely started, so it really should |
| 7738 | // have a window in this app token. Let's look for it. |
| 7739 | for (int i=0; i<imFocus.mAppToken.windows.size(); i++) { |
| 7740 | WindowState w = imFocus.mAppToken.windows.get(i); |
| 7741 | if (w != imFocus) { |
Dianne Hackborn | ac92087 | 2012-05-22 11:49:49 -0700 | [diff] [blame] | 7742 | Log.i(TAG, "Switching to real app window: " + w); |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 7743 | imFocus = w; |
| 7744 | break; |
| 7745 | } |
| 7746 | } |
| 7747 | } |
Dianne Hackborn | ac92087 | 2012-05-22 11:49:49 -0700 | [diff] [blame] | 7748 | if (DEBUG_INPUT_METHOD) { |
| 7749 | Slog.i(TAG, "IM target client: " + imFocus.mSession.mClient); |
| 7750 | if (imFocus.mSession.mClient != null) { |
| 7751 | Slog.i(TAG, "IM target client binder: " |
| 7752 | + imFocus.mSession.mClient.asBinder()); |
| 7753 | Slog.i(TAG, "Requesting client binder: " + client.asBinder()); |
| 7754 | } |
| 7755 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7756 | if (imFocus.mSession.mClient != null && |
| 7757 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 7758 | return true; |
| 7759 | } |
| 7760 | } |
| 7761 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7762 | |
| 7763 | // Okay, how about this... what is the current focus? |
| 7764 | // It seems in some cases we may not have moved the IM |
| 7765 | // target window, such as when it was in a pop-up window, |
| 7766 | // so let's also look at the current focus. (An example: |
| 7767 | // go to Gmail, start searching so the keyboard goes up, |
| 7768 | // press home. Sometimes the IME won't go down.) |
| 7769 | // Would be nice to fix this more correctly, but it's |
| 7770 | // way at the end of a release, and this should be good enough. |
| 7771 | if (mCurrentFocus != null && mCurrentFocus.mSession.mClient != null |
| 7772 | && mCurrentFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 7773 | return true; |
| 7774 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7775 | } |
| 7776 | return false; |
| 7777 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7778 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7779 | public void getInitialDisplaySize(int displayId, Point size) { |
| 7780 | // TODO(cmautner): Access to DisplayContent should be locked on mWindowMap. Doing that |
| 7781 | // could lead to deadlock since this is called from ActivityManager. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 7782 | final DisplayContent displayContent = getDisplayContentLocked(displayId); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7783 | synchronized(displayContent.mDisplaySizeLock) { |
| 7784 | size.x = displayContent.mInitialDisplayWidth; |
| 7785 | size.y = displayContent.mInitialDisplayHeight; |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 7786 | } |
| 7787 | } |
| 7788 | |
Jeff Brown | 43aa159 | 2012-09-10 17:36:31 -0700 | [diff] [blame] | 7789 | public void setForcedDisplaySize(int displayId, int width, int height) { |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 7790 | synchronized(mWindowMap) { |
Jeff Brown | 43aa159 | 2012-09-10 17:36:31 -0700 | [diff] [blame] | 7791 | // Set some sort of reasonable bounds on the size of the display that we |
| 7792 | // will try to emulate. |
| 7793 | final int MIN_WIDTH = 200; |
| 7794 | final int MIN_HEIGHT = 200; |
| 7795 | final int MAX_SCALE = 2; |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 7796 | final DisplayContent displayContent = getDisplayContentLocked(displayId); |
Jeff Brown | 43aa159 | 2012-09-10 17:36:31 -0700 | [diff] [blame] | 7797 | |
| 7798 | width = Math.min(Math.max(width, MIN_WIDTH), |
| 7799 | displayContent.mInitialDisplayWidth * MAX_SCALE); |
| 7800 | height = Math.min(Math.max(height, MIN_HEIGHT), |
| 7801 | displayContent.mInitialDisplayHeight * MAX_SCALE); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7802 | setForcedDisplaySizeLocked(displayContent, width, height); |
Jeff Brown | 43aa159 | 2012-09-10 17:36:31 -0700 | [diff] [blame] | 7803 | Settings.Global.putString(mContext.getContentResolver(), |
| 7804 | Settings.Global.DISPLAY_SIZE_FORCED, width + "," + height); |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 7805 | } |
| 7806 | } |
| 7807 | |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7808 | private void readForcedDisplaySizeAndDensityLocked(final DisplayContent displayContent) { |
Jeff Brown | 43aa159 | 2012-09-10 17:36:31 -0700 | [diff] [blame] | 7809 | final String sizeStr = Settings.Global.getString(mContext.getContentResolver(), |
| 7810 | Settings.Global.DISPLAY_SIZE_FORCED); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7811 | if (sizeStr != null && sizeStr.length() > 0) { |
| 7812 | final int pos = sizeStr.indexOf(','); |
| 7813 | if (pos > 0 && sizeStr.lastIndexOf(',') == pos) { |
| 7814 | int width, height; |
| 7815 | try { |
| 7816 | width = Integer.parseInt(sizeStr.substring(0, pos)); |
| 7817 | height = Integer.parseInt(sizeStr.substring(pos+1)); |
| 7818 | synchronized(displayContent.mDisplaySizeLock) { |
| 7819 | if (displayContent.mBaseDisplayWidth != width |
| 7820 | || displayContent.mBaseDisplayHeight != height) { |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7821 | Slog.i(TAG, "FORCED DISPLAY SIZE: " + width + "x" + height); |
| 7822 | displayContent.mBaseDisplayWidth = width; |
| 7823 | displayContent.mBaseDisplayHeight = height; |
| 7824 | } |
| 7825 | } |
| 7826 | } catch (NumberFormatException ex) { |
| 7827 | } |
| 7828 | } |
Joe Onorato | 571ae90 | 2011-05-24 13:48:43 -0700 | [diff] [blame] | 7829 | } |
Jeff Brown | 43aa159 | 2012-09-10 17:36:31 -0700 | [diff] [blame] | 7830 | final String densityStr = Settings.Global.getString(mContext.getContentResolver(), |
| 7831 | Settings.Global.DISPLAY_DENSITY_FORCED); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7832 | if (densityStr != null && densityStr.length() > 0) { |
| 7833 | int density; |
| 7834 | try { |
| 7835 | density = Integer.parseInt(densityStr); |
| 7836 | synchronized(displayContent.mDisplaySizeLock) { |
| 7837 | if (displayContent.mBaseDisplayDensity != density) { |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7838 | Slog.i(TAG, "FORCED DISPLAY DENSITY: " + density); |
| 7839 | displayContent.mBaseDisplayDensity = density; |
| 7840 | } |
| 7841 | } |
| 7842 | } catch (NumberFormatException ex) { |
| 7843 | } |
Joe Onorato | 571ae90 | 2011-05-24 13:48:43 -0700 | [diff] [blame] | 7844 | } |
Joe Onorato | 571ae90 | 2011-05-24 13:48:43 -0700 | [diff] [blame] | 7845 | } |
| 7846 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7847 | private void setForcedDisplaySizeLocked(DisplayContent displayContent, int width, int height) { |
Joe Onorato | 571ae90 | 2011-05-24 13:48:43 -0700 | [diff] [blame] | 7848 | Slog.i(TAG, "Using new display size: " + width + "x" + height); |
| 7849 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7850 | synchronized(displayContent.mDisplaySizeLock) { |
| 7851 | displayContent.mBaseDisplayWidth = width; |
| 7852 | displayContent.mBaseDisplayHeight = height; |
Dianne Hackborn | 1fbee79 | 2011-11-30 11:29:58 -0800 | [diff] [blame] | 7853 | } |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7854 | reconfigureDisplayLocked(displayContent); |
| 7855 | } |
| 7856 | |
| 7857 | public void clearForcedDisplaySize(int displayId) { |
| 7858 | synchronized(mWindowMap) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 7859 | final DisplayContent displayContent = getDisplayContentLocked(displayId); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7860 | setForcedDisplaySizeLocked(displayContent, displayContent.mInitialDisplayWidth, |
| 7861 | displayContent.mInitialDisplayHeight); |
Jeff Brown | 43aa159 | 2012-09-10 17:36:31 -0700 | [diff] [blame] | 7862 | Settings.Global.putString(mContext.getContentResolver(), |
| 7863 | Settings.Global.DISPLAY_SIZE_FORCED, ""); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7864 | } |
| 7865 | } |
| 7866 | |
| 7867 | public void setForcedDisplayDensity(int displayId, int density) { |
| 7868 | synchronized(mWindowMap) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 7869 | final DisplayContent displayContent = getDisplayContentLocked(displayId); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7870 | setForcedDisplayDensityLocked(displayContent, density); |
Jeff Brown | 43aa159 | 2012-09-10 17:36:31 -0700 | [diff] [blame] | 7871 | Settings.Global.putString(mContext.getContentResolver(), |
| 7872 | Settings.Global.DISPLAY_DENSITY_FORCED, Integer.toString(density)); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7873 | } |
| 7874 | } |
| 7875 | |
| 7876 | private void setForcedDisplayDensityLocked(DisplayContent displayContent, int density) { |
| 7877 | Slog.i(TAG, "Using new display density: " + density); |
| 7878 | |
| 7879 | synchronized(displayContent.mDisplaySizeLock) { |
| 7880 | displayContent.mBaseDisplayDensity = density; |
| 7881 | } |
| 7882 | reconfigureDisplayLocked(displayContent); |
| 7883 | } |
| 7884 | |
| 7885 | public void clearForcedDisplayDensity(int displayId) { |
| 7886 | synchronized(mWindowMap) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 7887 | final DisplayContent displayContent = getDisplayContentLocked(displayId); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7888 | setForcedDisplayDensityLocked(displayContent, displayContent.mInitialDisplayDensity); |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 7889 | Settings.Global.putString(mContext.getContentResolver(), |
| 7890 | Settings.Global.DISPLAY_DENSITY_FORCED, ""); |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 7891 | } |
| 7892 | } |
| 7893 | |
| 7894 | private void reconfigureDisplayLocked(DisplayContent displayContent) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 7895 | // TODO: Multidisplay: for now only use with default display. |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 7896 | mPolicy.setInitialDisplaySize(displayContent.getDisplay(), |
| 7897 | displayContent.mBaseDisplayWidth, |
| 7898 | displayContent.mBaseDisplayHeight, |
| 7899 | displayContent.mBaseDisplayDensity); |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 7900 | |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 7901 | displayContent.layoutNeeded = true; |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 7902 | |
| 7903 | boolean configChanged = updateOrientationFromAppTokensLocked(false); |
| 7904 | mTempConfiguration.setToDefaults(); |
| 7905 | mTempConfiguration.fontScale = mCurConfiguration.fontScale; |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 7906 | if (computeScreenConfigurationLocked(mTempConfiguration)) { |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 7907 | if (mCurConfiguration.diff(mTempConfiguration) != 0) { |
| 7908 | configChanged = true; |
| 7909 | } |
| 7910 | } |
| 7911 | |
| 7912 | if (configChanged) { |
| 7913 | mWaitingForConfig = true; |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 7914 | startFreezingDisplayLocked(false, 0, 0); |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 7915 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 7916 | } |
| 7917 | |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 7918 | performLayoutAndPlaceSurfacesLocked(); |
| 7919 | } |
| 7920 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 7921 | public boolean hasSystemNavBar() { |
| 7922 | return mPolicy.hasSystemNavBar(); |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 7923 | } |
| 7924 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7925 | // ------------------------------------------------------------- |
| 7926 | // Internals |
| 7927 | // ------------------------------------------------------------- |
| 7928 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7929 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 7930 | boolean throwOnError) { |
| 7931 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7932 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7933 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7934 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 7935 | boolean throwOnError) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7936 | WindowState win = mWindowMap.get(client); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7937 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7938 | TAG, "Looking up client " + client + ": " + win); |
| 7939 | if (win == null) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7940 | RuntimeException ex = new IllegalArgumentException( |
| 7941 | "Requested window " + client + " does not exist"); |
| 7942 | if (throwOnError) { |
| 7943 | throw ex; |
| 7944 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7945 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7946 | return null; |
| 7947 | } |
| 7948 | if (session != null && win.mSession != session) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7949 | RuntimeException ex = new IllegalArgumentException( |
| 7950 | "Requested window " + client + " is in session " + |
| 7951 | win.mSession + ", not " + session); |
| 7952 | if (throwOnError) { |
| 7953 | throw ex; |
| 7954 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7955 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7956 | return null; |
| 7957 | } |
| 7958 | |
| 7959 | return win; |
| 7960 | } |
| 7961 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7962 | final void rebuildAppWindowListLocked() { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7963 | DisplayContentsIterator iterator = new DisplayContentsIterator(); |
| 7964 | while (iterator.hasNext()) { |
| 7965 | rebuildAppWindowListLocked(iterator.next()); |
| 7966 | } |
| 7967 | } |
| 7968 | |
| 7969 | private void rebuildAppWindowListLocked(final DisplayContent displayContent) { |
| 7970 | final WindowList windows = displayContent.getWindowList(); |
| 7971 | int NW = windows.size(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7972 | int i; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 7973 | int lastBelow = -1; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 7974 | int numRemoved = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7975 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7976 | if (mRebuildTmp.length < NW) { |
| 7977 | mRebuildTmp = new WindowState[NW+10]; |
| 7978 | } |
| 7979 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7980 | // First remove all existing app windows. |
| 7981 | i=0; |
| 7982 | while (i < NW) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7983 | WindowState w = windows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7984 | if (w.mAppToken != null) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 7985 | WindowState win = windows.remove(i); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7986 | win.mRebuilding = true; |
| 7987 | mRebuildTmp[numRemoved] = win; |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 7988 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7989 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 7990 | "Rebuild removing window: " + win); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7991 | NW--; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 7992 | numRemoved++; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7993 | continue; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 7994 | } else if (lastBelow == i-1) { |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 7995 | if (w.mAttrs.type == TYPE_WALLPAPER || w.mAttrs.type == TYPE_UNIVERSE_BACKGROUND) { |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 7996 | lastBelow = i; |
| 7997 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7998 | } |
| 7999 | i++; |
| 8000 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8001 | |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 8002 | // Keep whatever windows were below the app windows still below, |
| 8003 | // by skipping them. |
| 8004 | lastBelow++; |
| 8005 | i = lastBelow; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8006 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8007 | // First add all of the exiting app tokens... these are no longer |
| 8008 | // in the main app list, but still have windows shown. We put them |
| 8009 | // in the back because now that the animation is over we no longer |
| 8010 | // will care about them. |
| 8011 | int NT = mExitingAppTokens.size(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8012 | for (int j=0; j<NT; j++) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8013 | i = reAddAppWindowsLocked(displayContent, i, mExitingAppTokens.get(j)); |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8014 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8015 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8016 | // And add in the still active app tokens in Z order. |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 8017 | NT = mAnimatingAppTokens.size(); |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8018 | for (int j=0; j<NT; j++) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8019 | i = reAddAppWindowsLocked(displayContent, i, mAnimatingAppTokens.get(j)); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8020 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8021 | |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 8022 | i -= lastBelow; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8023 | if (i != numRemoved) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8024 | Slog.w(TAG, "Rebuild removed " + numRemoved |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8025 | + " windows but added " + i); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8026 | for (i=0; i<numRemoved; i++) { |
| 8027 | WindowState ws = mRebuildTmp[i]; |
| 8028 | if (ws.mRebuilding) { |
| 8029 | StringWriter sw = new StringWriter(); |
| 8030 | PrintWriter pw = new PrintWriter(sw); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 8031 | ws.dump(pw, "", true); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8032 | pw.flush(); |
| 8033 | Slog.w(TAG, "This window was lost: " + ws); |
| 8034 | Slog.w(TAG, sw.toString()); |
Craig Mautner | f20588f | 2012-04-11 17:06:21 -0700 | [diff] [blame] | 8035 | ws.mWinAnimator.destroySurfaceLocked(); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8036 | } |
| 8037 | } |
| 8038 | Slog.w(TAG, "Current app token list:"); |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 8039 | dumpAnimatingAppTokensLocked(); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8040 | Slog.w(TAG, "Final window list:"); |
| 8041 | dumpWindowsLocked(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8042 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8043 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8044 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8045 | private final void assignLayersLocked(WindowList windows) { |
| 8046 | int N = windows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8047 | int curBaseLayer = 0; |
| 8048 | int curLayer = 0; |
| 8049 | int i; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8050 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 8051 | if (DEBUG_LAYERS) { |
| 8052 | RuntimeException here = new RuntimeException("here"); |
| 8053 | here.fillInStackTrace(); |
Dianne Hackborn | 3ec891a | 2011-10-25 13:58:30 -0700 | [diff] [blame] | 8054 | Slog.v(TAG, "Assigning layers", here); |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 8055 | } |
| 8056 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8057 | for (i=0; i<N; i++) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8058 | final WindowState w = windows.get(i); |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 8059 | final WindowStateAnimator winAnimator = w.mWinAnimator; |
| 8060 | boolean layerChanged = false; |
| 8061 | int oldLayer = w.mLayer; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8062 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 8063 | || (i > 0 && w.mIsWallpaper)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8064 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 8065 | w.mLayer = curLayer; |
| 8066 | } else { |
| 8067 | curBaseLayer = curLayer = w.mBaseLayer; |
| 8068 | w.mLayer = curLayer; |
| 8069 | } |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 8070 | if (w.mLayer != oldLayer) { |
| 8071 | layerChanged = true; |
| 8072 | } |
| 8073 | oldLayer = winAnimator.mAnimLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8074 | if (w.mTargetAppToken != null) { |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 8075 | winAnimator.mAnimLayer = |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 8076 | w.mLayer + w.mTargetAppToken.mAppAnimator.animLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8077 | } else if (w.mAppToken != null) { |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 8078 | winAnimator.mAnimLayer = |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 8079 | w.mLayer + w.mAppToken.mAppAnimator.animLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8080 | } else { |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 8081 | winAnimator.mAnimLayer = w.mLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8082 | } |
| 8083 | if (w.mIsImWindow) { |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 8084 | winAnimator.mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8085 | } else if (w.mIsWallpaper) { |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 8086 | winAnimator.mAnimLayer += mWallpaperAnimLayerAdjustment; |
| 8087 | } |
| 8088 | if (winAnimator.mAnimLayer != oldLayer) { |
| 8089 | layerChanged = true; |
| 8090 | } |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 8091 | if (layerChanged && mAnimator.isDimmingLocked(winAnimator)) { |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 8092 | // Force an animation pass just to update the mDimAnimator layer. |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 8093 | updateLayoutToAnimationLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8094 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8095 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 8096 | + "mBase=" + w.mBaseLayer |
| 8097 | + " mLayer=" + w.mLayer |
| 8098 | + (w.mAppToken == null ? |
| 8099 | "" : " mAppLayer=" + w.mAppToken.mAppAnimator.animLayerAdjustment) |
| 8100 | + " =mAnimLayer=" + winAnimator.mAnimLayer); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8101 | //System.out.println( |
| 8102 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 8103 | } |
| 8104 | } |
| 8105 | |
| 8106 | private boolean mInLayout = false; |
| 8107 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 8108 | if (mInLayout) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 8109 | if (DEBUG) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8110 | throw new RuntimeException("Recursive call!"); |
| 8111 | } |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 8112 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout. Callers=" |
| 8113 | + Debug.getCallers(3)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8114 | return; |
| 8115 | } |
| 8116 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8117 | if (mWaitingForConfig) { |
| 8118 | // Our configuration has changed (most likely rotation), but we |
| 8119 | // don't yet have the complete configuration to report to |
| 8120 | // applications. Don't do any window layout until we have it. |
| 8121 | return; |
| 8122 | } |
| 8123 | |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 8124 | if (!mDisplayReady) { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8125 | // Not yet initialized, nothing to do. |
| 8126 | return; |
| 8127 | } |
| 8128 | |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 8129 | Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "wmLayout"); |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 8130 | mInLayout = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8131 | boolean recoveringMemory = false; |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 8132 | |
| 8133 | try { |
| 8134 | if (mForceRemoves != null) { |
| 8135 | recoveringMemory = true; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8136 | // 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] | 8137 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 8138 | WindowState ws = mForceRemoves.get(i); |
| 8139 | Slog.i(TAG, "Force removing: " + ws); |
| 8140 | removeWindowInnerLocked(ws.mSession, ws); |
| 8141 | } |
| 8142 | mForceRemoves = null; |
| 8143 | Slog.w(TAG, "Due to memory failure, waiting a bit for next layout"); |
| 8144 | Object tmp = new Object(); |
| 8145 | synchronized (tmp) { |
| 8146 | try { |
| 8147 | tmp.wait(250); |
| 8148 | } catch (InterruptedException e) { |
| 8149 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8150 | } |
| 8151 | } |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 8152 | } catch (RuntimeException e) { |
Dianne Hackborn | 8962028 | 2011-09-11 12:47:45 -0700 | [diff] [blame] | 8153 | Log.wtf(TAG, "Unhandled exception while force removing for memory", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8154 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8155 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8156 | try { |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8157 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 8158 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8159 | mInLayout = false; |
| 8160 | |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 8161 | if (needsLayout()) { |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 8162 | if (++mLayoutRepeatCount < 6) { |
| 8163 | requestTraversalLocked(); |
| 8164 | } else { |
| 8165 | Slog.e(TAG, "Performed 6 layouts in a row. Skipping"); |
| 8166 | mLayoutRepeatCount = 0; |
| 8167 | } |
| 8168 | } else { |
| 8169 | mLayoutRepeatCount = 0; |
| 8170 | } |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 8171 | |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8172 | if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) { |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8173 | mH.removeMessages(H.REPORT_WINDOWS_CHANGE); |
| 8174 | mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE)); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8175 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8176 | } catch (RuntimeException e) { |
| 8177 | mInLayout = false; |
Dianne Hackborn | 8962028 | 2011-09-11 12:47:45 -0700 | [diff] [blame] | 8178 | Log.wtf(TAG, "Unhandled exception while laying out windows", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8179 | } |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 8180 | |
| 8181 | Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8182 | } |
| 8183 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8184 | private final void performLayoutLockedInner(final DisplayContent displayContent, |
| 8185 | boolean initial, boolean updateInputWindows) { |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 8186 | if (!displayContent.layoutNeeded) { |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8187 | return; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8188 | } |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 8189 | displayContent.layoutNeeded = false; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8190 | WindowList windows = displayContent.getWindowList(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 8191 | boolean isDefaultDisplay = displayContent.isDefaultDisplay; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8192 | |
| 8193 | DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
| 8194 | final int dw = displayInfo.logicalWidth; |
| 8195 | final int dh = displayInfo.logicalHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8196 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 8197 | final int NFW = mFakeWindows.size(); |
| 8198 | for (int i=0; i<NFW; i++) { |
| 8199 | mFakeWindows.get(i).layout(dw, dh); |
| 8200 | } |
| 8201 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8202 | final int N = windows.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8203 | int i; |
| 8204 | |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 8205 | if (DEBUG_LAYOUT) { |
| 8206 | Slog.v(TAG, "-------------------------------------"); |
| 8207 | Slog.v(TAG, "performLayout: needed=" |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 8208 | + displayContent.layoutNeeded + " dw=" + dw + " dh=" + dh); |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 8209 | } |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 8210 | |
| 8211 | WindowStateAnimator universeBackground = null; |
| 8212 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 8213 | mPolicy.beginLayoutLw(isDefaultDisplay, dw, dh, mRotation); |
| 8214 | if (isDefaultDisplay) { |
| 8215 | // Not needed on non-default displays. |
| 8216 | mSystemDecorLayer = mPolicy.getSystemDecorRectLw(mSystemDecorRect); |
| 8217 | mScreenRect.set(0, 0, dw, dh); |
| 8218 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8219 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8220 | int seq = mLayoutSeq+1; |
| 8221 | if (seq < 0) seq = 0; |
| 8222 | mLayoutSeq = seq; |
| 8223 | |
| 8224 | // First perform layout of any root windows (not attached |
| 8225 | // to another window). |
| 8226 | int topAttached = -1; |
| 8227 | for (i = N-1; i >= 0; i--) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8228 | final WindowState win = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8229 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8230 | // Don't do layout of a window if it is not visible, or |
| 8231 | // soon won't be visible, to avoid wasting time and funky |
| 8232 | // changes while a window is animating away. |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 8233 | final boolean gone = win.isGoneForLayoutLw(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8234 | |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 8235 | if (DEBUG_LAYOUT && !win.mLayoutAttached) { |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 8236 | Slog.v(TAG, "1ST PASS " + win |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8237 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 8238 | + " mLayoutAttached=" + win.mLayoutAttached |
| 8239 | + " screen changed=" + win.isConfigDiff(ActivityInfo.CONFIG_SCREEN_SIZE)); |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 8240 | final AppWindowToken atoken = win.mAppToken; |
| 8241 | if (gone) Slog.v(TAG, " GONE: mViewVisibility=" |
| 8242 | + win.mViewVisibility + " mRelayoutCalled=" |
| 8243 | + win.mRelayoutCalled + " hidden=" |
| 8244 | + win.mRootToken.hidden + " hiddenRequested=" |
| 8245 | + (atoken != null && atoken.hiddenRequested) |
| 8246 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 8247 | else Slog.v(TAG, " VIS: mViewVisibility=" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8248 | + win.mViewVisibility + " mRelayoutCalled=" |
| 8249 | + win.mRelayoutCalled + " hidden=" |
| 8250 | + win.mRootToken.hidden + " hiddenRequested=" |
| 8251 | + (atoken != null && atoken.hiddenRequested) |
| 8252 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 8253 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 8254 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8255 | // If this view is GONE, then skip it -- keep the current |
| 8256 | // frame, and let the caller know so they can ignore it |
| 8257 | // if they want. (We do the normal layout for INVISIBLE |
| 8258 | // windows, since that means "perform layout as normal, |
| 8259 | // just don't display"). |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 8260 | if (!gone || !win.mHaveFrame || win.mLayoutNeeded |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 8261 | || win.isConfigDiff(ActivityInfo.CONFIG_SCREEN_SIZE) |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 8262 | || win.mAttrs.type == TYPE_UNIVERSE_BACKGROUND) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8263 | if (!win.mLayoutAttached) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 8264 | if (initial) { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 8265 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 8266 | win.mContentChanged = false; |
| 8267 | } |
Dianne Hackborn | b7ff51b | 2012-01-23 19:15:27 -0800 | [diff] [blame] | 8268 | win.mLayoutNeeded = false; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 8269 | win.prelayout(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8270 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 8271 | win.mLayoutSeq = seq; |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 8272 | if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8273 | + win.mFrame + " mContainingFrame=" |
| 8274 | + win.mContainingFrame + " mDisplayFrame=" |
| 8275 | + win.mDisplayFrame); |
| 8276 | } else { |
| 8277 | if (topAttached < 0) topAttached = i; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8278 | } |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 8279 | } |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 8280 | if (win.mViewVisibility == View.VISIBLE |
| 8281 | && win.mAttrs.type == TYPE_UNIVERSE_BACKGROUND |
| 8282 | && universeBackground == null) { |
| 8283 | universeBackground = win.mWinAnimator; |
| 8284 | } |
| 8285 | } |
| 8286 | |
| 8287 | if (mAnimator.mUniverseBackground != universeBackground) { |
| 8288 | mFocusMayChange = true; |
| 8289 | mAnimator.mUniverseBackground = universeBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8290 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8291 | |
| 8292 | // Now perform layout of attached windows, which usually |
| 8293 | // depend on the position of the window they are attached to. |
| 8294 | // XXX does not deal with windows that are attached to windows |
| 8295 | // that are themselves attached. |
| 8296 | for (i = topAttached; i >= 0; i--) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8297 | final WindowState win = windows.get(i); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8298 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8299 | if (win.mLayoutAttached) { |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 8300 | if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + win |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8301 | + " mHaveFrame=" + win.mHaveFrame |
| 8302 | + " mViewVisibility=" + win.mViewVisibility |
| 8303 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 8304 | // If this view is GONE, then skip it -- keep the current |
| 8305 | // frame, and let the caller know so they can ignore it |
| 8306 | // if they want. (We do the normal layout for INVISIBLE |
| 8307 | // windows, since that means "perform layout as normal, |
| 8308 | // just don't display"). |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8309 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
Dianne Hackborn | b7ff51b | 2012-01-23 19:15:27 -0800 | [diff] [blame] | 8310 | || !win.mHaveFrame || win.mLayoutNeeded) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 8311 | if (initial) { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 8312 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 8313 | win.mContentChanged = false; |
| 8314 | } |
Dianne Hackborn | b7ff51b | 2012-01-23 19:15:27 -0800 | [diff] [blame] | 8315 | win.mLayoutNeeded = false; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 8316 | win.prelayout(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8317 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 8318 | win.mLayoutSeq = seq; |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 8319 | if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8320 | + win.mFrame + " mContainingFrame=" |
| 8321 | + win.mContainingFrame + " mDisplayFrame=" |
| 8322 | + win.mDisplayFrame); |
| 8323 | } |
| 8324 | } |
| 8325 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8326 | |
| 8327 | // Window frames may have changed. Tell the input dispatcher about it. |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 8328 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 8329 | if (updateInputWindows) { |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 8330 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 8331 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8332 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8333 | mPolicy.finishLayoutLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8334 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8335 | |
Dianne Hackborn | 3ec891a | 2011-10-25 13:58:30 -0700 | [diff] [blame] | 8336 | void makeWindowFreezingScreenIfNeededLocked(WindowState w) { |
| 8337 | // If the screen is currently frozen or off, then keep |
| 8338 | // it frozen/off until this window draws at its new |
| 8339 | // orientation. |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 8340 | if (!okToDisplay()) { |
Dianne Hackborn | 3ec891a | 2011-10-25 13:58:30 -0700 | [diff] [blame] | 8341 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| 8342 | "Changing surface while display frozen: " + w); |
| 8343 | w.mOrientationChanging = true; |
Craig Mautner | 3255a28 | 2012-04-16 15:42:47 -0700 | [diff] [blame] | 8344 | mInnerFields.mOrientationChangeComplete = false; |
Dianne Hackborn | 3ec891a | 2011-10-25 13:58:30 -0700 | [diff] [blame] | 8345 | if (!mWindowsFreezingScreen) { |
| 8346 | mWindowsFreezingScreen = true; |
| 8347 | // XXX should probably keep timeout from |
| 8348 | // when we first froze the display. |
| 8349 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 8350 | mH.sendMessageDelayed(mH.obtainMessage( |
| 8351 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 8352 | } |
| 8353 | } |
| 8354 | } |
| 8355 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8356 | /** |
| 8357 | * Extracted from {@link #performLayoutAndPlaceSurfacesLockedInner} to reduce size of method. |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 8358 | * @param windows List of windows on default display. |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8359 | * @return bitmap indicating if another pass through layout must be made. |
| 8360 | */ |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8361 | public int handleAppTransitionReadyLocked(WindowList windows) { |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8362 | int changes = 0; |
| 8363 | int i; |
| 8364 | int NN = mOpeningApps.size(); |
| 8365 | boolean goodToGo = true; |
| 8366 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| 8367 | "Checking " + NN + " opening apps (frozen=" |
| 8368 | + mDisplayFrozen + " timeout=" |
| 8369 | + mAppTransitionTimeout + ")..."); |
| 8370 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 8371 | // If the display isn't frozen, wait to do anything until |
| 8372 | // all of the apps are ready. Otherwise just go because |
| 8373 | // we'll unfreeze the display when everyone is ready. |
| 8374 | for (i=0; i<NN && goodToGo; i++) { |
| 8375 | AppWindowToken wtoken = mOpeningApps.get(i); |
| 8376 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Craig Mautner | 1d961d4 | 2012-05-27 12:02:11 -0700 | [diff] [blame] | 8377 | "Check opening app=" + wtoken + ": allDrawn=" |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8378 | + wtoken.allDrawn + " startingDisplayed=" |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 8379 | + wtoken.startingDisplayed + " startingMoved=" |
| 8380 | + wtoken.startingMoved); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8381 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 8382 | && !wtoken.startingMoved) { |
| 8383 | goodToGo = false; |
| 8384 | } |
| 8385 | } |
| 8386 | } |
| 8387 | if (goodToGo) { |
| 8388 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO"); |
| 8389 | int transit = mNextAppTransition; |
| 8390 | if (mSkipAppTransitionAnimation) { |
| 8391 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
| 8392 | } |
| 8393 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| 8394 | mAppTransitionReady = false; |
| 8395 | mAppTransitionRunning = true; |
| 8396 | mAppTransitionTimeout = false; |
| 8397 | mStartingIconInTransition = false; |
| 8398 | mSkipAppTransitionAnimation = false; |
| 8399 | |
| 8400 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 8401 | |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 8402 | rebuildAppWindowListLocked(); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8403 | |
Craig Mautner | 0afddcb | 2012-05-08 15:38:00 -0700 | [diff] [blame] | 8404 | // if wallpaper is animating in or out set oldWallpaper to null else to wallpaper |
Craig Mautner | 83339b4 | 2012-05-01 22:13:23 -0700 | [diff] [blame] | 8405 | WindowState oldWallpaper = |
| 8406 | mWallpaperTarget != null && mWallpaperTarget.mWinAnimator.isAnimating() |
Craig Mautner | 0afddcb | 2012-05-08 15:38:00 -0700 | [diff] [blame] | 8407 | && !mWallpaperTarget.mWinAnimator.isDummyAnimation() |
Craig Mautner | 83339b4 | 2012-05-01 22:13:23 -0700 | [diff] [blame] | 8408 | ? null : mWallpaperTarget; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8409 | |
| 8410 | adjustWallpaperWindowsLocked(); |
| 8411 | mInnerFields.mWallpaperMayChange = false; |
| 8412 | |
| 8413 | // The top-most window will supply the layout params, |
| 8414 | // and we will determine it below. |
| 8415 | LayoutParams animLp = null; |
| 8416 | int bestAnimLayer = -1; |
| 8417 | boolean fullscreenAnim = false; |
| 8418 | |
| 8419 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| 8420 | "New wallpaper target=" + mWallpaperTarget |
Daniel Sandler | ab886f5 | 2012-06-04 14:36:25 -0400 | [diff] [blame] | 8421 | + ", oldWallpaper=" + oldWallpaper |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8422 | + ", lower target=" + mLowerWallpaperTarget |
| 8423 | + ", upper target=" + mUpperWallpaperTarget); |
| 8424 | int foundWallpapers = 0; |
| 8425 | // Do a first pass through the tokens for two |
| 8426 | // things: |
| 8427 | // (1) Determine if both the closing and opening |
| 8428 | // app token sets are wallpaper targets, in which |
| 8429 | // case special animations are needed |
| 8430 | // (since the wallpaper needs to stay static |
| 8431 | // behind them). |
| 8432 | // (2) Find the layout params of the top-most |
| 8433 | // application window in the tokens, which is |
| 8434 | // what will control the animation theme. |
| 8435 | final int NC = mClosingApps.size(); |
| 8436 | NN = NC + mOpeningApps.size(); |
| 8437 | for (i=0; i<NN; i++) { |
| 8438 | AppWindowToken wtoken; |
| 8439 | int mode; |
| 8440 | if (i < NC) { |
| 8441 | wtoken = mClosingApps.get(i); |
| 8442 | mode = 1; |
| 8443 | } else { |
| 8444 | wtoken = mOpeningApps.get(i-NC); |
| 8445 | mode = 2; |
| 8446 | } |
| 8447 | if (mLowerWallpaperTarget != null) { |
| 8448 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 8449 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 8450 | foundWallpapers |= mode; |
| 8451 | } |
| 8452 | } |
| 8453 | if (wtoken.appFullscreen) { |
| 8454 | WindowState ws = wtoken.findMainWindow(); |
| 8455 | if (ws != null) { |
| 8456 | animLp = ws.mAttrs; |
| 8457 | bestAnimLayer = ws.mLayer; |
| 8458 | fullscreenAnim = true; |
| 8459 | } |
| 8460 | } else if (!fullscreenAnim) { |
| 8461 | WindowState ws = wtoken.findMainWindow(); |
| 8462 | if (ws != null) { |
| 8463 | if (ws.mLayer > bestAnimLayer) { |
| 8464 | animLp = ws.mAttrs; |
| 8465 | bestAnimLayer = ws.mLayer; |
| 8466 | } |
| 8467 | } |
| 8468 | } |
| 8469 | } |
| 8470 | |
| 8471 | if (foundWallpapers == 3) { |
| 8472 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| 8473 | "Wallpaper animation!"); |
| 8474 | switch (transit) { |
| 8475 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 8476 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 8477 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 8478 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 8479 | break; |
| 8480 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 8481 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 8482 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 8483 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 8484 | break; |
| 8485 | } |
| 8486 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| 8487 | "New transit: " + transit); |
Daniel Sandler | ab886f5 | 2012-06-04 14:36:25 -0400 | [diff] [blame] | 8488 | } else if ((oldWallpaper != null) && !mOpeningApps.contains(oldWallpaper.mAppToken)) { |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8489 | // We are transitioning from an activity with |
| 8490 | // a wallpaper to one without. |
| 8491 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
| 8492 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| 8493 | "New transit away from wallpaper: " + transit); |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 8494 | } else if (mWallpaperTarget != null && mWallpaperTarget.isVisibleLw()) { |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8495 | // We are transitioning from an activity without |
| 8496 | // a wallpaper to now showing the wallpaper |
| 8497 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
| 8498 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| 8499 | "New transit into wallpaper: " + transit); |
| 8500 | } |
| 8501 | |
| 8502 | // If all closing windows are obscured, then there is |
| 8503 | // no need to do an animation. This is the case, for |
| 8504 | // example, when this transition is being done behind |
| 8505 | // the lock screen. |
| 8506 | if (!mPolicy.allowAppAnimationsLw()) { |
| 8507 | animLp = null; |
| 8508 | } |
| 8509 | |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8510 | AppWindowToken topOpeningApp = null; |
| 8511 | int topOpeningLayer = 0; |
| 8512 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8513 | NN = mOpeningApps.size(); |
| 8514 | for (i=0; i<NN; i++) { |
| 8515 | AppWindowToken wtoken = mOpeningApps.get(i); |
Craig Mautner | bea12bd | 2012-08-20 10:18:34 -0700 | [diff] [blame] | 8516 | final AppWindowAnimator appAnimator = wtoken.mAppAnimator; |
Craig Mautner | bec53f7 | 2012-04-05 11:49:05 -0700 | [diff] [blame] | 8517 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Now opening app" + wtoken); |
Craig Mautner | bea12bd | 2012-08-20 10:18:34 -0700 | [diff] [blame] | 8518 | appAnimator.clearThumbnail(); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8519 | wtoken.reportedVisible = false; |
| 8520 | wtoken.inPendingTransaction = false; |
Craig Mautner | bea12bd | 2012-08-20 10:18:34 -0700 | [diff] [blame] | 8521 | appAnimator.animation = null; |
Craig Mautner | bec53f7 | 2012-04-05 11:49:05 -0700 | [diff] [blame] | 8522 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8523 | wtoken.updateReportedVisibilityLocked(); |
| 8524 | wtoken.waitingToShow = false; |
Craig Mautner | bea12bd | 2012-08-20 10:18:34 -0700 | [diff] [blame] | 8525 | |
| 8526 | appAnimator.mAllAppWinAnimators.clear(); |
| 8527 | final int N = wtoken.allAppWindows.size(); |
| 8528 | for (int j = 0; j < N; j++) { |
| 8529 | appAnimator.mAllAppWinAnimators.add(wtoken.allAppWindows.get(j).mWinAnimator); |
| 8530 | } |
| 8531 | mAnimator.mAnimating |= appAnimator.showAllWindowsLocked(); |
| 8532 | |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8533 | if (animLp != null) { |
| 8534 | int layer = -1; |
| 8535 | for (int j=0; j<wtoken.windows.size(); j++) { |
| 8536 | WindowState win = wtoken.windows.get(j); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 8537 | if (win.mWinAnimator.mAnimLayer > layer) { |
| 8538 | layer = win.mWinAnimator.mAnimLayer; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8539 | } |
| 8540 | } |
| 8541 | if (topOpeningApp == null || layer > topOpeningLayer) { |
| 8542 | topOpeningApp = wtoken; |
| 8543 | topOpeningLayer = layer; |
| 8544 | } |
| 8545 | } |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8546 | } |
| 8547 | NN = mClosingApps.size(); |
| 8548 | for (i=0; i<NN; i++) { |
| 8549 | AppWindowToken wtoken = mClosingApps.get(i); |
| 8550 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 8551 | "Now closing app " + wtoken); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 8552 | wtoken.mAppAnimator.clearThumbnail(); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8553 | wtoken.inPendingTransaction = false; |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 8554 | wtoken.mAppAnimator.animation = null; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8555 | setTokenVisibilityLocked(wtoken, animLp, false, |
| 8556 | transit, false); |
| 8557 | wtoken.updateReportedVisibilityLocked(); |
| 8558 | wtoken.waitingToHide = false; |
| 8559 | // Force the allDrawn flag, because we want to start |
| 8560 | // this guy's animations regardless of whether it's |
| 8561 | // gotten drawn. |
| 8562 | wtoken.allDrawn = true; |
| 8563 | } |
| 8564 | |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8565 | if (mNextAppTransitionThumbnail != null && topOpeningApp != null |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 8566 | && topOpeningApp.mAppAnimator.animation != null) { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8567 | // This thumbnail animation is very special, we need to have |
| 8568 | // an extra surface with the thumbnail included with the animation. |
| 8569 | Rect dirty = new Rect(0, 0, mNextAppTransitionThumbnail.getWidth(), |
| 8570 | mNextAppTransitionThumbnail.getHeight()); |
| 8571 | try { |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 8572 | // TODO(multi-display): support other displays |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 8573 | final DisplayContent displayContent = getDefaultDisplayContentLocked(); |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 8574 | final Display display = displayContent.getDisplay(); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 8575 | Surface surface = new Surface(mFxSession, |
| 8576 | "thumbnail anim", |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 8577 | dirty.width(), dirty.height(), |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8578 | PixelFormat.TRANSLUCENT, Surface.HIDDEN); |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 8579 | surface.setLayerStack(display.getLayerStack()); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 8580 | topOpeningApp.mAppAnimator.thumbnail = surface; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8581 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " THUMBNAIL " |
| 8582 | + surface + ": CREATE"); |
| 8583 | Surface drawSurface = new Surface(); |
| 8584 | drawSurface.copyFrom(surface); |
| 8585 | Canvas c = drawSurface.lockCanvas(dirty); |
| 8586 | c.drawBitmap(mNextAppTransitionThumbnail, 0, 0, null); |
| 8587 | drawSurface.unlockCanvasAndPost(c); |
| 8588 | drawSurface.release(); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 8589 | topOpeningApp.mAppAnimator.thumbnailLayer = topOpeningLayer; |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 8590 | Animation anim = createThumbnailAnimationLocked( |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 8591 | transit, true, true, mNextAppTransitionScaleUp); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 8592 | topOpeningApp.mAppAnimator.thumbnailAnimation = anim; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8593 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 8594 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 8595 | topOpeningApp.mAppAnimator.thumbnailX = mNextAppTransitionStartX; |
| 8596 | topOpeningApp.mAppAnimator.thumbnailY = mNextAppTransitionStartY; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8597 | } catch (Surface.OutOfResourcesException e) { |
| 8598 | Slog.e(TAG, "Can't allocate thumbnail surface w=" + dirty.width() |
| 8599 | + " h=" + dirty.height(), e); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 8600 | topOpeningApp.mAppAnimator.clearThumbnail(); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8601 | } |
| 8602 | } |
| 8603 | |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 8604 | mNextAppTransitionType = ActivityOptions.ANIM_NONE; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8605 | mNextAppTransitionPackage = null; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 8606 | mNextAppTransitionThumbnail = null; |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 8607 | scheduleAnimationCallback(mNextAppTransitionCallback); |
| 8608 | mNextAppTransitionCallback = null; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8609 | |
| 8610 | mOpeningApps.clear(); |
| 8611 | mClosingApps.clear(); |
| 8612 | |
| 8613 | // This has changed the visibility of windows, so perform |
| 8614 | // a new layout to get them all up-to-date. |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 8615 | changes |= WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8616 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG; |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 8617 | getDefaultDisplayContentLocked().layoutNeeded = true; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8618 | |
| 8619 | // TODO(multidisplay): IMEs are only supported on the default display. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 8620 | if (windows == getDefaultWindowListLocked() |
| 8621 | && !moveInputMethodWindowsIfNeededLocked(true)) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8622 | assignLayersLocked(windows); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8623 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8624 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, false /*updateInputWindows*/); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8625 | mFocusMayChange = false; |
| 8626 | } |
| 8627 | |
| 8628 | return changes; |
| 8629 | } |
| 8630 | |
| 8631 | /** |
| 8632 | * Extracted from {@link #performLayoutAndPlaceSurfacesLockedInner} to reduce size of method. |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8633 | * @return bitmap indicating if another pass through layout must be made. |
| 8634 | */ |
Craig Mautner | 2f995a7 | 2012-02-21 09:53:21 -0800 | [diff] [blame] | 8635 | private int handleAnimatingStoppedAndTransitionLocked() { |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8636 | int changes = 0; |
| 8637 | |
| 8638 | mAppTransitionRunning = false; |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 8639 | // Restore window app tokens to the ActivityManager views |
Craig Mautner | 3f99fde | 2012-06-19 14:10:01 -0700 | [diff] [blame] | 8640 | for (int i = mAnimatingAppTokens.size() - 1; i >= 0; i--) { |
| 8641 | mAnimatingAppTokens.get(i).sendingToBottom = false; |
| 8642 | } |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 8643 | mAnimatingAppTokens.clear(); |
| 8644 | mAnimatingAppTokens.addAll(mAppTokens); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8645 | rebuildAppWindowListLocked(); |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 8646 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8647 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| 8648 | mInnerFields.mAdjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 8649 | moveInputMethodWindowsIfNeededLocked(true); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8650 | mInnerFields.mWallpaperMayChange = true; |
| 8651 | // Since the window list has been rebuilt, focus might |
| 8652 | // have to be recomputed since the actual order of windows |
| 8653 | // might have changed again. |
| 8654 | mFocusMayChange = true; |
| 8655 | |
| 8656 | return changes; |
| 8657 | } |
| 8658 | |
| 8659 | /** |
| 8660 | * Extracted from {@link #performLayoutAndPlaceSurfacesLockedInner} to reduce size of method. |
| 8661 | * |
| 8662 | * @return bitmap indicating if another pass through layout must be made. |
| 8663 | */ |
| 8664 | private int animateAwayWallpaperLocked() { |
| 8665 | int changes = 0; |
| 8666 | WindowState oldWallpaper = mWallpaperTarget; |
| 8667 | if (mLowerWallpaperTarget != null |
| 8668 | && mLowerWallpaperTarget.mAppToken != null) { |
| 8669 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 8670 | "wallpaperForceHiding changed with lower=" |
| 8671 | + mLowerWallpaperTarget); |
| 8672 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 8673 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 8674 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 8675 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 8676 | // The lower target has become hidden before we |
| 8677 | // actually started the animation... let's completely |
| 8678 | // re-evaluate everything. |
| 8679 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
| 8680 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| 8681 | } |
| 8682 | } |
| 8683 | mInnerFields.mAdjResult |= adjustWallpaperWindowsLocked(); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8684 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
| 8685 | + " NEW: " + mWallpaperTarget |
| 8686 | + " LOWER: " + mLowerWallpaperTarget); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8687 | return changes; |
| 8688 | } |
| 8689 | |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8690 | private void updateResizingWindows(final WindowState w) { |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 8691 | final WindowStateAnimator winAnimator = w.mWinAnimator; |
Craig Mautner | 1efacf7 | 2012-04-27 12:58:21 -0700 | [diff] [blame] | 8692 | if (w.mHasSurface && !w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8693 | w.mContentInsetsChanged |= |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 8694 | !w.mLastContentInsets.equals(w.mContentInsets); |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8695 | w.mVisibleInsetsChanged |= |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 8696 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 8697 | boolean configChanged = w.isConfigChanged(); |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8698 | if (DEBUG_CONFIGURATION && configChanged) { |
| 8699 | Slog.v(TAG, "Win " + w + " config changed: " |
| 8700 | + mCurConfiguration); |
| 8701 | } |
| 8702 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
| 8703 | + ": configChanged=" + configChanged |
| 8704 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
| 8705 | w.mLastFrame.set(w.mFrame); |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 8706 | if (w.mContentInsetsChanged |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8707 | || w.mVisibleInsetsChanged |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 8708 | || winAnimator.mSurfaceResized |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8709 | || configChanged) { |
| 8710 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) { |
| 8711 | Slog.v(TAG, "Resize reasons: " |
| 8712 | + " contentInsetsChanged=" + w.mContentInsetsChanged |
| 8713 | + " visibleInsetsChanged=" + w.mVisibleInsetsChanged |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 8714 | + " surfaceResized=" + winAnimator.mSurfaceResized |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8715 | + " configChanged=" + configChanged); |
| 8716 | } |
| 8717 | |
| 8718 | w.mLastContentInsets.set(w.mContentInsets); |
| 8719 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
| 8720 | makeWindowFreezingScreenIfNeededLocked(w); |
| 8721 | // If the orientation is changing, then we need to |
| 8722 | // hold off on unfreezing the display until this |
| 8723 | // window has been redrawn; to do that, we need |
| 8724 | // to go through the process of getting informed |
| 8725 | // by the application when it has finished drawing. |
| 8726 | if (w.mOrientationChanging) { |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 8727 | if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || DEBUG_ORIENTATION) Slog.v(TAG, |
Craig Mautner | 83339b4 | 2012-05-01 22:13:23 -0700 | [diff] [blame] | 8728 | "Orientation start waiting for draw mDrawState=DRAW_PENDING in " |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 8729 | + w + ", surface " + winAnimator.mSurface); |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 8730 | winAnimator.mDrawState = WindowStateAnimator.DRAW_PENDING; |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8731 | if (w.mAppToken != null) { |
| 8732 | w.mAppToken.allDrawn = false; |
| 8733 | } |
| 8734 | } |
| 8735 | if (!mResizingWindows.contains(w)) { |
| 8736 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 8737 | "Resizing window " + w + " to " + winAnimator.mSurfaceW |
| 8738 | + "x" + winAnimator.mSurfaceH); |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8739 | mResizingWindows.add(w); |
| 8740 | } |
| 8741 | } else if (w.mOrientationChanging) { |
Craig Mautner | bf90eaa | 2012-03-15 11:28:53 -0700 | [diff] [blame] | 8742 | if (w.isDrawnLw()) { |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8743 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| 8744 | "Orientation not waiting for draw in " |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 8745 | + w + ", surface " + winAnimator.mSurface); |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 8746 | w.mOrientationChanging = false; |
| 8747 | } |
| 8748 | } |
| 8749 | } |
| 8750 | } |
| 8751 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8752 | /** |
| 8753 | * Extracted from {@link #performLayoutAndPlaceSurfacesLockedInner} to reduce size of method. |
| 8754 | * |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8755 | * @param w WindowState this method is applied to. |
| 8756 | * @param currentTime The time which animations use for calculating transitions. |
| 8757 | * @param innerDw Width of app window. |
| 8758 | * @param innerDh Height of app window. |
| 8759 | */ |
| 8760 | private void handleNotObscuredLocked(final WindowState w, final long currentTime, |
| 8761 | final int innerDw, final int innerDh) { |
| 8762 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 8763 | final int attrFlags = attrs.flags; |
| 8764 | final boolean canBeSeen = w.isDisplayedLw(); |
| 8765 | |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 8766 | if (w.mHasSurface) { |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8767 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 8768 | mInnerFields.mHoldScreen = w.mSession; |
| 8769 | } |
| 8770 | if (!mInnerFields.mSyswin && w.mAttrs.screenBrightness >= 0 |
| 8771 | && mInnerFields.mScreenBrightness < 0) { |
| 8772 | mInnerFields.mScreenBrightness = w.mAttrs.screenBrightness; |
| 8773 | } |
| 8774 | if (!mInnerFields.mSyswin && w.mAttrs.buttonBrightness >= 0 |
| 8775 | && mInnerFields.mButtonBrightness < 0) { |
| 8776 | mInnerFields.mButtonBrightness = w.mAttrs.buttonBrightness; |
| 8777 | } |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 8778 | final int type = attrs.type; |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8779 | if (canBeSeen |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 8780 | && (type == TYPE_SYSTEM_DIALOG |
| 8781 | || type == TYPE_KEYGUARD |
| 8782 | || type == TYPE_SYSTEM_ERROR)) { |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8783 | mInnerFields.mSyswin = true; |
| 8784 | } |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 8785 | |
| 8786 | if (canBeSeen) { |
| 8787 | if (type == TYPE_DREAM || type == TYPE_KEYGUARD) { |
| 8788 | mInnerFields.mDisplayHasContent = LayoutFields.DISPLAY_CONTENT_MIRROR; |
| 8789 | } else if (mInnerFields.mDisplayHasContent |
| 8790 | == LayoutFields.DISPLAY_CONTENT_UNKNOWN) { |
| 8791 | mInnerFields.mDisplayHasContent = LayoutFields.DISPLAY_CONTENT_UNIQUE; |
| 8792 | } |
| 8793 | } |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8794 | } |
| 8795 | |
| 8796 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 8797 | if (opaqueDrawn && w.isFullscreen(innerDw, innerDh)) { |
| 8798 | // This window completely covers everything behind it, |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 8799 | // so we want to leave all of them as undimmed (for |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8800 | // performance reasons). |
| 8801 | mInnerFields.mObscured = true; |
Craig Mautner | 35af2ff | 2012-04-24 14:30:15 -0700 | [diff] [blame] | 8802 | } else if (canBeSeen && (attrFlags & FLAG_DIM_BEHIND) != 0 |
Craig Mautner | 236a35b | 2012-06-08 09:54:59 -0700 | [diff] [blame] | 8803 | && !(w.mAppToken != null && w.mAppToken.hiddenRequested) |
| 8804 | && !w.mExiting) { |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 8805 | if (localLOGV) Slog.v(TAG, "Win " + w + " obscured=" + mInnerFields.mObscured); |
| 8806 | if (!mInnerFields.mDimming) { |
| 8807 | //Slog.i(TAG, "DIM BEHIND: " + w); |
| 8808 | mInnerFields.mDimming = true; |
Craig Mautner | acafd19 | 2012-05-10 10:41:02 -0700 | [diff] [blame] | 8809 | final WindowStateAnimator winAnimator = w.mWinAnimator; |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 8810 | if (!mAnimator.isDimmingLocked(winAnimator)) { |
Craig Mautner | f8d4fbb | 2012-04-11 09:25:53 -0700 | [diff] [blame] | 8811 | final int width, height; |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 8812 | if (attrs.type == TYPE_BOOT_PROGRESS) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 8813 | final DisplayInfo displayInfo = w.mDisplayContent.getDisplayInfo(); |
| 8814 | width = displayInfo.logicalWidth; |
| 8815 | height = displayInfo.logicalHeight; |
Craig Mautner | f8d4fbb | 2012-04-11 09:25:53 -0700 | [diff] [blame] | 8816 | } else { |
| 8817 | width = innerDw; |
| 8818 | height = innerDh; |
| 8819 | } |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 8820 | startDimmingLocked( |
| 8821 | winAnimator, w.mExiting ? 0 : w.mAttrs.dimAmount, width, height); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8822 | } |
| 8823 | } |
| 8824 | } |
| 8825 | } |
| 8826 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 8827 | private void updateAllDrawnLocked() { |
| 8828 | // See if any windows have been drawn, so they (and others |
| 8829 | // associated with them) can now be shown. |
| 8830 | final ArrayList<AppWindowToken> appTokens = mAnimatingAppTokens; |
| 8831 | final int NT = appTokens.size(); |
| 8832 | for (int i=0; i<NT; i++) { |
| 8833 | AppWindowToken wtoken = appTokens.get(i); |
| 8834 | if (!wtoken.allDrawn) { |
| 8835 | int numInteresting = wtoken.numInterestingWindows; |
| 8836 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| 8837 | if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG, |
| 8838 | "allDrawn: " + wtoken |
| 8839 | + " interesting=" + numInteresting |
| 8840 | + " drawn=" + wtoken.numDrawnWindows); |
| 8841 | wtoken.allDrawn = true; |
| 8842 | } |
| 8843 | } |
| 8844 | } |
| 8845 | } |
| 8846 | |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 8847 | // "Something has changed! Let's make it correct now." |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8848 | private final void performLayoutAndPlaceSurfacesLockedInner(boolean recoveringMemory) { |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 8849 | if (DEBUG_WINDOW_TRACE) { |
Craig Mautner | 3255a28 | 2012-04-16 15:42:47 -0700 | [diff] [blame] | 8850 | Slog.v(TAG, "performLayoutAndPlaceSurfacesLockedInner: entry. Called by " |
Craig Mautner | a51a956 | 2012-04-17 17:05:26 -0700 | [diff] [blame] | 8851 | + Debug.getCallers(3)); |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 8852 | } |
Joe Onorato | 34bcebc | 2010-07-07 18:05:01 -0400 | [diff] [blame] | 8853 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8854 | final long currentTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 8855 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8856 | int i; |
| 8857 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8858 | if (mFocusMayChange) { |
| 8859 | mFocusMayChange = false; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 8860 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 8861 | false /*updateInputWindows*/); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8862 | } |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 8863 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8864 | // Initialize state of exiting tokens. |
| 8865 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 8866 | mExitingTokens.get(i).hasVisible = false; |
| 8867 | } |
| 8868 | |
| 8869 | // Initialize state of exiting applications. |
| 8870 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 8871 | mExitingAppTokens.get(i).hasVisible = false; |
| 8872 | } |
| 8873 | |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 8874 | mInnerFields.mHoldScreen = null; |
| 8875 | mInnerFields.mScreenBrightness = -1; |
| 8876 | mInnerFields.mButtonBrightness = -1; |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 8877 | mInnerFields.mDisplayHasContent = LayoutFields.DISPLAY_CONTENT_UNKNOWN; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 8878 | mTransactionSequence++; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 8879 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 8880 | final DisplayContent defaultDisplay = getDefaultDisplayContentLocked(); |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8881 | final DisplayInfo defaultInfo = defaultDisplay.getDisplayInfo(); |
| 8882 | final int defaultDw = defaultInfo.logicalWidth; |
| 8883 | final int defaultDh = defaultInfo.logicalHeight; |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8884 | |
Dianne Hackborn | 3699174 | 2011-10-11 21:35:26 -0700 | [diff] [blame] | 8885 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
| 8886 | ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8887 | Surface.openTransaction(); |
| 8888 | try { |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8889 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 8890 | if (mWatermark != null) { |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8891 | mWatermark.positionSurface(defaultDw, defaultDh); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 8892 | } |
| 8893 | if (mStrictModeFlash != null) { |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8894 | mStrictModeFlash.positionSurface(defaultDw, defaultDh); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 8895 | } |
| 8896 | |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 8897 | boolean focusDisplayed = false; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 8898 | boolean updateAllDrawn = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8899 | |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8900 | DisplayContentsIterator iterator = new DisplayContentsIterator(); |
| 8901 | while (iterator.hasNext()) { |
| 8902 | final DisplayContent displayContent = iterator.next(); |
| 8903 | WindowList windows = displayContent.getWindowList(); |
| 8904 | DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 8905 | final int displayId = displayContent.getDisplayId(); |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8906 | final int dw = displayInfo.logicalWidth; |
| 8907 | final int dh = displayInfo.logicalHeight; |
| 8908 | final int innerDw = displayInfo.appWidth; |
| 8909 | final int innerDh = displayInfo.appHeight; |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 8910 | final boolean isDefaultDisplay = (displayId == Display.DEFAULT_DISPLAY); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8911 | |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 8912 | // Reset for each display unless we are forcing mirroring. |
| 8913 | if (mInnerFields.mDisplayHasContent != LayoutFields.DISPLAY_CONTENT_MIRROR) { |
| 8914 | mInnerFields.mDisplayHasContent = LayoutFields.DISPLAY_CONTENT_UNKNOWN; |
| 8915 | } |
| 8916 | |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8917 | int repeats = 0; |
| 8918 | do { |
| 8919 | repeats++; |
| 8920 | if (repeats > 6) { |
| 8921 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8922 | displayContent.layoutNeeded = false; |
| 8923 | break; |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 8924 | } |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 8925 | |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8926 | if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("On entry to LockedInner", |
| 8927 | displayContent.pendingLayoutChanges); |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 8928 | |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8929 | if (isDefaultDisplay && ((displayContent.pendingLayoutChanges |
| 8930 | & WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) |
| 8931 | && ((adjustWallpaperWindowsLocked() |
| 8932 | & ADJUST_WALLPAPER_LAYERS_CHANGED) != 0)) { |
| 8933 | assignLayersLocked(windows); |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8934 | displayContent.layoutNeeded = true; |
| 8935 | } |
| 8936 | |
| 8937 | if (isDefaultDisplay && (displayContent.pendingLayoutChanges |
| 8938 | & WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 8939 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
| 8940 | if (updateOrientationFromAppTokensLocked(true)) { |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8941 | displayContent.layoutNeeded = true; |
| 8942 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 8943 | } |
| 8944 | } |
| 8945 | |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8946 | if ((displayContent.pendingLayoutChanges |
| 8947 | & WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8948 | displayContent.layoutNeeded = true; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 8949 | } |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8950 | |
| 8951 | // FIRST LOOP: Perform a layout, if needed. |
| 8952 | if (repeats < 4) { |
| 8953 | performLayoutLockedInner(displayContent, repeats == 1, |
| 8954 | false /*updateInputWindows*/); |
| 8955 | } else { |
| 8956 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 8957 | } |
| 8958 | |
| 8959 | // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think |
| 8960 | // it is animating. |
| 8961 | displayContent.pendingLayoutChanges = 0; |
| 8962 | |
| 8963 | if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("loop number " |
| 8964 | + mLayoutRepeatCount, displayContent.pendingLayoutChanges); |
| 8965 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 8966 | if (isDefaultDisplay) { |
| 8967 | mPolicy.beginPostLayoutPolicyLw(dw, dh); |
| 8968 | for (i = windows.size() - 1; i >= 0; i--) { |
| 8969 | WindowState w = windows.get(i); |
| 8970 | if (w.mHasSurface) { |
| 8971 | mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs); |
| 8972 | } |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 8973 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 8974 | displayContent.pendingLayoutChanges |= mPolicy.finishPostLayoutPolicyLw(); |
| 8975 | if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats( |
| 8976 | "after finishPostLayoutPolicyLw", displayContent.pendingLayoutChanges); |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8977 | } |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 8978 | } while (displayContent.pendingLayoutChanges != 0); |
| 8979 | |
| 8980 | mInnerFields.mObscured = false; |
| 8981 | mInnerFields.mDimming = false; |
| 8982 | mInnerFields.mSyswin = false; |
| 8983 | |
| 8984 | // Only used if default window |
| 8985 | final boolean someoneLosingFocus = !mLosingFocus.isEmpty(); |
| 8986 | |
| 8987 | final int N = windows.size(); |
| 8988 | for (i=N-1; i>=0; i--) { |
| 8989 | WindowState w = windows.get(i); |
| 8990 | |
| 8991 | final boolean obscuredChanged = w.mObscured != mInnerFields.mObscured; |
| 8992 | |
| 8993 | // Update effect. |
| 8994 | w.mObscured = mInnerFields.mObscured; |
| 8995 | if (!mInnerFields.mObscured) { |
| 8996 | handleNotObscuredLocked(w, currentTime, innerDw, innerDh); |
| 8997 | } |
| 8998 | |
| 8999 | if (isDefaultDisplay && obscuredChanged && (mWallpaperTarget == w) |
| 9000 | && w.isVisibleLw()) { |
| 9001 | // This is the wallpaper target and its obscured state |
| 9002 | // changed... make sure the current wallaper's visibility |
| 9003 | // has been updated accordingly. |
| 9004 | updateWallpaperVisibilityLocked(); |
| 9005 | } |
| 9006 | |
| 9007 | final WindowStateAnimator winAnimator = w.mWinAnimator; |
| 9008 | |
| 9009 | // If the window has moved due to its containing |
| 9010 | // content frame changing, then we'd like to animate |
| 9011 | // it. |
| 9012 | if (w.mHasSurface && w.shouldAnimateMove()) { |
| 9013 | // Frame has moved, containing content frame |
| 9014 | // has also moved, and we're not currently animating... |
| 9015 | // let's do something. |
| 9016 | Animation a = AnimationUtils.loadAnimation(mContext, |
| 9017 | com.android.internal.R.anim.window_move_from_decor); |
| 9018 | winAnimator.setAnimation(a); |
| 9019 | winAnimator.mAnimDw = w.mLastFrame.left - w.mFrame.left; |
| 9020 | winAnimator.mAnimDh = w.mLastFrame.top - w.mFrame.top; |
| 9021 | try { |
| 9022 | w.mClient.moved(w.mFrame.left, w.mFrame.top); |
| 9023 | } catch (RemoteException e) { |
| 9024 | } |
| 9025 | } |
| 9026 | |
| 9027 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing"); |
| 9028 | w.mContentChanged = false; |
| 9029 | |
| 9030 | // Moved from updateWindowsAndWallpaperLocked(). |
| 9031 | if (w.mHasSurface) { |
| 9032 | // Take care of the window being ready to display. |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 9033 | final boolean committed = |
| 9034 | winAnimator.commitFinishDrawingLocked(currentTime); |
| 9035 | if (isDefaultDisplay && committed) { |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 9036 | if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) { |
| 9037 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9038 | "First draw done in potential wallpaper target " + w); |
| 9039 | mInnerFields.mWallpaperMayChange = true; |
| 9040 | displayContent.pendingLayoutChanges |= |
| 9041 | WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
| 9042 | if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { |
| 9043 | debugLayoutRepeats( |
| 9044 | "wallpaper and commitFinishDrawingLocked true", |
| 9045 | displayContent.pendingLayoutChanges); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 9046 | } |
| 9047 | } |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9048 | } |
| 9049 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 9050 | winAnimator.setSurfaceBoundariesLocked(recoveringMemory); |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9051 | |
| 9052 | final AppWindowToken atoken = w.mAppToken; |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 9053 | if (DEBUG_STARTING_WINDOW && atoken != null |
| 9054 | && w == atoken.startingWindow) { |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9055 | Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" |
| 9056 | + w.isOnScreen() + " allDrawn=" + atoken.allDrawn |
| 9057 | + " freezingScreen=" + atoken.mAppAnimator.freezingScreen); |
| 9058 | } |
| 9059 | if (atoken != null |
| 9060 | && (!atoken.allDrawn || atoken.mAppAnimator.freezingScreen)) { |
| 9061 | if (atoken.lastTransactionSequence != mTransactionSequence) { |
| 9062 | atoken.lastTransactionSequence = mTransactionSequence; |
| 9063 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 9064 | atoken.startingDisplayed = false; |
| 9065 | } |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 9066 | if ((w.isOnScreen() || winAnimator.mAttrType == TYPE_BASE_APPLICATION) |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9067 | && !w.mExiting && !w.mDestroying) { |
| 9068 | if (WindowManagerService.DEBUG_VISIBILITY || |
| 9069 | WindowManagerService.DEBUG_ORIENTATION) { |
| 9070 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw() |
| 9071 | + ", isAnimating=" + winAnimator.isAnimating()); |
| 9072 | if (!w.isDrawnLw()) { |
| 9073 | Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurface |
| 9074 | + " pv=" + w.mPolicyVisibility |
| 9075 | + " mDrawState=" + winAnimator.mDrawState |
| 9076 | + " ah=" + w.mAttachedHidden |
| 9077 | + " th=" + atoken.hiddenRequested |
| 9078 | + " a=" + winAnimator.mAnimating); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 9079 | } |
| 9080 | } |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9081 | if (w != atoken.startingWindow) { |
| 9082 | if (!atoken.mAppAnimator.freezingScreen || !w.mAppFreezing) { |
| 9083 | atoken.numInterestingWindows++; |
| 9084 | if (w.isDrawnLw()) { |
| 9085 | atoken.numDrawnWindows++; |
| 9086 | if (WindowManagerService.DEBUG_VISIBILITY || |
| 9087 | WindowManagerService.DEBUG_ORIENTATION) Slog.v(TAG, |
| 9088 | "tokenMayBeDrawn: " + atoken |
| 9089 | + " freezingScreen=" + atoken.mAppAnimator.freezingScreen |
| 9090 | + " mAppFreezing=" + w.mAppFreezing); |
| 9091 | updateAllDrawn = true; |
| 9092 | } |
| 9093 | } |
| 9094 | } else if (w.isDrawnLw()) { |
| 9095 | atoken.startingDisplayed = true; |
| 9096 | } |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 9097 | } |
| 9098 | } |
| 9099 | } |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 9100 | |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9101 | if (isDefaultDisplay && someoneLosingFocus && (w == mCurrentFocus) |
| 9102 | && w.isDisplayedLw()) { |
| 9103 | focusDisplayed = true; |
| 9104 | } |
Craig Mautner | 51bb12b | 2012-04-27 14:39:53 -0700 | [diff] [blame] | 9105 | |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9106 | updateResizingWindows(w); |
| 9107 | } |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 9108 | |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 9109 | final boolean hasUniqueContent; |
| 9110 | switch (mInnerFields.mDisplayHasContent) { |
| 9111 | case LayoutFields.DISPLAY_CONTENT_MIRROR: |
| 9112 | hasUniqueContent = isDefaultDisplay; |
| 9113 | break; |
| 9114 | case LayoutFields.DISPLAY_CONTENT_UNIQUE: |
| 9115 | hasUniqueContent = true; |
| 9116 | break; |
| 9117 | case LayoutFields.DISPLAY_CONTENT_UNKNOWN: |
| 9118 | default: |
| 9119 | hasUniqueContent = false; |
| 9120 | break; |
| 9121 | } |
| 9122 | mDisplayManagerService.setDisplayHasContent(displayId, hasUniqueContent, |
| 9123 | true /* inTraversal, must call performTraversalInTrans... below */); |
| 9124 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 9125 | if (!mInnerFields.mDimming && mAnimator.isDimmingLocked(displayId)) { |
| 9126 | stopDimmingLocked(displayId); |
| 9127 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9128 | } |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 9129 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 9130 | if (updateAllDrawn) { |
| 9131 | updateAllDrawnLocked(); |
| 9132 | } |
| 9133 | |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 9134 | if (focusDisplayed) { |
| 9135 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 9136 | } |
Craig Mautner | 65d11b3 | 2012-10-01 13:59:52 -0700 | [diff] [blame^] | 9137 | |
| 9138 | // Give the display manager a chance to adjust properties |
| 9139 | // like display rotation if it needs to. |
| 9140 | mDisplayManagerService.performTraversalInTransactionFromWindowManager(); |
| 9141 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9142 | } catch (RuntimeException e) { |
Dianne Hackborn | 8962028 | 2011-09-11 12:47:45 -0700 | [diff] [blame] | 9143 | Log.wtf(TAG, "Unhandled exception in Window Manager", e); |
Craig Mautner | bf90eaa | 2012-03-15 11:28:53 -0700 | [diff] [blame] | 9144 | } finally { |
| 9145 | Surface.closeTransaction(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9146 | } |
| 9147 | |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9148 | final WindowList defaultWindows = defaultDisplay.getWindowList(); |
| 9149 | |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 9150 | // If we are ready to perform an app transition, check through |
| 9151 | // all of the app tokens to be shown and see if they are ready |
| 9152 | // to go. |
| 9153 | if (mAppTransitionReady) { |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9154 | defaultDisplay.pendingLayoutChanges |= handleAppTransitionReadyLocked(defaultWindows); |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 9155 | if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("after handleAppTransitionReadyLocked", |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9156 | defaultDisplay.pendingLayoutChanges); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 9157 | } |
| 9158 | |
| 9159 | mInnerFields.mAdjResult = 0; |
| 9160 | |
| 9161 | if (!mAnimator.mAnimating && mAppTransitionRunning) { |
| 9162 | // We have finished the animation of an app transition. To do |
| 9163 | // this, we have delayed a lot of operations like showing and |
| 9164 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 9165 | // reflects the correct Z-order, but the window list may now |
| 9166 | // be out of sync with it. So here we will just rebuild the |
| 9167 | // entire app window list. Fun! |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9168 | defaultDisplay.pendingLayoutChanges |= handleAnimatingStoppedAndTransitionLocked(); |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 9169 | if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("after handleAnimStopAndXitionLock", |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9170 | defaultDisplay.pendingLayoutChanges); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 9171 | } |
| 9172 | |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9173 | if (mInnerFields.mWallpaperForceHidingChanged && defaultDisplay.pendingLayoutChanges == 0 |
| 9174 | && !mAppTransitionReady) { |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 9175 | // At this point, there was a window with a wallpaper that |
| 9176 | // was force hiding other windows behind it, but now it |
| 9177 | // is going away. This may be simple -- just animate |
| 9178 | // away the wallpaper and its window -- or it may be |
| 9179 | // hard -- the wallpaper now needs to be shown behind |
| 9180 | // something that was hidden. |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9181 | defaultDisplay.pendingLayoutChanges |= animateAwayWallpaperLocked(); |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 9182 | if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("after animateAwayWallpaperLocked", |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9183 | defaultDisplay.pendingLayoutChanges); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 9184 | } |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 9185 | mInnerFields.mWallpaperForceHidingChanged = false; |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 9186 | |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 9187 | if (mInnerFields.mWallpaperMayChange) { |
| 9188 | if (WindowManagerService.DEBUG_WALLPAPER) Slog.v(TAG, |
| 9189 | "Wallpaper may change! Adjusting"); |
| 9190 | mInnerFields.mAdjResult |= adjustWallpaperWindowsLocked(); |
| 9191 | } |
| 9192 | |
| 9193 | if ((mInnerFields.mAdjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 9194 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 9195 | "Wallpaper layer changed: assigning layers + relayout"); |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9196 | defaultDisplay.pendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT; |
| 9197 | assignLayersLocked(defaultWindows); |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 9198 | } else if ((mInnerFields.mAdjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
| 9199 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 9200 | "Wallpaper visibility changed: relayout"); |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9201 | defaultDisplay.pendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT; |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 9202 | } |
| 9203 | |
| 9204 | if (mFocusMayChange) { |
| 9205 | mFocusMayChange = false; |
| 9206 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, |
| 9207 | false /*updateInputWindows*/)) { |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9208 | defaultDisplay.pendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM; |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 9209 | mInnerFields.mAdjResult = 0; |
| 9210 | } |
| 9211 | } |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 9212 | |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 9213 | if (needsLayout()) { |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9214 | defaultDisplay.pendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT; |
| 9215 | if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("mLayoutNeeded", |
| 9216 | defaultDisplay.pendingLayoutChanges); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 9217 | } |
| 9218 | |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 9219 | if (!mResizingWindows.isEmpty()) { |
| 9220 | for (i = mResizingWindows.size() - 1; i >= 0; i--) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9221 | WindowState win = mResizingWindows.get(i); |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 9222 | final WindowStateAnimator winAnimator = win.mWinAnimator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9223 | try { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9224 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 9225 | "Reporting new frame to " + win + ": " + win.mCompatFrame); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9226 | int diff = 0; |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 9227 | boolean configChanged = win.isConfigChanged(); |
Craig Mautner | c36c49e | 2012-09-29 16:02:43 -0700 | [diff] [blame] | 9228 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION |
| 9229 | // TODO: Remove once b/7094175 is fixed |
| 9230 | || ((String)win.mAttrs.getTitle()).contains("Keyguard")) |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9231 | && configChanged) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9232 | Slog.i(TAG, "Sending new config to window " + win + ": " |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 9233 | + winAnimator.mSurfaceW + "x" + winAnimator.mSurfaceH |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9234 | + " / " + mCurConfiguration + " / 0x" |
| 9235 | + Integer.toHexString(diff)); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9236 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9237 | win.mConfiguration = mCurConfiguration; |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 9238 | if (DEBUG_ORIENTATION && |
| 9239 | winAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING) Slog.i( |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 9240 | TAG, "Resizing " + win + " WITH DRAW PENDING"); |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 9241 | win.mClient.resized(win.mFrame, win.mLastContentInsets, win.mLastVisibleInsets, |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 9242 | winAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING, |
| 9243 | configChanged ? win.mConfiguration : null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9244 | win.mContentInsetsChanged = false; |
| 9245 | win.mVisibleInsetsChanged = false; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 9246 | winAnimator.mSurfaceResized = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9247 | } catch (RemoteException e) { |
| 9248 | win.mOrientationChanging = false; |
| 9249 | } |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 9250 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9251 | mResizingWindows.clear(); |
| 9252 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9253 | |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 9254 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
| 9255 | "With display frozen, orientationChangeComplete=" |
| 9256 | + mInnerFields.mOrientationChangeComplete); |
| 9257 | if (mInnerFields.mOrientationChangeComplete) { |
| 9258 | if (mWindowsFreezingScreen) { |
| 9259 | mWindowsFreezingScreen = false; |
| 9260 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 9261 | } |
| 9262 | stopFreezingDisplayLocked(); |
| 9263 | } |
| 9264 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9265 | // Destroy the surface of any windows that are no longer visible. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9266 | boolean wallpaperDestroyed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9267 | i = mDestroySurface.size(); |
| 9268 | if (i > 0) { |
| 9269 | do { |
| 9270 | i--; |
| 9271 | WindowState win = mDestroySurface.get(i); |
| 9272 | win.mDestroying = false; |
| 9273 | if (mInputMethodWindow == win) { |
| 9274 | mInputMethodWindow = null; |
| 9275 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9276 | if (win == mWallpaperTarget) { |
| 9277 | wallpaperDestroyed = true; |
| 9278 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9279 | win.mWinAnimator.destroySurfaceLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9280 | } while (i > 0); |
| 9281 | mDestroySurface.clear(); |
| 9282 | } |
| 9283 | |
| 9284 | // Time to remove any exiting tokens? |
| 9285 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9286 | WindowToken token = mExitingTokens.get(i); |
| 9287 | if (!token.hasVisible) { |
| 9288 | mExitingTokens.remove(i); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 9289 | if (token.windowType == TYPE_WALLPAPER) { |
| 9290 | mWallpaperTokens.remove(token); |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 9291 | updateLayoutToAnimWallpaperTokens(); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 9292 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9293 | } |
| 9294 | } |
| 9295 | |
| 9296 | // Time to remove any exiting applications? |
| 9297 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9298 | AppWindowToken token = mExitingAppTokens.get(i); |
| 9299 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9300 | // Make sure there is no animation running on this token, |
| 9301 | // so any windows associated with it will be removed as |
| 9302 | // soon as their animations are complete |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 9303 | token.mAppAnimator.clearAnimation(); |
| 9304 | token.mAppAnimator.animating = false; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9305 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 9306 | "performLayout: App token exiting now removed" + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9307 | mAppTokens.remove(token); |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 9308 | mAnimatingAppTokens.remove(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9309 | mExitingAppTokens.remove(i); |
| 9310 | } |
| 9311 | } |
| 9312 | |
Dianne Hackborn | 12d3a94 | 2012-04-27 14:16:30 -0700 | [diff] [blame] | 9313 | if (!mAnimator.mAnimating && mRelayoutWhileAnimating.size() > 0) { |
| 9314 | for (int j=mRelayoutWhileAnimating.size()-1; j>=0; j--) { |
| 9315 | try { |
| 9316 | mRelayoutWhileAnimating.get(j).mClient.doneAnimating(); |
| 9317 | } catch (RemoteException e) { |
| 9318 | } |
| 9319 | } |
| 9320 | mRelayoutWhileAnimating.clear(); |
| 9321 | } |
| 9322 | |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 9323 | if (wallpaperDestroyed && (adjustWallpaperWindowsLocked() != 0)) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 9324 | getDefaultDisplayContentLocked().layoutNeeded = true; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9325 | } |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9326 | |
| 9327 | DisplayContentsIterator iterator = new DisplayContentsIterator(); |
| 9328 | while (iterator.hasNext()) { |
| 9329 | DisplayContent displayContent = iterator.next(); |
| 9330 | if (displayContent.pendingLayoutChanges != 0) { |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 9331 | displayContent.layoutNeeded = true; |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9332 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9333 | } |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 9334 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9335 | // Finally update all input windows now that the window changes have stabilized. |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 9336 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 9337 | |
Craig Mautner | 259328c | 2012-08-21 19:30:58 -0700 | [diff] [blame] | 9338 | setHoldScreenLocked(mInnerFields.mHoldScreen); |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 9339 | if (!mDisplayFrozen) { |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 9340 | if (mInnerFields.mScreenBrightness < 0 || mInnerFields.mScreenBrightness > 1.0f) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 9341 | mPowerManager.setScreenBrightnessOverrideFromWindowManager(-1); |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 9342 | } else { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 9343 | mPowerManager.setScreenBrightnessOverrideFromWindowManager( |
| 9344 | toBrightnessOverride(mInnerFields.mScreenBrightness)); |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 9345 | } |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 9346 | if (mInnerFields.mButtonBrightness < 0 || mInnerFields.mButtonBrightness > 1.0f) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 9347 | mPowerManager.setButtonBrightnessOverrideFromWindowManager(-1); |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 9348 | } else { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 9349 | mPowerManager.setButtonBrightnessOverrideFromWindowManager( |
| 9350 | toBrightnessOverride(mInnerFields.mButtonBrightness)); |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 9351 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9352 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9353 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 9354 | if (mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9355 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 9356 | mPowerManager.wakeUp(SystemClock.uptimeMillis()); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 9357 | mTurnOnScreen = false; |
| 9358 | } |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 9359 | |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 9360 | if (mInnerFields.mUpdateRotation) { |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 9361 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation"); |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 9362 | if (updateRotationUncheckedLocked(false)) { |
Dianne Hackborn | 3e4f9d0 | 2011-02-04 14:05:55 -0800 | [diff] [blame] | 9363 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 9364 | } else { |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 9365 | mInnerFields.mUpdateRotation = false; |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 9366 | } |
| 9367 | } |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 9368 | |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 9369 | if (mInnerFields.mOrientationChangeComplete && !defaultDisplay.layoutNeeded |
| 9370 | && !mInnerFields.mUpdateRotation) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 9371 | checkDrawnWindowsLocked(); |
| 9372 | } |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 9373 | |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9374 | final int N = mPendingRemove.size(); |
| 9375 | if (N > 0) { |
| 9376 | if (mPendingRemoveTmp.length < N) { |
| 9377 | mPendingRemoveTmp = new WindowState[N+10]; |
| 9378 | } |
| 9379 | mPendingRemove.toArray(mPendingRemoveTmp); |
| 9380 | mPendingRemove.clear(); |
| 9381 | DisplayContentList displayList = new DisplayContentList(); |
| 9382 | for (i = 0; i < N; i++) { |
| 9383 | WindowState w = mPendingRemoveTmp[i]; |
| 9384 | removeWindowInnerLocked(w.mSession, w); |
| 9385 | if (!displayList.contains(w.mDisplayContent)) { |
| 9386 | displayList.add(w.mDisplayContent); |
| 9387 | } |
| 9388 | } |
| 9389 | |
| 9390 | for (DisplayContent displayContent : displayList) { |
| 9391 | assignLayersLocked(displayContent.getWindowList()); |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 9392 | displayContent.layoutNeeded = true; |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9393 | } |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9394 | } |
| 9395 | |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 9396 | // Check to see if we are now in a state where the screen should |
| 9397 | // be enabled, because the window obscured flags have changed. |
| 9398 | enableScreenIfNeededLocked(); |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 9399 | |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 9400 | updateLayoutToAnimationLocked(); |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 9401 | |
| 9402 | if (DEBUG_WINDOW_TRACE) { |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 9403 | Slog.e(TAG, "performLayoutAndPlaceSurfacesLockedInner exit: animating=" |
| 9404 | + mAnimator.mAnimating); |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 9405 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9406 | } |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 9407 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 9408 | private int toBrightnessOverride(float value) { |
| 9409 | return (int)(value * PowerManager.BRIGHTNESS_ON); |
| 9410 | } |
| 9411 | |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 9412 | void checkDrawnWindowsLocked() { |
| 9413 | if (mWaitingForDrawn.size() > 0) { |
| 9414 | for (int j=mWaitingForDrawn.size()-1; j>=0; j--) { |
| 9415 | Pair<WindowState, IRemoteCallback> pair = mWaitingForDrawn.get(j); |
| 9416 | WindowState win = pair.first; |
| 9417 | //Slog.i(TAG, "Waiting for drawn " + win + ": removed=" |
| 9418 | // + win.mRemoved + " visible=" + win.isVisibleLw() |
| 9419 | // + " shown=" + win.mSurfaceShown); |
| 9420 | if (win.mRemoved || !win.isVisibleLw()) { |
| 9421 | // Window has been removed or made invisible; no draw |
| 9422 | // will now happen, so stop waiting. |
| 9423 | Slog.w(TAG, "Aborted waiting for drawn: " + pair.first); |
| 9424 | try { |
| 9425 | pair.second.sendResult(null); |
| 9426 | } catch (RemoteException e) { |
| 9427 | } |
| 9428 | mWaitingForDrawn.remove(pair); |
| 9429 | mH.removeMessages(H.WAITING_FOR_DRAWN_TIMEOUT, pair); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9430 | } else if (win.mWinAnimator.mSurfaceShown) { |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 9431 | // Window is now drawn (and shown). |
| 9432 | try { |
| 9433 | pair.second.sendResult(null); |
| 9434 | } catch (RemoteException e) { |
| 9435 | } |
| 9436 | mWaitingForDrawn.remove(pair); |
| 9437 | mH.removeMessages(H.WAITING_FOR_DRAWN_TIMEOUT, pair); |
| 9438 | } |
| 9439 | } |
| 9440 | } |
| 9441 | } |
| 9442 | |
| 9443 | public void waitForWindowDrawn(IBinder token, IRemoteCallback callback) { |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 9444 | synchronized (mWindowMap) { |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 9445 | WindowState win = windowForClientLocked(null, token, true); |
| 9446 | if (win != null) { |
| 9447 | Pair<WindowState, IRemoteCallback> pair = |
| 9448 | new Pair<WindowState, IRemoteCallback>(win, callback); |
| 9449 | Message m = mH.obtainMessage(H.WAITING_FOR_DRAWN_TIMEOUT, pair); |
| 9450 | mH.sendMessageDelayed(m, 2000); |
| 9451 | mWaitingForDrawn.add(pair); |
| 9452 | checkDrawnWindowsLocked(); |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 9453 | } |
| 9454 | } |
| 9455 | } |
| 9456 | |
Craig Mautner | 259328c | 2012-08-21 19:30:58 -0700 | [diff] [blame] | 9457 | void setHoldScreenLocked(final Session newHoldScreen) { |
| 9458 | final boolean hold = newHoldScreen != null; |
| 9459 | |
| 9460 | if (hold && mHoldingScreenOn != newHoldScreen) { |
| 9461 | mHoldingScreenWakeLock.setWorkSource(new WorkSource(newHoldScreen.mUid)); |
| 9462 | } |
| 9463 | mHoldingScreenOn = newHoldScreen; |
| 9464 | |
| 9465 | final boolean state = mHoldingScreenWakeLock.isHeld(); |
| 9466 | if (hold != state) { |
| 9467 | if (hold) { |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 9468 | mPolicy.screenOnStartedLw(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 9469 | mHoldingScreenWakeLock.acquire(); |
| 9470 | } else { |
| 9471 | mPolicy.screenOnStoppedLw(); |
| 9472 | mHoldingScreenWakeLock.release(); |
| 9473 | } |
| 9474 | } |
| 9475 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9476 | |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 9477 | @Override |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 9478 | public void requestTraversal() { |
| 9479 | synchronized (mWindowMap) { |
| 9480 | requestTraversalLocked(); |
| 9481 | } |
| 9482 | } |
| 9483 | |
Dianne Hackborn | 8bcd54b | 2012-01-31 19:04:53 -0800 | [diff] [blame] | 9484 | void requestTraversalLocked() { |
| 9485 | if (!mTraversalScheduled) { |
| 9486 | mTraversalScheduled = true; |
| 9487 | mH.sendEmptyMessage(H.DO_TRAVERSAL); |
| 9488 | } |
| 9489 | } |
| 9490 | |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 9491 | /** Note that Locked in this case is on mLayoutToAnim */ |
Jeff Brown | 4a06c80 | 2012-02-15 15:06:01 -0800 | [diff] [blame] | 9492 | void scheduleAnimationLocked() { |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 9493 | final LayoutToAnimatorParams layoutToAnim = mLayoutToAnim; |
| 9494 | if (!layoutToAnim.mAnimationScheduled) { |
| 9495 | layoutToAnim.mAnimationScheduled = true; |
| 9496 | mChoreographer.postCallback( |
| 9497 | Choreographer.CALLBACK_ANIMATION, mAnimator.mAnimationRunnable, null); |
| 9498 | } |
| 9499 | } |
| 9500 | |
| 9501 | void updateLayoutToAnimationLocked() { |
| 9502 | final LayoutToAnimatorParams layoutToAnim = mLayoutToAnim; |
Craig Mautner | 1caa399 | 2012-06-22 09:46:48 -0700 | [diff] [blame] | 9503 | synchronized (layoutToAnim) { |
| 9504 | // Copy local params to transfer params. |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 9505 | SparseArray<WinAnimatorList> allWinAnimatorLists = layoutToAnim.mWinAnimatorLists; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9506 | allWinAnimatorLists.clear(); |
| 9507 | DisplayContentsIterator iterator = new DisplayContentsIterator(); |
| 9508 | while (iterator.hasNext()) { |
| 9509 | final DisplayContent displayContent = iterator.next(); |
| 9510 | WinAnimatorList winAnimatorList = new WinAnimatorList(); |
| 9511 | final WindowList windows = displayContent.getWindowList(); |
| 9512 | int N = windows.size(); |
| 9513 | for (int i = 0; i < N; i++) { |
| 9514 | final WindowStateAnimator winAnimator = windows.get(i).mWinAnimator; |
| 9515 | if (winAnimator.mSurface != null) { |
| 9516 | winAnimatorList.add(winAnimator); |
| 9517 | } |
Craig Mautner | 1caa399 | 2012-06-22 09:46:48 -0700 | [diff] [blame] | 9518 | } |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 9519 | allWinAnimatorLists.put(displayContent.getDisplayId(), winAnimatorList); |
Craig Mautner | 1caa399 | 2012-06-22 09:46:48 -0700 | [diff] [blame] | 9520 | } |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 9521 | |
Craig Mautner | 1caa399 | 2012-06-22 09:46:48 -0700 | [diff] [blame] | 9522 | layoutToAnim.mWallpaperTarget = mWallpaperTarget; |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 9523 | layoutToAnim.mLowerWallpaperTarget = mLowerWallpaperTarget; |
| 9524 | layoutToAnim.mUpperWallpaperTarget = mUpperWallpaperTarget; |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 9525 | |
| 9526 | final ArrayList<AppWindowAnimParams> paramList = layoutToAnim.mAppWindowAnimParams; |
| 9527 | paramList.clear(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9528 | int N = mAnimatingAppTokens.size(); |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 9529 | for (int i = 0; i < N; i++) { |
| 9530 | paramList.add(new AppWindowAnimParams(mAnimatingAppTokens.get(i).mAppAnimator)); |
| 9531 | } |
| 9532 | |
| 9533 | layoutToAnim.mParamsModified = true; |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 9534 | scheduleAnimationLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9535 | } |
| 9536 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9537 | |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 9538 | void updateLayoutToAnimWallpaperTokens() { |
| 9539 | synchronized(mLayoutToAnim) { |
| 9540 | mLayoutToAnim.mWallpaperTokens = new ArrayList<WindowToken>(mWallpaperTokens); |
| 9541 | mLayoutToAnim.mChanges |= LayoutToAnimatorParams.WALLPAPER_TOKENS_CHANGED; |
| 9542 | } |
| 9543 | } |
| 9544 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 9545 | void setAnimDimParams(int displayId, DimAnimator.Parameters params) { |
Craig Mautner | a76fdb7 | 2012-07-03 19:03:02 -0700 | [diff] [blame] | 9546 | synchronized (mLayoutToAnim) { |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 9547 | mLayoutToAnim.mDimParams.put(displayId, params); |
Craig Mautner | a76fdb7 | 2012-07-03 19:03:02 -0700 | [diff] [blame] | 9548 | scheduleAnimationLocked(); |
| 9549 | } |
| 9550 | } |
| 9551 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 9552 | void startDimmingLocked(final WindowStateAnimator winAnimator, final float target, |
Craig Mautner | a76fdb7 | 2012-07-03 19:03:02 -0700 | [diff] [blame] | 9553 | final int width, final int height) { |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 9554 | setAnimDimParams(winAnimator.mWin.getDisplayId(), |
| 9555 | new DimAnimator.Parameters(winAnimator, width, height, target)); |
Craig Mautner | a76fdb7 | 2012-07-03 19:03:02 -0700 | [diff] [blame] | 9556 | } |
| 9557 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 9558 | void stopDimmingLocked(int displayId) { |
| 9559 | setAnimDimParams(displayId, null); |
Craig Mautner | a76fdb7 | 2012-07-03 19:03:02 -0700 | [diff] [blame] | 9560 | } |
| 9561 | |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 9562 | private boolean needsLayout() { |
| 9563 | DisplayContentsIterator iterator = new DisplayContentsIterator(); |
| 9564 | while (iterator.hasNext()) { |
| 9565 | if (iterator.next().layoutNeeded) { |
| 9566 | return true; |
| 9567 | } |
| 9568 | } |
| 9569 | return false; |
| 9570 | } |
| 9571 | |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 9572 | private boolean copyAnimToLayoutParamsLocked() { |
| 9573 | boolean doRequest = false; |
| 9574 | final WindowAnimator.AnimatorToLayoutParams animToLayout = mAnimator.mAnimToLayout; |
| 9575 | synchronized (animToLayout) { |
| 9576 | animToLayout.mUpdateQueued = false; |
| 9577 | final int bulkUpdateParams = animToLayout.mBulkUpdateParams; |
| 9578 | // TODO(cmautner): As the number of bits grows, use masks of bit groups to |
| 9579 | // eliminate unnecessary tests. |
| 9580 | if ((bulkUpdateParams & LayoutFields.SET_UPDATE_ROTATION) != 0) { |
| 9581 | mInnerFields.mUpdateRotation = true; |
| 9582 | doRequest = true; |
| 9583 | } |
| 9584 | if ((bulkUpdateParams & LayoutFields.SET_WALLPAPER_MAY_CHANGE) != 0) { |
| 9585 | mInnerFields.mWallpaperMayChange = true; |
| 9586 | doRequest = true; |
| 9587 | } |
| 9588 | if ((bulkUpdateParams & LayoutFields.SET_FORCE_HIDING_CHANGED) != 0) { |
| 9589 | mInnerFields.mWallpaperForceHidingChanged = true; |
| 9590 | doRequest = true; |
| 9591 | } |
| 9592 | if ((bulkUpdateParams & LayoutFields.SET_ORIENTATION_CHANGE_COMPLETE) == 0) { |
| 9593 | mInnerFields.mOrientationChangeComplete = false; |
| 9594 | } else { |
| 9595 | mInnerFields.mOrientationChangeComplete = true; |
| 9596 | if (mWindowsFreezingScreen) { |
| 9597 | doRequest = true; |
| 9598 | } |
| 9599 | } |
| 9600 | if ((bulkUpdateParams & LayoutFields.SET_TURN_ON_SCREEN) != 0) { |
| 9601 | mTurnOnScreen = true; |
| 9602 | } |
| 9603 | |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9604 | SparseIntArray pendingLayouts = animToLayout.mPendingLayoutChanges; |
| 9605 | final int count = pendingLayouts.size(); |
| 9606 | if (count > 0) { |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 9607 | doRequest = true; |
| 9608 | } |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9609 | for (int i = 0; i < count; ++i) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 9610 | final DisplayContent displayContent = |
| 9611 | getDisplayContentLocked(pendingLayouts.keyAt(i)); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 9612 | displayContent.pendingLayoutChanges |= pendingLayouts.valueAt(i); |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 9613 | } |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 9614 | |
| 9615 | mWindowDetachedWallpaper = animToLayout.mWindowDetachedWallpaper; |
| 9616 | } |
| 9617 | return doRequest; |
| 9618 | } |
| 9619 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9620 | boolean reclaimSomeSurfaceMemoryLocked(WindowStateAnimator winAnimator, String operation, |
| 9621 | boolean secure) { |
| 9622 | final Surface surface = winAnimator.mSurface; |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 9623 | boolean leakedSurface = false; |
| 9624 | boolean killedApps = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9625 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9626 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, winAnimator.mWin.toString(), |
| 9627 | winAnimator.mSession.mPid, operation); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9628 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9629 | if (mForceRemoves == null) { |
| 9630 | mForceRemoves = new ArrayList<WindowState>(); |
| 9631 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9632 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9633 | long callingIdentity = Binder.clearCallingIdentity(); |
| 9634 | try { |
| 9635 | // There was some problem... first, do a sanity check of the |
| 9636 | // window list to make sure we haven't left any dangling surfaces |
| 9637 | // around. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9638 | |
| 9639 | AllWindowsIterator iterator = new AllWindowsIterator(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9640 | Slog.i(TAG, "Out of memory for surface! Looking for leaks..."); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9641 | while (iterator.hasNext()) { |
| 9642 | WindowState ws = iterator.next(); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9643 | WindowStateAnimator wsa = ws.mWinAnimator; |
| 9644 | if (wsa.mSurface != null) { |
| 9645 | if (!mSessions.contains(wsa.mSession)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9646 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9647 | + ws + " surface=" + wsa.mSurface |
| 9648 | + " token=" + ws.mToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9649 | + " pid=" + ws.mSession.mPid |
| 9650 | + " uid=" + ws.mSession.mUid); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 9651 | if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9652 | wsa.mSurface.destroy(); |
| 9653 | wsa.mSurfaceShown = false; |
| 9654 | wsa.mSurface = null; |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 9655 | ws.mHasSurface = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9656 | mForceRemoves.add(ws); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9657 | leakedSurface = true; |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 9658 | } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9659 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9660 | + ws + " surface=" + wsa.mSurface |
| 9661 | + " token=" + ws.mAppToken); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 9662 | if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9663 | wsa.mSurface.destroy(); |
| 9664 | wsa.mSurfaceShown = false; |
| 9665 | wsa.mSurface = null; |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 9666 | ws.mHasSurface = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9667 | leakedSurface = true; |
| 9668 | } |
| 9669 | } |
| 9670 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9671 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9672 | if (!leakedSurface) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9673 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9674 | SparseIntArray pidCandidates = new SparseIntArray(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9675 | iterator = new AllWindowsIterator(); |
| 9676 | while (iterator.hasNext()) { |
| 9677 | WindowState ws = iterator.next(); |
| 9678 | if (mForceRemoves.contains(ws)) { |
| 9679 | continue; |
| 9680 | } |
| 9681 | WindowStateAnimator wsa = ws.mWinAnimator; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9682 | if (wsa.mSurface != null) { |
| 9683 | pidCandidates.append(wsa.mSession.mPid, wsa.mSession.mPid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9684 | } |
| 9685 | } |
| 9686 | if (pidCandidates.size() > 0) { |
| 9687 | int[] pids = new int[pidCandidates.size()]; |
| 9688 | for (int i=0; i<pids.length; i++) { |
| 9689 | pids[i] = pidCandidates.keyAt(i); |
| 9690 | } |
| 9691 | try { |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 9692 | if (mActivityManager.killPids(pids, "Free memory", secure)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9693 | killedApps = true; |
| 9694 | } |
| 9695 | } catch (RemoteException e) { |
| 9696 | } |
| 9697 | } |
| 9698 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9699 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9700 | if (leakedSurface || killedApps) { |
| 9701 | // We managed to reclaim some memory, so get rid of the trouble |
| 9702 | // surface and ask the app to request another one. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9703 | 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] | 9704 | if (surface != null) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9705 | if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) logSurface(winAnimator.mWin, |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 9706 | "RECOVER DESTROY", null); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9707 | surface.destroy(); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9708 | winAnimator.mSurfaceShown = false; |
| 9709 | winAnimator.mSurface = null; |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 9710 | winAnimator.mWin.mHasSurface = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9711 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9712 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9713 | try { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 9714 | winAnimator.mWin.mClient.dispatchGetNewSurface(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9715 | } catch (RemoteException e) { |
| 9716 | } |
| 9717 | } |
| 9718 | } finally { |
| 9719 | Binder.restoreCallingIdentity(callingIdentity); |
| 9720 | } |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 9721 | |
| 9722 | return leakedSurface || killedApps; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9723 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9724 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9725 | private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9726 | WindowState newFocus = computeFocusedWindowLocked(); |
| 9727 | if (mCurrentFocus != newFocus) { |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 9728 | Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "wmUpdateFocus"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9729 | // This check makes sure that we don't already have the focus |
| 9730 | // change message pending. |
| 9731 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 9732 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9733 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9734 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 9735 | final WindowState oldFocus = mCurrentFocus; |
| 9736 | mCurrentFocus = newFocus; |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 9737 | mAnimator.setCurrentFocus(newFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9738 | mLosingFocus.remove(newFocus); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 9739 | int focusChanged = mPolicy.focusChangedLw(oldFocus, newFocus); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9740 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9741 | // TODO(multidisplay): Focused windows on default display only. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 9742 | final DisplayContent displayContent = getDefaultDisplayContentLocked(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9743 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9744 | final WindowState imWindow = mInputMethodWindow; |
| 9745 | if (newFocus != imWindow && oldFocus != imWindow) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9746 | if (moveInputMethodWindowsIfNeededLocked( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9747 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9748 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
Jeff Brown | 2033763 | 2012-09-24 14:25:54 -0700 | [diff] [blame] | 9749 | displayContent.layoutNeeded = true; |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9750 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9751 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9752 | performLayoutLockedInner(displayContent, true /*initial*/, updateInputWindows); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 9753 | focusChanged &= ~WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT; |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9754 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 9755 | // Client will do the layout, but we need to assign layers |
| 9756 | // for handleNewWindowLocked() below. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9757 | assignLayersLocked(displayContent.getWindowList()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9758 | } |
| 9759 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 9760 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 9761 | if ((focusChanged & WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 9762 | // The change in focus caused us to need to do a layout. Okay. |
Jeff Brown | 2033763 | 2012-09-24 14:25:54 -0700 | [diff] [blame] | 9763 | displayContent.layoutNeeded = true; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 9764 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9765 | performLayoutLockedInner(displayContent, true /*initial*/, updateInputWindows); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 9766 | } |
| 9767 | } |
| 9768 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9769 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 9770 | // If we defer assigning layers, then the caller is responsible for |
| 9771 | // doing this part. |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9772 | finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9773 | } |
Dianne Hackborn | 1ded0b1 | 2012-04-26 14:14:50 -0700 | [diff] [blame] | 9774 | |
| 9775 | Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9776 | return true; |
| 9777 | } |
| 9778 | return false; |
| 9779 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9780 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9781 | private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) { |
| 9782 | mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9783 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9784 | |
| 9785 | private WindowState computeFocusedWindowLocked() { |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 9786 | if (mAnimator.mUniverseBackground != null |
| 9787 | && mAnimator.mUniverseBackground.mWin.canReceiveKeys()) { |
| 9788 | return mAnimator.mUniverseBackground.mWin; |
| 9789 | } |
| 9790 | |
Jeff Brown | 2033763 | 2012-09-24 14:25:54 -0700 | [diff] [blame] | 9791 | final int displayCount = mDisplayContents.size(); |
| 9792 | for (int i = 0; i < displayCount; i++) { |
| 9793 | final DisplayContent displayContent = mDisplayContents.valueAt(i); |
| 9794 | WindowState win = findFocusedWindowLocked(displayContent); |
| 9795 | if (win != null) { |
| 9796 | return win; |
| 9797 | } |
| 9798 | } |
| 9799 | return null; |
| 9800 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9801 | |
Jeff Brown | 2033763 | 2012-09-24 14:25:54 -0700 | [diff] [blame] | 9802 | private WindowState findFocusedWindowLocked(DisplayContent displayContent) { |
| 9803 | int nextAppIndex = mAppTokens.size()-1; |
| 9804 | WindowToken nextApp = nextAppIndex >= 0 ? mAppTokens.get(nextAppIndex) : null; |
| 9805 | |
| 9806 | final WindowList windows = displayContent.getWindowList(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9807 | for (int i = windows.size() - 1; i >= 0; i--) { |
Jeff Brown | 2033763 | 2012-09-24 14:25:54 -0700 | [diff] [blame] | 9808 | final WindowState win = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9809 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9810 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9811 | TAG, "Looking for focus: " + i |
| 9812 | + " = " + win |
| 9813 | + ", flags=" + win.mAttrs.flags |
| 9814 | + ", canReceive=" + win.canReceiveKeys()); |
| 9815 | |
| 9816 | AppWindowToken thisApp = win.mAppToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9817 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9818 | // If this window's application has been removed, just skip it. |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 9819 | if (thisApp != null && (thisApp.removed || thisApp.sendingToBottom)) { |
Craig Mautner | 3f99fde | 2012-06-19 14:10:01 -0700 | [diff] [blame] | 9820 | if (DEBUG_FOCUS) Slog.v(TAG, "Skipping app because " + (thisApp.removed |
| 9821 | ? "removed" : "sendingToBottom")); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9822 | continue; |
| 9823 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9824 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9825 | // If there is a focused app, don't allow focus to go to any |
| 9826 | // windows below it. If this is an application window, step |
| 9827 | // through the app tokens until we find its app. |
| 9828 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 9829 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 9830 | int origAppIndex = nextAppIndex; |
| 9831 | while (nextAppIndex > 0) { |
| 9832 | if (nextApp == mFocusedApp) { |
| 9833 | // Whoops, we are below the focused app... no focus |
| 9834 | // for you! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9835 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9836 | TAG, "Reached focused app: " + mFocusedApp); |
| 9837 | return null; |
| 9838 | } |
| 9839 | nextAppIndex--; |
| 9840 | nextApp = mAppTokens.get(nextAppIndex); |
| 9841 | if (nextApp == thisApp) { |
| 9842 | break; |
| 9843 | } |
| 9844 | } |
| 9845 | if (thisApp != nextApp) { |
| 9846 | // Uh oh, the app token doesn't exist! This shouldn't |
| 9847 | // happen, but if it does we can get totally hosed... |
| 9848 | // so restart at the original app. |
| 9849 | nextAppIndex = origAppIndex; |
| 9850 | nextApp = mAppTokens.get(nextAppIndex); |
| 9851 | } |
| 9852 | } |
| 9853 | |
| 9854 | // Dispatch to this window if it is wants key events. |
| 9855 | if (win.canReceiveKeys()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9856 | if (DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9857 | TAG, "Found focus @ " + i + " = " + win); |
Jeff Brown | 2033763 | 2012-09-24 14:25:54 -0700 | [diff] [blame] | 9858 | return win; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9859 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9860 | } |
Jeff Brown | 2033763 | 2012-09-24 14:25:54 -0700 | [diff] [blame] | 9861 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9862 | } |
| 9863 | |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 9864 | private void startFreezingDisplayLocked(boolean inTransaction, |
| 9865 | int exitAnim, int enterAnim) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9866 | if (mDisplayFrozen) { |
| 9867 | return; |
| 9868 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9869 | |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 9870 | if (!mDisplayReady || !mPolicy.isScreenOnFully()) { |
Dianne Hackborn | 8e8d65f | 2011-08-11 19:36:18 -0700 | [diff] [blame] | 9871 | // No need to freeze the screen before the system is ready or if |
| 9872 | // the screen is off. |
| 9873 | return; |
| 9874 | } |
| 9875 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9876 | mScreenFrozenLock.acquire(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9877 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9878 | mDisplayFrozen = true; |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 9879 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9880 | mInputMonitor.freezeInputDispatchingLw(); |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 9881 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9882 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 9883 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 9884 | mNextAppTransitionType = ActivityOptions.ANIM_NONE; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9885 | mNextAppTransitionPackage = null; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 9886 | mNextAppTransitionThumbnail = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9887 | mAppTransitionReady = true; |
| 9888 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9889 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9890 | if (PROFILE_ORIENTATION) { |
| 9891 | File file = new File("/data/system/frozen"); |
| 9892 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 9893 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 9894 | |
| 9895 | if (CUSTOM_SCREEN_ROTATION) { |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 9896 | final DisplayContent displayContent = getDefaultDisplayContentLocked(); |
| 9897 | final int displayId = displayContent.getDisplayId(); |
| 9898 | ScreenRotationAnimation screenRotationAnimation = |
| 9899 | mAnimator.getScreenRotationAnimationLocked(displayId); |
| 9900 | if (screenRotationAnimation != null) { |
| 9901 | screenRotationAnimation.kill(); |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 9902 | } |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 9903 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9904 | // TODO(multidisplay): rotation on main screen only. |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 9905 | final Display display = displayContent.getDisplay(); |
| 9906 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 9907 | screenRotationAnimation = new ScreenRotationAnimation(mContext, |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 9908 | display, mFxSession, inTransaction, displayInfo.logicalWidth, |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 9909 | displayInfo.logicalHeight, display.getRotation(), |
| 9910 | exitAnim, enterAnim); |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 9911 | mAnimator.setScreenRotationAnimationLocked(displayId, screenRotationAnimation); |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 9912 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9913 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9914 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9915 | private void stopFreezingDisplayLocked() { |
| 9916 | if (!mDisplayFrozen) { |
| 9917 | return; |
| 9918 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9919 | |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 9920 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen |
| 9921 | || mClientFreezingScreen) { |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 9922 | if (DEBUG_ORIENTATION) Slog.d(TAG, |
| 9923 | "stopFreezingDisplayLocked: Returning mWaitingForConfig=" + mWaitingForConfig |
| 9924 | + ", mAppsFreezingScreen=" + mAppsFreezingScreen |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 9925 | + ", mWindowsFreezingScreen=" + mWindowsFreezingScreen |
| 9926 | + ", mClientFreezingScreen=" + mClientFreezingScreen); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9927 | return; |
| 9928 | } |
| 9929 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9930 | mDisplayFrozen = false; |
| 9931 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 9932 | mH.removeMessages(H.CLIENT_FREEZE_TIMEOUT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9933 | if (PROFILE_ORIENTATION) { |
| 9934 | Debug.stopMethodTracing(); |
| 9935 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 9936 | |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 9937 | boolean updateRotation = false; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9938 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 9939 | final DisplayContent displayContent = getDefaultDisplayContentLocked(); |
| 9940 | final int displayId = displayContent.getDisplayId(); |
| 9941 | ScreenRotationAnimation screenRotationAnimation = |
| 9942 | mAnimator.getScreenRotationAnimationLocked(displayId); |
| 9943 | if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null |
| 9944 | && screenRotationAnimation.hasScreenshot()) { |
Dianne Hackborn | 3ec891a | 2011-10-25 13:58:30 -0700 | [diff] [blame] | 9945 | if (DEBUG_ORIENTATION) Slog.i(TAG, "**** Dismissing screen rotation animation"); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9946 | // TODO(multidisplay): rotation on main screen only. |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 9947 | DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
| 9948 | if (screenRotationAnimation.dismiss(mFxSession, MAX_ANIMATION_DURATION, |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 9949 | mTransitionAnimationScale, displayInfo.logicalWidth, |
| 9950 | displayInfo.logicalHeight)) { |
Craig Mautner | 711f90a | 2012-07-03 18:43:52 -0700 | [diff] [blame] | 9951 | updateLayoutToAnimationLocked(); |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 9952 | } else { |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 9953 | screenRotationAnimation.kill(); |
| 9954 | screenRotationAnimation = null; |
| 9955 | mAnimator.setScreenRotationAnimationLocked(displayId, screenRotationAnimation); |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 9956 | updateRotation = true; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 9957 | } |
| 9958 | } else { |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 9959 | if (screenRotationAnimation != null) { |
| 9960 | screenRotationAnimation.kill(); |
| 9961 | screenRotationAnimation = null; |
| 9962 | mAnimator.setScreenRotationAnimationLocked(displayId, screenRotationAnimation); |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 9963 | } |
| 9964 | updateRotation = true; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 9965 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9966 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9967 | mInputMonitor.thawInputDispatchingLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9968 | |
Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 9969 | boolean configChanged; |
| 9970 | |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 9971 | // While the display is frozen we don't re-compute the orientation |
| 9972 | // to avoid inconsistent states. However, something interesting |
| 9973 | // could have actually changed during that time so re-evaluate it |
| 9974 | // now to catch that. |
Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 9975 | configChanged = updateOrientationFromAppTokensLocked(false); |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 9976 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9977 | // A little kludge: a lot could have happened while the |
| 9978 | // display was frozen, so now that we are coming back we |
| 9979 | // do a gc so that any remote references the system |
| 9980 | // processes holds on others can be released if they are |
| 9981 | // no longer needed. |
| 9982 | mH.removeMessages(H.FORCE_GC); |
| 9983 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 9984 | 2000); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9985 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9986 | mScreenFrozenLock.release(); |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 9987 | |
| 9988 | if (updateRotation) { |
| 9989 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation"); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 9990 | configChanged |= updateRotationUncheckedLocked(false); |
Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 9991 | } |
| 9992 | |
| 9993 | if (configChanged) { |
| 9994 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 9995 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9996 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9997 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 9998 | static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps, |
| 9999 | DisplayMetrics dm) { |
| 10000 | if (index < tokens.length) { |
| 10001 | String str = tokens[index]; |
| 10002 | if (str != null && str.length() > 0) { |
| 10003 | try { |
| 10004 | int val = Integer.parseInt(str); |
| 10005 | return val; |
| 10006 | } catch (Exception e) { |
| 10007 | } |
| 10008 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10009 | } |
| 10010 | if (defUnits == TypedValue.COMPLEX_UNIT_PX) { |
| 10011 | return defDps; |
| 10012 | } |
| 10013 | int val = (int)TypedValue.applyDimension(defUnits, defDps, dm); |
| 10014 | return val; |
| 10015 | } |
| 10016 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 10017 | void createWatermarkInTransaction() { |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10018 | if (mWatermark != null) { |
| 10019 | return; |
| 10020 | } |
| 10021 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10022 | File file = new File("/system/etc/setup.conf"); |
| 10023 | FileInputStream in = null; |
| 10024 | try { |
| 10025 | in = new FileInputStream(file); |
| 10026 | DataInputStream ind = new DataInputStream(in); |
| 10027 | String line = ind.readLine(); |
| 10028 | if (line != null) { |
| 10029 | String[] toks = line.split("%"); |
| 10030 | if (toks != null && toks.length > 0) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 10031 | mWatermark = new Watermark(getDefaultDisplayContentLocked().getDisplay(), |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 10032 | mRealDisplayMetrics, mFxSession, toks); |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10033 | } |
| 10034 | } |
| 10035 | } catch (FileNotFoundException e) { |
| 10036 | } catch (IOException e) { |
| 10037 | } finally { |
| 10038 | if (in != null) { |
| 10039 | try { |
| 10040 | in.close(); |
| 10041 | } catch (IOException e) { |
| 10042 | } |
| 10043 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10044 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10045 | } |
| 10046 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10047 | @Override |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 10048 | public void statusBarVisibilityChanged(int visibility) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 10049 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR) |
| 10050 | != PackageManager.PERMISSION_GRANTED) { |
| 10051 | throw new SecurityException("Caller does not hold permission " |
| 10052 | + android.Manifest.permission.STATUS_BAR); |
| 10053 | } |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 10054 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 10055 | synchronized (mWindowMap) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 10056 | mLastStatusBarVisibility = visibility; |
| 10057 | visibility = mPolicy.adjustSystemUiVisibilityLw(visibility); |
| 10058 | updateStatusBarVisibilityLocked(visibility); |
| 10059 | } |
| 10060 | } |
| 10061 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10062 | // TOOD(multidisplay): StatusBar on multiple screens? |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 10063 | void updateStatusBarVisibilityLocked(int visibility) { |
| 10064 | mInputManager.setSystemUiVisibility(visibility); |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 10065 | final WindowList windows = getDefaultWindowListLocked(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10066 | final int N = windows.size(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 10067 | for (int i = 0; i < N; i++) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10068 | WindowState ws = windows.get(i); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 10069 | try { |
| 10070 | int curValue = ws.mSystemUiVisibility; |
| 10071 | int diff = curValue ^ visibility; |
| 10072 | // We are only interested in differences of one of the |
| 10073 | // clearable flags... |
| 10074 | diff &= View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 10075 | // ...if it has actually been cleared. |
| 10076 | diff &= ~visibility; |
| 10077 | int newValue = (curValue&~diff) | (visibility&diff); |
| 10078 | if (newValue != curValue) { |
| 10079 | ws.mSeq++; |
| 10080 | ws.mSystemUiVisibility = newValue; |
| 10081 | } |
| 10082 | if (newValue != curValue || ws.mAttrs.hasSystemUiListeners) { |
| 10083 | ws.mClient.dispatchSystemUiVisibilityChanged(ws.mSeq, |
| 10084 | visibility, newValue, diff); |
| 10085 | } |
| 10086 | } catch (RemoteException e) { |
| 10087 | // so sorry |
| 10088 | } |
| 10089 | } |
| 10090 | } |
| 10091 | |
| 10092 | @Override |
| 10093 | public void reevaluateStatusBarVisibility() { |
| 10094 | synchronized (mWindowMap) { |
| 10095 | int visibility = mPolicy.adjustSystemUiVisibilityLw(mLastStatusBarVisibility); |
| 10096 | updateStatusBarVisibilityLocked(visibility); |
| 10097 | performLayoutAndPlaceSurfacesLocked(); |
| 10098 | } |
| 10099 | } |
| 10100 | |
| 10101 | @Override |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 10102 | public FakeWindow addFakeWindow(Looper looper, |
| 10103 | InputEventReceiver.Factory inputEventReceiverFactory, |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 10104 | String name, int windowType, int layoutParamsFlags, boolean canReceiveKeys, |
| 10105 | boolean hasFocus, boolean touchFullscreen) { |
| 10106 | synchronized (mWindowMap) { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 10107 | FakeWindowImpl fw = new FakeWindowImpl(this, looper, inputEventReceiverFactory, |
| 10108 | name, windowType, |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 10109 | layoutParamsFlags, canReceiveKeys, hasFocus, touchFullscreen); |
| 10110 | int i=0; |
| 10111 | while (i<mFakeWindows.size()) { |
| 10112 | if (mFakeWindows.get(i).mWindowLayer <= fw.mWindowLayer) { |
| 10113 | break; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 10114 | } |
| 10115 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 10116 | mFakeWindows.add(i, fw); |
| 10117 | mInputMonitor.updateInputWindowsLw(true); |
| 10118 | return fw; |
| 10119 | } |
| 10120 | } |
| 10121 | |
| 10122 | boolean removeFakeWindowLocked(FakeWindow window) { |
| 10123 | synchronized (mWindowMap) { |
| 10124 | if (mFakeWindows.remove(window)) { |
| 10125 | mInputMonitor.updateInputWindowsLw(true); |
| 10126 | return true; |
| 10127 | } |
| 10128 | return false; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 10129 | } |
| 10130 | } |
| 10131 | |
satok | e0a9941 | 2012-05-10 02:22:58 +0900 | [diff] [blame] | 10132 | // It is assumed that this method is called only by InputMethodManagerService. |
| 10133 | public void saveLastInputMethodWindowForTransition() { |
| 10134 | synchronized (mWindowMap) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10135 | // TODO(multidisplay): Pass in the displayID. |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 10136 | DisplayContent displayContent = getDefaultDisplayContentLocked(); |
satok | e0a9941 | 2012-05-10 02:22:58 +0900 | [diff] [blame] | 10137 | if (mInputMethodWindow != null) { |
| 10138 | mPolicy.setLastInputMethodWindowLw(mInputMethodWindow, mInputMethodTarget); |
| 10139 | } |
| 10140 | } |
| 10141 | } |
| 10142 | |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 10143 | @Override |
| 10144 | public boolean hasNavigationBar() { |
| 10145 | return mPolicy.hasNavigationBar(); |
| 10146 | } |
| 10147 | |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 10148 | public void lockNow() { |
| 10149 | mPolicy.lockNow(); |
| 10150 | } |
| 10151 | |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10152 | void dumpPolicyLocked(PrintWriter pw, String[] args, boolean dumpAll) { |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10153 | pw.println("WINDOW MANAGER POLICY STATE (dumpsys window policy)"); |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10154 | mPolicy.dump(" ", pw, args); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10155 | } |
| 10156 | |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10157 | void dumpTokensLocked(PrintWriter pw, boolean dumpAll) { |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10158 | pw.println("WINDOW MANAGER TOKENS (dumpsys window tokens)"); |
| 10159 | if (mTokenMap.size() > 0) { |
| 10160 | pw.println(" All tokens:"); |
| 10161 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 10162 | while (it.hasNext()) { |
| 10163 | WindowToken token = it.next(); |
| 10164 | pw.print(" Token "); pw.print(token.token); |
| 10165 | if (dumpAll) { |
| 10166 | pw.println(':'); |
| 10167 | token.dump(pw, " "); |
| 10168 | } else { |
| 10169 | pw.println(); |
| 10170 | } |
| 10171 | } |
| 10172 | } |
| 10173 | if (mWallpaperTokens.size() > 0) { |
| 10174 | pw.println(); |
| 10175 | pw.println(" Wallpaper tokens:"); |
| 10176 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 10177 | WindowToken token = mWallpaperTokens.get(i); |
| 10178 | pw.print(" Wallpaper #"); pw.print(i); |
| 10179 | pw.print(' '); pw.print(token); |
| 10180 | if (dumpAll) { |
| 10181 | pw.println(':'); |
| 10182 | token.dump(pw, " "); |
| 10183 | } else { |
| 10184 | pw.println(); |
| 10185 | } |
| 10186 | } |
| 10187 | } |
| 10188 | if (mAppTokens.size() > 0) { |
| 10189 | pw.println(); |
| 10190 | pw.println(" Application tokens in Z order:"); |
| 10191 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 10192 | pw.print(" App #"); pw.print(i); pw.println(": "); |
| 10193 | mAppTokens.get(i).dump(pw, " "); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10194 | } |
| 10195 | } |
| 10196 | if (mFinishedStarting.size() > 0) { |
| 10197 | pw.println(); |
| 10198 | pw.println(" Finishing start of application tokens:"); |
| 10199 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 10200 | WindowToken token = mFinishedStarting.get(i); |
| 10201 | pw.print(" Finished Starting #"); pw.print(i); |
| 10202 | pw.print(' '); pw.print(token); |
| 10203 | if (dumpAll) { |
| 10204 | pw.println(':'); |
| 10205 | token.dump(pw, " "); |
| 10206 | } else { |
| 10207 | pw.println(); |
| 10208 | } |
| 10209 | } |
| 10210 | } |
| 10211 | if (mExitingTokens.size() > 0) { |
| 10212 | pw.println(); |
| 10213 | pw.println(" Exiting tokens:"); |
| 10214 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 10215 | WindowToken token = mExitingTokens.get(i); |
| 10216 | pw.print(" Exiting #"); pw.print(i); |
| 10217 | pw.print(' '); pw.print(token); |
| 10218 | if (dumpAll) { |
| 10219 | pw.println(':'); |
| 10220 | token.dump(pw, " "); |
| 10221 | } else { |
| 10222 | pw.println(); |
| 10223 | } |
| 10224 | } |
| 10225 | } |
| 10226 | if (mExitingAppTokens.size() > 0) { |
| 10227 | pw.println(); |
| 10228 | pw.println(" Exiting application tokens:"); |
| 10229 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10230 | WindowToken token = mExitingAppTokens.get(i); |
| 10231 | pw.print(" Exiting App #"); pw.print(i); |
| 10232 | pw.print(' '); pw.print(token); |
| 10233 | if (dumpAll) { |
| 10234 | pw.println(':'); |
| 10235 | token.dump(pw, " "); |
| 10236 | } else { |
| 10237 | pw.println(); |
| 10238 | } |
| 10239 | } |
| 10240 | } |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 10241 | if (mAppTransitionRunning && mAnimatingAppTokens.size() > 0) { |
| 10242 | pw.println(); |
| 10243 | pw.println(" Application tokens during animation:"); |
| 10244 | for (int i=mAnimatingAppTokens.size()-1; i>=0; i--) { |
| 10245 | WindowToken token = mAnimatingAppTokens.get(i); |
| 10246 | pw.print(" App moving to bottom #"); pw.print(i); |
| 10247 | pw.print(' '); pw.print(token); |
| 10248 | if (dumpAll) { |
| 10249 | pw.println(':'); |
| 10250 | token.dump(pw, " "); |
| 10251 | } else { |
| 10252 | pw.println(); |
| 10253 | } |
| 10254 | } |
| 10255 | } |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 10256 | if (mOpeningApps.size() > 0 || mClosingApps.size() > 0) { |
| 10257 | pw.println(); |
| 10258 | if (mOpeningApps.size() > 0) { |
| 10259 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 10260 | } |
| 10261 | if (mClosingApps.size() > 0) { |
| 10262 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 10263 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10264 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10265 | } |
| 10266 | |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10267 | void dumpSessionsLocked(PrintWriter pw, boolean dumpAll) { |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10268 | pw.println("WINDOW MANAGER SESSIONS (dumpsys window sessions)"); |
| 10269 | if (mSessions.size() > 0) { |
| 10270 | Iterator<Session> it = mSessions.iterator(); |
| 10271 | while (it.hasNext()) { |
| 10272 | Session s = it.next(); |
| 10273 | pw.print(" Session "); pw.print(s); pw.println(':'); |
| 10274 | s.dump(pw, " "); |
| 10275 | } |
| 10276 | } |
| 10277 | } |
| 10278 | |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10279 | void dumpWindowsLocked(PrintWriter pw, boolean dumpAll, |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10280 | ArrayList<WindowState> windows) { |
| 10281 | pw.println("WINDOW MANAGER WINDOWS (dumpsys window windows)"); |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10282 | dumpWindowsNoHeaderLocked(pw, dumpAll, windows); |
| 10283 | } |
| 10284 | |
| 10285 | void dumpWindowsNoHeaderLocked(PrintWriter pw, boolean dumpAll, |
| 10286 | ArrayList<WindowState> windows) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10287 | int j = 0; |
| 10288 | final AllWindowsIterator iterator = new AllWindowsIterator(REVERSE_ITERATOR); |
| 10289 | while (iterator.hasNext()) { |
| 10290 | final WindowState w = iterator.next(); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10291 | if (windows == null || windows.contains(w)) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10292 | pw.print(" Window #"); pw.print(j++); pw.print(' '); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10293 | pw.print(w); pw.println(":"); |
Dianne Hackborn | 8962028 | 2011-09-11 12:47:45 -0700 | [diff] [blame] | 10294 | w.dump(pw, " ", dumpAll || windows != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10295 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10296 | } |
| 10297 | if (mInputMethodDialogs.size() > 0) { |
| 10298 | pw.println(); |
| 10299 | pw.println(" Input method dialogs:"); |
| 10300 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 10301 | WindowState w = mInputMethodDialogs.get(i); |
| 10302 | if (windows == null || windows.contains(w)) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10303 | 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] | 10304 | } |
| 10305 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10306 | } |
| 10307 | if (mPendingRemove.size() > 0) { |
| 10308 | pw.println(); |
| 10309 | pw.println(" Remove pending for:"); |
| 10310 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 10311 | WindowState w = mPendingRemove.get(i); |
| 10312 | if (windows == null || windows.contains(w)) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10313 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10314 | pw.print(w); |
| 10315 | if (dumpAll) { |
| 10316 | pw.println(":"); |
| 10317 | w.dump(pw, " ", true); |
| 10318 | } else { |
| 10319 | pw.println(); |
| 10320 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10321 | } |
| 10322 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10323 | } |
| 10324 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 10325 | pw.println(); |
| 10326 | pw.println(" Windows force removing:"); |
| 10327 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 10328 | WindowState w = mForceRemoves.get(i); |
| 10329 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 10330 | pw.print(w); |
| 10331 | if (dumpAll) { |
| 10332 | pw.println(":"); |
| 10333 | w.dump(pw, " ", true); |
| 10334 | } else { |
| 10335 | pw.println(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10336 | } |
| 10337 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10338 | } |
| 10339 | if (mDestroySurface.size() > 0) { |
| 10340 | pw.println(); |
| 10341 | pw.println(" Windows waiting to destroy their surface:"); |
| 10342 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 10343 | WindowState w = mDestroySurface.get(i); |
| 10344 | if (windows == null || windows.contains(w)) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10345 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10346 | pw.print(w); |
| 10347 | if (dumpAll) { |
| 10348 | pw.println(":"); |
| 10349 | w.dump(pw, " ", true); |
| 10350 | } else { |
| 10351 | pw.println(); |
| 10352 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10353 | } |
| 10354 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10355 | } |
| 10356 | if (mLosingFocus.size() > 0) { |
| 10357 | pw.println(); |
| 10358 | pw.println(" Windows losing focus:"); |
| 10359 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 10360 | WindowState w = mLosingFocus.get(i); |
| 10361 | if (windows == null || windows.contains(w)) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10362 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10363 | pw.print(w); |
| 10364 | if (dumpAll) { |
| 10365 | pw.println(":"); |
| 10366 | w.dump(pw, " ", true); |
| 10367 | } else { |
| 10368 | pw.println(); |
| 10369 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10370 | } |
| 10371 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10372 | } |
| 10373 | if (mResizingWindows.size() > 0) { |
| 10374 | pw.println(); |
| 10375 | pw.println(" Windows waiting to resize:"); |
| 10376 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 10377 | WindowState w = mResizingWindows.get(i); |
| 10378 | if (windows == null || windows.contains(w)) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10379 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10380 | pw.print(w); |
| 10381 | if (dumpAll) { |
| 10382 | pw.println(":"); |
| 10383 | w.dump(pw, " ", true); |
| 10384 | } else { |
| 10385 | pw.println(); |
| 10386 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10387 | } |
| 10388 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10389 | } |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 10390 | if (mWaitingForDrawn.size() > 0) { |
| 10391 | pw.println(); |
| 10392 | pw.println(" Clients waiting for these windows to be drawn:"); |
| 10393 | for (int i=mWaitingForDrawn.size()-1; i>=0; i--) { |
| 10394 | Pair<WindowState, IRemoteCallback> pair = mWaitingForDrawn.get(i); |
| 10395 | pw.print(" Waiting #"); pw.print(i); pw.print(' '); pw.print(pair.first); |
| 10396 | pw.print(": "); pw.println(pair.second); |
| 10397 | } |
| 10398 | } |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 10399 | pw.println(" DisplayContents"); |
Jeff Brown | e215f26 | 2012-09-10 16:01:14 -0700 | [diff] [blame] | 10400 | if (mDisplayReady) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10401 | DisplayContentsIterator dCIterator = new DisplayContentsIterator(); |
| 10402 | while (dCIterator.hasNext()) { |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 10403 | dCIterator.next().dump(" ", pw); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10404 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10405 | } else { |
| 10406 | pw.println(" NO DISPLAY"); |
| 10407 | } |
| 10408 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 10409 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 10410 | if (mLastFocus != mCurrentFocus) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10411 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10412 | } |
| 10413 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 10414 | if (mInputMethodTarget != null) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10415 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10416 | } |
| 10417 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 10418 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| 10419 | if (dumpAll) { |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 10420 | pw.print(" mSystemDecorRect="); pw.print(mSystemDecorRect.toShortString()); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 10421 | pw.print(" mSystemDecorLayer="); pw.print(mSystemDecorLayer); |
| 10422 | pw.print(" mScreenRecr="); pw.println(mScreenRect.toShortString()); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 10423 | if (mLastStatusBarVisibility != 0) { |
| 10424 | pw.print(" mLastStatusBarVisibility=0x"); |
| 10425 | pw.println(Integer.toHexString(mLastStatusBarVisibility)); |
| 10426 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10427 | if (mInputMethodWindow != null) { |
| 10428 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
| 10429 | } |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 10430 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10431 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 10432 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 10433 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 10434 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10435 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 10436 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
| 10437 | if (mInputMethodAnimLayerAdjustment != 0 || |
| 10438 | mWallpaperAnimLayerAdjustment != 0) { |
| 10439 | pw.print(" mInputMethodAnimLayerAdjustment="); |
| 10440 | pw.print(mInputMethodAnimLayerAdjustment); |
| 10441 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 10442 | pw.println(mWallpaperAnimLayerAdjustment); |
| 10443 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10444 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 10445 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 10446 | if (needsLayout()) { |
| 10447 | pw.print(" layoutNeeded on displays="); |
| 10448 | DisplayContentsIterator dcIterator = new DisplayContentsIterator(); |
| 10449 | while (dcIterator.hasNext()) { |
| 10450 | final DisplayContent displayContent = dcIterator.next(); |
| 10451 | if (displayContent.layoutNeeded) { |
| 10452 | pw.print(displayContent.getDisplayId()); |
| 10453 | } |
| 10454 | } |
| 10455 | pw.println(); |
| 10456 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 10457 | pw.print(" mTransactionSequence="); pw.println(mTransactionSequence); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10458 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 10459 | pw.print(" windows="); pw.print(mWindowsFreezingScreen); |
| 10460 | pw.print(" client="); pw.print(mClientFreezingScreen); |
| 10461 | pw.print(" apps="); pw.print(mAppsFreezingScreen); |
| 10462 | pw.print(" waitingForConfig="); pw.println(mWaitingForConfig); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10463 | pw.print(" mRotation="); pw.print(mRotation); |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 10464 | pw.print(" mAltOrientation="); pw.println(mAltOrientation); |
Craig Mautner | f20588f | 2012-04-11 17:06:21 -0700 | [diff] [blame] | 10465 | pw.print(" mLastWindowForcedOrientation="); pw.print(mLastWindowForcedOrientation); |
Dianne Hackborn | bc7386c | 2011-06-06 17:27:54 -0700 | [diff] [blame] | 10466 | pw.print(" mForcedAppOrientation="); pw.println(mForcedAppOrientation); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 10467 | pw.print(" mDeferredRotationPauseCount="); pw.println(mDeferredRotationPauseCount); |
Dianne Hackborn | 4dcece8 | 2012-02-10 14:50:32 -0800 | [diff] [blame] | 10468 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 10469 | pw.print(" mTransitionWindowAnimationScale="); pw.print(mTransitionAnimationScale); |
Chet Haase | c38fa1f | 2012-02-01 16:37:46 -0800 | [diff] [blame] | 10470 | pw.print(" mAnimatorDurationScale="); pw.println(mAnimatorDurationScale); |
Dianne Hackborn | 4dcece8 | 2012-02-10 14:50:32 -0800 | [diff] [blame] | 10471 | pw.print(" mTraversalScheduled="); pw.print(mTraversalScheduled); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 10472 | pw.print(" mNextAppTransition=0x"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10473 | pw.print(Integer.toHexString(mNextAppTransition)); |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 10474 | pw.print(" mAppTransitionReady="); pw.println(mAppTransitionReady); |
| 10475 | pw.print(" mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 10476 | pw.print(" mAppTransitionTimeout="); pw.println(mAppTransitionTimeout); |
| 10477 | if (mNextAppTransitionType != ActivityOptions.ANIM_NONE) { |
| 10478 | pw.print(" mNextAppTransitionType="); pw.println(mNextAppTransitionType); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10479 | } |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 10480 | switch (mNextAppTransitionType) { |
| 10481 | case ActivityOptions.ANIM_CUSTOM: |
| 10482 | pw.print(" mNextAppTransitionPackage="); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 10483 | pw.println(mNextAppTransitionPackage); |
| 10484 | pw.print(" mNextAppTransitionEnter=0x"); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 10485 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 10486 | pw.print(" mNextAppTransitionExit=0x"); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 10487 | pw.println(Integer.toHexString(mNextAppTransitionExit)); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 10488 | break; |
| 10489 | case ActivityOptions.ANIM_SCALE_UP: |
| 10490 | pw.print(" mNextAppTransitionStartX="); pw.print(mNextAppTransitionStartX); |
| 10491 | pw.print(" mNextAppTransitionStartY="); |
| 10492 | pw.println(mNextAppTransitionStartY); |
| 10493 | pw.print(" mNextAppTransitionStartWidth="); |
| 10494 | pw.print(mNextAppTransitionStartWidth); |
| 10495 | pw.print(" mNextAppTransitionStartHeight="); |
| 10496 | pw.println(mNextAppTransitionStartHeight); |
| 10497 | break; |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 10498 | case ActivityOptions.ANIM_THUMBNAIL_SCALE_UP: |
| 10499 | case ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN: |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 10500 | pw.print(" mNextAppTransitionThumbnail="); |
| 10501 | pw.print(mNextAppTransitionThumbnail); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 10502 | pw.print(" mNextAppTransitionStartX="); |
| 10503 | pw.print(mNextAppTransitionStartX); |
| 10504 | pw.print(" mNextAppTransitionStartY="); |
| 10505 | pw.println(mNextAppTransitionStartY); |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 10506 | pw.print(" mNextAppTransitionScaleUp="); pw.println(mNextAppTransitionScaleUp); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 10507 | break; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 10508 | } |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 10509 | if (mNextAppTransitionCallback != null) { |
| 10510 | pw.print(" mNextAppTransitionCallback="); |
| 10511 | pw.println(mNextAppTransitionCallback); |
| 10512 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10513 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 10514 | pw.print(" mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 10515 | pw.println(" Window Animator:"); |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 10516 | mAnimator.dumpLocked(pw, " ", dumpAll); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10517 | } |
| 10518 | } |
| 10519 | |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10520 | boolean dumpWindows(PrintWriter pw, String name, String[] args, |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10521 | int opti, boolean dumpAll) { |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 10522 | WindowList windows = new WindowList(); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10523 | if ("visible".equals(name)) { |
| 10524 | synchronized(mWindowMap) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10525 | final AllWindowsIterator iterator = new AllWindowsIterator(REVERSE_ITERATOR); |
| 10526 | while (iterator.hasNext()) { |
| 10527 | final WindowState w = iterator.next(); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 10528 | if (w.mWinAnimator.mSurfaceShown) { |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10529 | windows.add(w); |
| 10530 | } |
| 10531 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10532 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10533 | } else { |
| 10534 | int objectId = 0; |
| 10535 | // See if this is an object ID. |
| 10536 | try { |
| 10537 | objectId = Integer.parseInt(name, 16); |
| 10538 | name = null; |
| 10539 | } catch (RuntimeException e) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10540 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10541 | synchronized(mWindowMap) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10542 | final AllWindowsIterator iterator = new AllWindowsIterator(REVERSE_ITERATOR); |
| 10543 | while (iterator.hasNext()) { |
| 10544 | final WindowState w = iterator.next(); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10545 | if (name != null) { |
| 10546 | if (w.mAttrs.getTitle().toString().contains(name)) { |
| 10547 | windows.add(w); |
| 10548 | } |
| 10549 | } else if (System.identityHashCode(w) == objectId) { |
| 10550 | windows.add(w); |
| 10551 | } |
| 10552 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10553 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10554 | } |
| 10555 | |
| 10556 | if (windows.size() <= 0) { |
| 10557 | return false; |
| 10558 | } |
| 10559 | |
| 10560 | synchronized(mWindowMap) { |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10561 | dumpWindowsLocked(pw, dumpAll, windows); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10562 | } |
| 10563 | return true; |
| 10564 | } |
| 10565 | |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10566 | void dumpLastANRLocked(PrintWriter pw) { |
| 10567 | pw.println("WINDOW MANAGER LAST ANR (dumpsys window lastanr)"); |
| 10568 | if (mLastANRState == null) { |
| 10569 | pw.println(" <no ANR has occurred since boot>"); |
| 10570 | } else { |
| 10571 | pw.println(mLastANRState); |
| 10572 | } |
| 10573 | } |
| 10574 | |
| 10575 | /** |
| 10576 | * Saves information about the state of the window manager at |
| 10577 | * the time an ANR occurred before anything else in the system changes |
| 10578 | * in response. |
| 10579 | * |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 10580 | * @param appWindowToken The application that ANR'd, may be null. |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10581 | * @param windowState The window that ANR'd, may be null. |
| 10582 | */ |
| 10583 | public void saveANRStateLocked(AppWindowToken appWindowToken, WindowState windowState) { |
| 10584 | StringWriter sw = new StringWriter(); |
| 10585 | PrintWriter pw = new PrintWriter(sw); |
| 10586 | pw.println(" ANR time: " + DateFormat.getInstance().format(new Date())); |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 10587 | if (appWindowToken != null) { |
| 10588 | pw.println(" Application at fault: " + appWindowToken.stringName); |
| 10589 | } |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10590 | if (windowState != null) { |
| 10591 | pw.println(" Window at fault: " + windowState.mAttrs.getTitle()); |
| 10592 | } |
| 10593 | pw.println(); |
| 10594 | dumpWindowsNoHeaderLocked(pw, true, null); |
| 10595 | pw.close(); |
| 10596 | mLastANRState = sw.toString(); |
| 10597 | } |
| 10598 | |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10599 | @Override |
| 10600 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 10601 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 10602 | != PackageManager.PERMISSION_GRANTED) { |
| 10603 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 10604 | + Binder.getCallingPid() |
| 10605 | + ", uid=" + Binder.getCallingUid()); |
| 10606 | return; |
| 10607 | } |
| 10608 | |
| 10609 | boolean dumpAll = false; |
| 10610 | |
| 10611 | int opti = 0; |
| 10612 | while (opti < args.length) { |
| 10613 | String opt = args[opti]; |
| 10614 | if (opt == null || opt.length() <= 0 || opt.charAt(0) != '-') { |
| 10615 | break; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10616 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10617 | opti++; |
| 10618 | if ("-a".equals(opt)) { |
| 10619 | dumpAll = true; |
| 10620 | } else if ("-h".equals(opt)) { |
| 10621 | pw.println("Window manager dump options:"); |
| 10622 | pw.println(" [-a] [-h] [cmd] ..."); |
| 10623 | pw.println(" cmd may be one of:"); |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10624 | pw.println(" l[astanr]: last ANR information"); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10625 | pw.println(" p[policy]: policy state"); |
| 10626 | pw.println(" s[essions]: active sessions"); |
| 10627 | pw.println(" t[okens]: token list"); |
| 10628 | pw.println(" w[indows]: window list"); |
| 10629 | pw.println(" cmd may also be a NAME to dump windows. NAME may"); |
| 10630 | pw.println(" be a partial substring in a window name, a"); |
| 10631 | pw.println(" Window hex object identifier, or"); |
| 10632 | pw.println(" \"all\" for all windows, or"); |
| 10633 | pw.println(" \"visible\" for the visible windows."); |
| 10634 | pw.println(" -a: include all available server state."); |
| 10635 | return; |
Dianne Hackborn | 87fc308 | 2010-12-03 13:09:12 -0800 | [diff] [blame] | 10636 | } else { |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10637 | pw.println("Unknown argument: " + opt + "; use -h for help"); |
Dianne Hackborn | 87fc308 | 2010-12-03 13:09:12 -0800 | [diff] [blame] | 10638 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10639 | } |
| 10640 | |
| 10641 | // Is the caller requesting to dump a particular piece of data? |
| 10642 | if (opti < args.length) { |
| 10643 | String cmd = args[opti]; |
| 10644 | opti++; |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10645 | if ("lastanr".equals(cmd) || "l".equals(cmd)) { |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10646 | synchronized(mWindowMap) { |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10647 | dumpLastANRLocked(pw); |
| 10648 | } |
| 10649 | return; |
| 10650 | } else if ("policy".equals(cmd) || "p".equals(cmd)) { |
| 10651 | synchronized(mWindowMap) { |
| 10652 | dumpPolicyLocked(pw, args, true); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10653 | } |
| 10654 | return; |
| 10655 | } else if ("sessions".equals(cmd) || "s".equals(cmd)) { |
| 10656 | synchronized(mWindowMap) { |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10657 | dumpSessionsLocked(pw, true); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10658 | } |
| 10659 | return; |
| 10660 | } else if ("tokens".equals(cmd) || "t".equals(cmd)) { |
| 10661 | synchronized(mWindowMap) { |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10662 | dumpTokensLocked(pw, true); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10663 | } |
| 10664 | return; |
| 10665 | } else if ("windows".equals(cmd) || "w".equals(cmd)) { |
| 10666 | synchronized(mWindowMap) { |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10667 | dumpWindowsLocked(pw, true, null); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10668 | } |
| 10669 | return; |
| 10670 | } else if ("all".equals(cmd) || "a".equals(cmd)) { |
| 10671 | synchronized(mWindowMap) { |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10672 | dumpWindowsLocked(pw, true, null); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10673 | } |
| 10674 | return; |
| 10675 | } else { |
| 10676 | // Dumping a single name? |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10677 | if (!dumpWindows(pw, cmd, args, opti, dumpAll)) { |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10678 | pw.println("Bad window command, or no windows match: " + cmd); |
| 10679 | pw.println("Use -h for help."); |
| 10680 | } |
| 10681 | return; |
| 10682 | } |
| 10683 | } |
| 10684 | |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10685 | synchronized(mWindowMap) { |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 10686 | pw.println(); |
| 10687 | if (dumpAll) { |
| 10688 | pw.println("-------------------------------------------------------------------------------"); |
| 10689 | } |
| 10690 | dumpLastANRLocked(pw); |
| 10691 | pw.println(); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10692 | if (dumpAll) { |
| 10693 | pw.println("-------------------------------------------------------------------------------"); |
| 10694 | } |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10695 | dumpPolicyLocked(pw, args, dumpAll); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10696 | pw.println(); |
| 10697 | if (dumpAll) { |
| 10698 | pw.println("-------------------------------------------------------------------------------"); |
| 10699 | } |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10700 | dumpSessionsLocked(pw, dumpAll); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10701 | pw.println(); |
| 10702 | if (dumpAll) { |
| 10703 | pw.println("-------------------------------------------------------------------------------"); |
| 10704 | } |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10705 | dumpTokensLocked(pw, dumpAll); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 10706 | pw.println(); |
| 10707 | if (dumpAll) { |
| 10708 | pw.println("-------------------------------------------------------------------------------"); |
| 10709 | } |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 10710 | dumpWindowsLocked(pw, dumpAll, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10711 | } |
| 10712 | } |
| 10713 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10714 | // 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] | 10715 | public void monitor() { |
| 10716 | synchronized (mWindowMap) { } |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 10717 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10718 | |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 10719 | public interface OnHardKeyboardStatusChangeListener { |
| 10720 | public void onHardKeyboardStatusChange(boolean available, boolean enabled); |
| 10721 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 10722 | |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 10723 | void debugLayoutRepeats(final String msg, int pendingLayoutChanges) { |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 10724 | if (mLayoutRepeatCount >= LAYOUT_REPEAT_THRESHOLD) { |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 10725 | Slog.v(TAG, "Layouts looping: " + msg + ", mPendingLayoutChanges = 0x" + |
| 10726 | Integer.toHexString(pendingLayoutChanges)); |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 10727 | } |
| 10728 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10729 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 10730 | public void createDisplayContentLocked(final Display display) { |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 10731 | if (display == null) { |
| 10732 | throw new IllegalArgumentException("getDisplayContent: display must not be null"); |
| 10733 | } |
| 10734 | final DisplayContent displayContent = new DisplayContent(display); |
| 10735 | mDisplayContents.put(display.getDisplayId(), displayContent); |
| 10736 | } |
| 10737 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 10738 | public DisplayContent getDisplayContentLocked(final int displayId) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10739 | DisplayContent displayContent = mDisplayContents.get(displayId); |
| 10740 | if (displayContent == null) { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 10741 | displayContent = new DisplayContent(mDisplayManager.getDisplay(displayId)); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10742 | mDisplayContents.put(displayId, displayContent); |
| 10743 | } |
| 10744 | return displayContent; |
| 10745 | } |
| 10746 | |
| 10747 | class DisplayContentsIterator implements Iterator<DisplayContent> { |
| 10748 | private int cur; |
| 10749 | |
| 10750 | @Override |
| 10751 | public boolean hasNext() { |
| 10752 | return cur < mDisplayContents.size(); |
| 10753 | } |
| 10754 | |
| 10755 | @Override |
| 10756 | public DisplayContent next() { |
| 10757 | if (hasNext()) { |
| 10758 | return mDisplayContents.valueAt(cur++); |
| 10759 | } |
| 10760 | throw new NoSuchElementException(); |
| 10761 | } |
| 10762 | |
| 10763 | @Override |
| 10764 | public void remove() { |
| 10765 | throw new IllegalArgumentException("AllDisplayContentIterator.remove not implemented"); |
| 10766 | } |
| 10767 | } |
| 10768 | |
Jeff Brown | 83d616a | 2012-09-09 20:33:43 -0700 | [diff] [blame] | 10769 | final static boolean REVERSE_ITERATOR = true; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10770 | class AllWindowsIterator implements Iterator<WindowState> { |
| 10771 | private DisplayContent mDisplayContent; |
| 10772 | private DisplayContentsIterator mDisplayContentsIterator; |
| 10773 | private WindowList mWindowList; |
| 10774 | private int mWindowListIndex; |
| 10775 | private boolean mReverse; |
| 10776 | |
| 10777 | AllWindowsIterator() { |
| 10778 | mDisplayContentsIterator = new DisplayContentsIterator(); |
| 10779 | mDisplayContent = mDisplayContentsIterator.next(); |
| 10780 | mWindowList = mDisplayContent.getWindowList(); |
| 10781 | } |
| 10782 | |
| 10783 | AllWindowsIterator(boolean reverse) { |
| 10784 | this(); |
| 10785 | mReverse = reverse; |
| 10786 | mWindowListIndex = reverse ? mWindowList.size() - 1 : 0; |
| 10787 | } |
| 10788 | |
| 10789 | @Override |
| 10790 | public boolean hasNext() { |
| 10791 | if (mReverse) { |
| 10792 | return mWindowListIndex >= 0; |
| 10793 | } |
| 10794 | return mWindowListIndex < mWindowList.size(); |
| 10795 | } |
| 10796 | |
| 10797 | @Override |
| 10798 | public WindowState next() { |
| 10799 | if (hasNext()) { |
| 10800 | WindowState win = mWindowList.get(mWindowListIndex); |
| 10801 | if (mReverse) { |
| 10802 | mWindowListIndex--; |
| 10803 | if (mWindowListIndex < 0 && mDisplayContentsIterator.hasNext()) { |
| 10804 | mDisplayContent = mDisplayContentsIterator.next(); |
| 10805 | mWindowList = mDisplayContent.getWindowList(); |
| 10806 | mWindowListIndex = mWindowList.size() - 1; |
| 10807 | } |
| 10808 | } else { |
| 10809 | mWindowListIndex++; |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 10810 | if (mWindowListIndex >= mWindowList.size() |
| 10811 | && mDisplayContentsIterator.hasNext()) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10812 | mDisplayContent = mDisplayContentsIterator.next(); |
| 10813 | mWindowList = mDisplayContent.getWindowList(); |
| 10814 | mWindowListIndex = 0; |
| 10815 | } |
| 10816 | } |
| 10817 | return win; |
| 10818 | } |
| 10819 | throw new NoSuchElementException(); |
| 10820 | } |
| 10821 | |
| 10822 | @Override |
| 10823 | public void remove() { |
| 10824 | throw new IllegalArgumentException("AllWindowsIterator.remove not implemented"); |
| 10825 | } |
| 10826 | } |
| 10827 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 10828 | public DisplayContent getDefaultDisplayContentLocked() { |
| 10829 | return getDisplayContentLocked(Display.DEFAULT_DISPLAY); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10830 | } |
| 10831 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 10832 | public WindowList getDefaultWindowListLocked() { |
| 10833 | return getDefaultDisplayContentLocked().getWindowList(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10834 | } |
| 10835 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 10836 | public DisplayInfo getDefaultDisplayInfoLocked() { |
| 10837 | return getDefaultDisplayContentLocked().getDisplayInfo(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 10838 | } |
| 10839 | |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 10840 | public WindowList getWindowListLocked(final Display display) { |
| 10841 | return getDisplayContentLocked(display.getDisplayId()).getWindowList(); |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 10842 | } |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 10843 | |
| 10844 | @Override |
| 10845 | public void onDisplayAdded(int displayId) { |
| 10846 | mH.sendMessage(mH.obtainMessage(H.DO_DISPLAY_ADDED, displayId, 0)); |
| 10847 | } |
| 10848 | |
| 10849 | private void handleDisplayAddedLocked(int displayId) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 10850 | createDisplayContentLocked(mDisplayManager.getDisplay(displayId)); |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 10851 | displayReady(displayId); |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 10852 | } |
| 10853 | |
| 10854 | @Override |
| 10855 | public void onDisplayRemoved(int displayId) { |
| 10856 | mH.sendMessage(mH.obtainMessage(H.DO_DISPLAY_REMOVED, displayId, 0)); |
| 10857 | } |
| 10858 | |
| 10859 | private void handleDisplayRemovedLocked(int displayId) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 10860 | final DisplayContent displayContent = getDisplayContentLocked(displayId); |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 10861 | mDisplayContents.delete(displayId); |
| 10862 | WindowList windows = displayContent.getWindowList(); |
| 10863 | for (int i = windows.size() - 1; i >= 0; --i) { |
| 10864 | final WindowState win = windows.get(i); |
| 10865 | removeWindowLocked(win.mSession, win); |
| 10866 | } |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 10867 | mAnimator.removeDisplayLocked(displayId); |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 10868 | } |
| 10869 | |
| 10870 | @Override |
| 10871 | public void onDisplayChanged(int displayId) { |
| 10872 | mH.sendMessage(mH.obtainMessage(H.DO_DISPLAY_CHANGED, displayId, 0)); |
| 10873 | } |
| 10874 | |
| 10875 | private void handleDisplayChangedLocked(int displayId) { |
Craig Mautner | 5c0e78c | 2012-09-12 16:45:36 -0700 | [diff] [blame] | 10876 | final DisplayContent displayContent = getDisplayContentLocked(displayId); |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 10877 | if (displayContent != null) { |
| 10878 | displayContent.updateDisplayInfo(); |
| 10879 | } |
| 10880 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10881 | } |