The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1 | /* |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2 | * |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | package com.android.internal.policy.impl; |
| 17 | |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 18 | import android.app.ActivityManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 19 | import android.app.ActivityManagerNative; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 20 | import android.app.AppOpsManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 21 | import android.app.IUiModeManager; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 22 | import android.app.ProgressDialog; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 23 | import android.app.SearchManager; |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 24 | import android.app.StatusBarManager; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 25 | import android.app.UiModeManager; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 26 | import android.content.ActivityNotFoundException; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 27 | import android.content.BroadcastReceiver; |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 28 | import android.content.ComponentName; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 29 | import android.content.ContentResolver; |
| 30 | import android.content.Context; |
| 31 | import android.content.Intent; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 32 | import android.content.IntentFilter; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 33 | import android.content.ServiceConnection; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 34 | import android.content.pm.ActivityInfo; |
| 35 | import android.content.pm.PackageManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 36 | import android.content.pm.ResolveInfo; |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 37 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 38 | import android.content.res.Configuration; |
| 39 | import android.content.res.Resources; |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 40 | import android.content.res.TypedArray; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 41 | import android.database.ContentObserver; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 42 | import android.graphics.PixelFormat; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 43 | import android.graphics.Rect; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 44 | import android.media.AudioManager; |
| 45 | import android.media.IAudioService; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 46 | import android.media.Ringtone; |
| 47 | import android.media.RingtoneManager; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 48 | import android.os.Bundle; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 49 | import android.os.FactoryTest; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 50 | import android.os.Handler; |
| 51 | import android.os.IBinder; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 52 | import android.os.IRemoteCallback; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 53 | import android.os.Looper; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 54 | import android.os.Message; |
| 55 | import android.os.Messenger; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 56 | import android.os.PowerManager; |
| 57 | import android.os.RemoteException; |
| 58 | import android.os.ServiceManager; |
| 59 | import android.os.SystemClock; |
| 60 | import android.os.SystemProperties; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 61 | import android.os.UEventObserver; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 62 | import android.os.UserHandle; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 63 | import android.os.Vibrator; |
| 64 | import android.provider.Settings; |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 65 | import android.service.dreams.DreamService; |
| 66 | import android.service.dreams.IDreamManager; |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 67 | import android.util.DisplayMetrics; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 68 | import android.util.EventLog; |
| 69 | import android.util.Log; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 70 | import android.util.Slog; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 71 | import android.util.SparseArray; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 72 | import android.view.Display; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 73 | import android.view.Gravity; |
| 74 | import android.view.HapticFeedbackConstants; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 75 | import android.view.IApplicationToken; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 76 | import android.view.IWindowManager; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 77 | import android.view.InputChannel; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 78 | import android.view.InputDevice; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 79 | import android.view.InputEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 80 | import android.view.InputEventReceiver; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 81 | import android.view.KeyCharacterMap; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 82 | import android.view.KeyCharacterMap.FallbackAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 83 | import android.view.KeyEvent; |
| 84 | import android.view.MotionEvent; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 85 | import android.view.Surface; |
| 86 | import android.view.View; |
| 87 | import android.view.ViewConfiguration; |
| 88 | import android.view.Window; |
| 89 | import android.view.WindowManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 90 | import android.view.WindowManagerGlobal; |
| 91 | import android.view.WindowManagerPolicy; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 92 | import android.view.accessibility.AccessibilityEvent; |
| 93 | import android.view.animation.Animation; |
| 94 | import android.view.animation.AnimationUtils; |
| 95 | |
| 96 | import com.android.internal.R; |
| 97 | import com.android.internal.policy.PolicyManager; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 98 | import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 99 | import com.android.internal.statusbar.IStatusBarService; |
| 100 | import com.android.internal.telephony.ITelephony; |
| 101 | import com.android.internal.widget.PointerLocationView; |
| 102 | |
| 103 | import java.io.File; |
| 104 | import java.io.FileReader; |
| 105 | import java.io.IOException; |
| 106 | import java.io.PrintWriter; |
| 107 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 108 | import static android.view.WindowManager.LayoutParams.*; |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 109 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT; |
| 110 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN; |
| 111 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 112 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 113 | /** |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 114 | * WindowManagerPolicy implementation for the Android phone UI. This |
| 115 | * introduces a new method suffix, Lp, for an internal lock of the |
| 116 | * PhoneWindowManager. This is used to protect some internal state, and |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 117 | * can be acquired with either the Lw and Li lock held, so has the restrictions |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 118 | * of both of those when held. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 119 | */ |
| 120 | public class PhoneWindowManager implements WindowManagerPolicy { |
| 121 | static final String TAG = "WindowManager"; |
| 122 | static final boolean DEBUG = false; |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 123 | static final boolean localLOGV = false; |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 124 | static final boolean DEBUG_LAYOUT = false; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 125 | static final boolean DEBUG_INPUT = false; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 126 | static final boolean DEBUG_STARTING_WINDOW = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 127 | static final boolean SHOW_STARTING_ANIMATIONS = true; |
| 128 | static final boolean SHOW_PROCESSES_ON_ALT_MENU = false; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 129 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 130 | // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key. |
| 131 | // No longer recommended for desk docks; still useful in car docks. |
| 132 | static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true; |
| 133 | static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false; |
| 134 | |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 135 | static final int LONG_PRESS_POWER_NOTHING = 0; |
| 136 | static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; |
| 137 | static final int LONG_PRESS_POWER_SHUT_OFF = 2; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 138 | static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3; |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 139 | |
| 140 | // These need to match the documentation/constant in |
| 141 | // core/res/res/values/config.xml |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 142 | static final int LONG_PRESS_HOME_NOTHING = 0; |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 143 | static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 144 | static final int LONG_PRESS_HOME_ASSIST = 2; |
| 145 | |
| 146 | static final int DOUBLE_TAP_HOME_NOTHING = 0; |
| 147 | static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 148 | |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 149 | static final int APPLICATION_MEDIA_SUBLAYER = -2; |
| 150 | static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 151 | static final int APPLICATION_PANEL_SUBLAYER = 1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 152 | static final int APPLICATION_SUB_PANEL_SUBLAYER = 2; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 153 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 154 | static public final String SYSTEM_DIALOG_REASON_KEY = "reason"; |
| 155 | static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; |
| 156 | static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 157 | static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 158 | static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 159 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 160 | /** |
| 161 | * These are the system UI flags that, when changing, can cause the layout |
| 162 | * of the screen to change. |
| 163 | */ |
| 164 | static final int SYSTEM_UI_CHANGING_LAYOUT = |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 165 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
| 166 | | View.SYSTEM_UI_FLAG_FULLSCREEN |
| 167 | | View.SYSTEM_UI_FLAG_TRANSPARENT_STATUS |
| 168 | | View.SYSTEM_UI_FLAG_TRANSPARENT_NAVIGATION; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 169 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 170 | /** |
| 171 | * Keyguard stuff |
| 172 | */ |
| 173 | private WindowState mKeyguardScrim; |
| 174 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 175 | /* Table of Application Launch keys. Maps from key codes to intent categories. |
| 176 | * |
| 177 | * These are special keys that are used to launch particular kinds of applications, |
| 178 | * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C) |
| 179 | * usage page. We don't support quite that many yet... |
| 180 | */ |
| 181 | static SparseArray<String> sApplicationLaunchKeyCategories; |
| 182 | static { |
| 183 | sApplicationLaunchKeyCategories = new SparseArray<String>(); |
| 184 | sApplicationLaunchKeyCategories.append( |
| 185 | KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER); |
| 186 | sApplicationLaunchKeyCategories.append( |
| 187 | KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL); |
| 188 | sApplicationLaunchKeyCategories.append( |
| 189 | KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS); |
| 190 | sApplicationLaunchKeyCategories.append( |
| 191 | KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR); |
| 192 | sApplicationLaunchKeyCategories.append( |
| 193 | KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC); |
| 194 | sApplicationLaunchKeyCategories.append( |
| 195 | KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR); |
| 196 | } |
| 197 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 198 | /** |
| 199 | * Lock protecting internal state. Must not call out into window |
| 200 | * manager with lock held. (This lock will be acquired in places |
| 201 | * where the window manager is calling in with its own lock held.) |
| 202 | */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 203 | private final Object mLock = new Object(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 204 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 205 | Context mContext; |
| 206 | IWindowManager mWindowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 207 | WindowManagerFuncs mWindowManagerFuncs; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 208 | PowerManager mPowerManager; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 209 | IStatusBarService mStatusBarService; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 210 | boolean mPreloadedRecentApps; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 211 | final Object mServiceAquireLock = new Object(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 212 | Vibrator mVibrator; // Vibrator for giving feedback of orientation changes |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 213 | SearchManager mSearchManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 214 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 215 | // Vibrator pattern for haptic feedback of a long press. |
| 216 | long[] mLongPressVibePattern; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 217 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 218 | // Vibrator pattern for haptic feedback of virtual key press. |
| 219 | long[] mVirtualKeyVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 220 | |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 221 | // Vibrator pattern for a short vibration. |
| 222 | long[] mKeyboardTapVibePattern; |
| 223 | |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame^] | 224 | // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock. |
| 225 | long[] mClockTickVibePattern; |
| 226 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 227 | // Vibrator pattern for haptic feedback during boot when safe mode is disabled. |
| 228 | long[] mSafeModeDisabledVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 229 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 230 | // Vibrator pattern for haptic feedback during boot when safe mode is enabled. |
| 231 | long[] mSafeModeEnabledVibePattern; |
Romain Guy | 8154cd3 | 2010-03-29 14:41:15 -0700 | [diff] [blame] | 232 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 233 | /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */ |
| 234 | boolean mEnableShiftMenuBugReports = false; |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 235 | |
| 236 | boolean mHeadless; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 237 | boolean mSafeMode; |
| 238 | WindowState mStatusBar = null; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 239 | int mStatusBarHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 240 | WindowState mNavigationBar = null; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 241 | boolean mHasNavigationBar = false; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 242 | boolean mCanHideNavigationBar = false; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 243 | boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side? |
| 244 | boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*? |
| 245 | int[] mNavigationBarHeightForRotation = new int[4]; |
| 246 | int[] mNavigationBarWidthForRotation = new int[4]; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 247 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 248 | WindowState mKeyguard = null; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 249 | KeyguardServiceDelegate mKeyguardDelegate; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 250 | GlobalActions mGlobalActions; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 251 | volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread |
| 252 | boolean mPendingPowerKeyUpCanceled; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 253 | Handler mHandler; |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 254 | WindowState mLastInputMethodWindow = null; |
| 255 | WindowState mLastInputMethodTargetWindow = null; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 256 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 257 | static final int RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS = 0; |
| 258 | static final int RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW = 1; |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 259 | static final int RECENT_APPS_BEHAVIOR_DISMISS = 2; |
| 260 | static final int RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH = 3; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 261 | |
| 262 | RecentApplicationsDialog mRecentAppsDialog; |
| 263 | int mRecentAppsDialogHeldModifiers; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 264 | boolean mLanguageSwitchKeyPressed; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 265 | |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 266 | int mLidState = LID_ABSENT; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 267 | boolean mHaveBuiltInKeyboard; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 268 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 269 | boolean mSystemReady; |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 270 | boolean mSystemBooted; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 271 | boolean mHdmiPlugged; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 272 | int mUiMode; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 273 | int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 274 | int mLidOpenRotation; |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 275 | int mCarDockRotation; |
| 276 | int mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 277 | int mUndockedHdmiRotation; |
| 278 | int mDemoHdmiRotation; |
| 279 | boolean mDemoHdmiRotationLock; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 280 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 281 | // Default display does not rotate, apps that require non-default orientation will have to |
| 282 | // have the orientation emulated. |
| 283 | private boolean mForceDefaultOrientation = false; |
| 284 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 285 | int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE; |
| 286 | int mUserRotation = Surface.ROTATION_0; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 287 | boolean mAccelerometerDefault; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 288 | |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 289 | int mAllowAllRotations = -1; |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 290 | boolean mCarDockEnablesAccelerometer; |
| 291 | boolean mDeskDockEnablesAccelerometer; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 292 | int mLidKeyboardAccessibility; |
| 293 | int mLidNavigationAccessibility; |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 294 | boolean mLidControlsSleep; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 295 | int mLongPressOnPowerBehavior = -1; |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 296 | boolean mScreenOnEarly = false; |
| 297 | boolean mScreenOnFully = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 298 | boolean mOrientationSensorEnabled = false; |
| 299 | int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 300 | boolean mHasSoftInput = false; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 301 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 302 | int mPointerLocationMode = 0; // guarded by mLock |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 303 | |
| 304 | // The last window we were told about in focusChanged. |
| 305 | WindowState mFocusedWindow; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 306 | IApplicationToken mFocusedApp; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 307 | |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 308 | private final class PointerLocationPointerEventListener implements PointerEventListener { |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 309 | @Override |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 310 | public void onPointerEvent(MotionEvent motionEvent) { |
| 311 | if (mPointerLocationView != null) { |
| 312 | mPointerLocationView.addPointerEvent(motionEvent); |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 313 | } |
| 314 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 315 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 316 | |
| 317 | // Pointer location view state, only modified on the mHandler Looper. |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 318 | PointerLocationPointerEventListener mPointerLocationPointerEventListener; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 319 | PointerLocationView mPointerLocationView; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 320 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 321 | // The current size of the screen; really; extends into the overscan area of |
| 322 | // the screen and doesn't account for any system elements like the status bar. |
| 323 | int mOverscanScreenLeft, mOverscanScreenTop; |
| 324 | int mOverscanScreenWidth, mOverscanScreenHeight; |
| 325 | // The current visible size of the screen; really; (ir)regardless of whether the status |
| 326 | // bar can be hidden but not extending into the overscan area. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 327 | int mUnrestrictedScreenLeft, mUnrestrictedScreenTop; |
| 328 | int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 329 | // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate. |
| 330 | int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop; |
| 331 | int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight; |
Dianne Hackborn | 82de1ae | 2010-10-28 11:28:39 -0700 | [diff] [blame] | 332 | // The current size of the screen; these may be different than (0,0)-(dw,dh) |
| 333 | // if the status bar can't be hidden; in that case it effectively carves out |
| 334 | // that area of the display from all other windows. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 335 | int mRestrictedScreenLeft, mRestrictedScreenTop; |
| 336 | int mRestrictedScreenWidth, mRestrictedScreenHeight; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 337 | // During layout, the current screen borders accounting for any currently |
| 338 | // visible system UI elements. |
| 339 | int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 340 | // For applications requesting stable content insets, these are them. |
| 341 | int mStableLeft, mStableTop, mStableRight, mStableBottom; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 342 | // For applications requesting stable content insets but have also set the |
| 343 | // fullscreen window flag, these are the stable dimensions without the status bar. |
| 344 | int mStableFullscreenLeft, mStableFullscreenTop; |
| 345 | int mStableFullscreenRight, mStableFullscreenBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 346 | // During layout, the current screen borders with all outer decoration |
| 347 | // (status bar, input method dock) accounted for. |
| 348 | int mCurLeft, mCurTop, mCurRight, mCurBottom; |
| 349 | // During layout, the frame in which content should be displayed |
| 350 | // to the user, accounting for all screen decoration except for any |
| 351 | // space they deem as available for other content. This is usually |
| 352 | // the same as mCur*, but may be larger if the screen decor has supplied |
| 353 | // content insets. |
| 354 | int mContentLeft, mContentTop, mContentRight, mContentBottom; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 355 | // During layout, the current screen borders along which input method |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 356 | // windows are placed. |
| 357 | int mDockLeft, mDockTop, mDockRight, mDockBottom; |
| 358 | // During layout, the layer at which the doc window is placed. |
| 359 | int mDockLayer; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 360 | // During layout, this is the layer of the status bar. |
| 361 | int mStatusBarLayer; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 362 | int mLastSystemUiFlags; |
| 363 | // Bits that we are in the process of clearing, so we want to prevent |
| 364 | // them from being set by applications until everything has been updated |
| 365 | // to have them clear. |
| 366 | int mResettingSystemUiFlags = 0; |
| 367 | // Bits that we are currently always keeping cleared. |
| 368 | int mForceClearedSystemUiFlags = 0; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 369 | // What we last reported to system UI about whether the compatibility |
| 370 | // menu needs to be displayed. |
| 371 | boolean mLastFocusNeedsMenu = false; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 372 | |
| 373 | FakeWindow mHideNavFakeWindow = null; |
| 374 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 375 | static final Rect mTmpParentFrame = new Rect(); |
| 376 | static final Rect mTmpDisplayFrame = new Rect(); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 377 | static final Rect mTmpOverscanFrame = new Rect(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 378 | static final Rect mTmpContentFrame = new Rect(); |
| 379 | static final Rect mTmpVisibleFrame = new Rect(); |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 380 | static final Rect mTmpNavigationFrame = new Rect(); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 381 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 382 | WindowState mTopFullscreenOpaqueWindowState; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 383 | boolean mTopIsFullscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 384 | boolean mForceStatusBar; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 385 | boolean mForceStatusBarFromKeyguard; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 386 | boolean mHideLockScreen; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 387 | boolean mForcingShowNavBar; |
| 388 | int mForcingShowNavBarLayer; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 389 | |
| 390 | // States of keyguard dismiss. |
| 391 | private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed. |
| 392 | private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed. |
| 393 | private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed. |
| 394 | int mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
| 395 | |
| 396 | /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only |
| 397 | * be done once per window. */ |
| 398 | private WindowState mWinDismissingKeyguard; |
| 399 | |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 400 | boolean mShowingLockscreen; |
| 401 | boolean mShowingDream; |
| 402 | boolean mDreamingLockscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 403 | boolean mHomePressed; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 404 | boolean mHomeConsumed; |
| 405 | boolean mHomeDoubleTapPending; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 406 | Intent mHomeIntent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 407 | Intent mCarDockIntent; |
| 408 | Intent mDeskDockIntent; |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 409 | boolean mSearchKeyShortcutPending; |
| 410 | boolean mConsumeSearchKeyUp; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 411 | boolean mAssistKeyLongPressed; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 412 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 413 | // support for activating the lock screen while the screen is on |
| 414 | boolean mAllowLockscreenWhenOn; |
| 415 | int mLockScreenTimeout; |
| 416 | boolean mLockScreenTimerActive; |
| 417 | |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 418 | // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.) |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 419 | int mEndcallBehavior; |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 420 | |
| 421 | // Behavior of POWER button while in-call and screen on. |
| 422 | // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.) |
| 423 | int mIncallPowerBehavior; |
| 424 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 425 | Display mDisplay; |
| 426 | |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 427 | int mLandscapeRotation = 0; // default landscape rotation |
| 428 | int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation |
| 429 | int mPortraitRotation = 0; // default portrait rotation |
| 430 | int mUpsideDownRotation = 0; // "other" portrait rotation |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 431 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 432 | int mOverscanLeft = 0; |
| 433 | int mOverscanTop = 0; |
| 434 | int mOverscanRight = 0; |
| 435 | int mOverscanBottom = 0; |
| 436 | |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 437 | // What we do when the user long presses on home |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 438 | private int mLongPressOnHomeBehavior; |
| 439 | |
| 440 | // What we do when the user double-taps on home |
| 441 | private int mDoubleTapOnHomeBehavior; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 442 | |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 443 | // Screenshot trigger states |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 444 | // Time to volume and power must be pressed within this interval of each other. |
| 445 | private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150; |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 446 | // Increase the chord delay when taking a screenshot from the keyguard |
| 447 | private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f; |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 448 | private boolean mScreenshotChordEnabled; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 449 | private boolean mVolumeDownKeyTriggered; |
| 450 | private long mVolumeDownKeyTime; |
| 451 | private boolean mVolumeDownKeyConsumedByScreenshotChord; |
| 452 | private boolean mVolumeUpKeyTriggered; |
| 453 | private boolean mPowerKeyTriggered; |
| 454 | private long mPowerKeyTime; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 455 | |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 456 | /* The number of steps between min and max brightness */ |
| 457 | private static final int BRIGHTNESS_STEPS = 10; |
| 458 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 459 | SettingsObserver mSettingsObserver; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 460 | ShortcutManager mShortcutManager; |
| 461 | PowerManager.WakeLock mBroadcastWakeLock; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 462 | boolean mHavePendingMediaKeyRepeatWithWakeLock; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 463 | |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 464 | private int mCurrentUserId; |
| 465 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 466 | // Maps global key codes to the components that will handle them. |
| 467 | private GlobalKeyManager mGlobalKeyManager; |
| 468 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 469 | // Fallback actions by key code. |
| 470 | private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions = |
| 471 | new SparseArray<KeyCharacterMap.FallbackAction>(); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 472 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 473 | private static final int MSG_ENABLE_POINTER_LOCATION = 1; |
| 474 | private static final int MSG_DISABLE_POINTER_LOCATION = 2; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 475 | private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3; |
| 476 | private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 477 | |
| 478 | private class PolicyHandler extends Handler { |
| 479 | @Override |
| 480 | public void handleMessage(Message msg) { |
| 481 | switch (msg.what) { |
| 482 | case MSG_ENABLE_POINTER_LOCATION: |
| 483 | enablePointerLocation(); |
| 484 | break; |
| 485 | case MSG_DISABLE_POINTER_LOCATION: |
| 486 | disablePointerLocation(); |
| 487 | break; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 488 | case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK: |
| 489 | dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj); |
| 490 | break; |
| 491 | case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK: |
| 492 | dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj); |
| 493 | break; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 494 | } |
| 495 | } |
| 496 | } |
| 497 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 498 | private UEventObserver mHDMIObserver = new UEventObserver() { |
| 499 | @Override |
| 500 | public void onUEvent(UEventObserver.UEvent event) { |
| 501 | setHdmiPlugged("1".equals(event.get("SWITCH_STATE"))); |
| 502 | } |
| 503 | }; |
| 504 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 505 | class SettingsObserver extends ContentObserver { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 506 | SettingsObserver(Handler handler) { |
| 507 | super(handler); |
| 508 | } |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 509 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 510 | void observe() { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 511 | // Observe all users' changes |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 512 | ContentResolver resolver = mContext.getContentResolver(); |
| 513 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 514 | Settings.System.END_BUTTON_BEHAVIOR), false, this, |
| 515 | UserHandle.USER_ALL); |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 516 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 517 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this, |
| 518 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 519 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 520 | Settings.System.ACCELEROMETER_ROTATION), false, this, |
| 521 | UserHandle.USER_ALL); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 522 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 523 | Settings.System.USER_ROTATION), false, this, |
| 524 | UserHandle.USER_ALL); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 525 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 526 | Settings.System.SCREEN_OFF_TIMEOUT), false, this, |
| 527 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 528 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 529 | Settings.System.POINTER_LOCATION), false, this, |
| 530 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 531 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 532 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this, |
| 533 | UserHandle.USER_ALL); |
Dianne Hackborn | 03759ed | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 534 | resolver.registerContentObserver(Settings.System.getUriFor( |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 535 | Settings.Secure.TRANSIENT_NAV_CONFIRMATIONS), false, this, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 536 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 537 | updateSettings(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | @Override public void onChange(boolean selfChange) { |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 541 | updateSettings(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 542 | updateRotation(false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 543 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 544 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 545 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 546 | class MyOrientationListener extends WindowOrientationListener { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 547 | MyOrientationListener(Context context, Handler handler) { |
| 548 | super(context, handler); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 549 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 550 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 551 | @Override |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 552 | public void onProposedRotationChanged(int rotation) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 553 | if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 554 | updateRotation(false); |
| 555 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 556 | } |
| 557 | MyOrientationListener mOrientationListener; |
| 558 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 559 | private final BarController mStatusBarController = new BarController("StatusBar", |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 560 | View.STATUS_BAR_TRANSIENT, |
| 561 | View.STATUS_BAR_UNHIDE, |
John Spurlock | b77edbf | 2013-08-21 21:04:12 -0400 | [diff] [blame] | 562 | View.SYSTEM_UI_FLAG_TRANSPARENT_STATUS, |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 563 | StatusBarManager.WINDOW_STATUS_BAR); |
| 564 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 565 | private final BarController mNavigationBarController = new BarController("NavigationBar", |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 566 | View.NAVIGATION_BAR_TRANSIENT, |
| 567 | View.NAVIGATION_BAR_UNHIDE, |
John Spurlock | b77edbf | 2013-08-21 21:04:12 -0400 | [diff] [blame] | 568 | View.SYSTEM_UI_FLAG_TRANSPARENT_NAVIGATION, |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 569 | StatusBarManager.WINDOW_NAVIGATION_BAR); |
| 570 | |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 571 | private TransientNavigationConfirmation mTransientNavigationConfirmation; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 572 | |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 573 | private SystemGesturesPointerEventListener mSystemGestures; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 574 | |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 575 | IStatusBarService getStatusBarService() { |
| 576 | synchronized (mServiceAquireLock) { |
| 577 | if (mStatusBarService == null) { |
| 578 | mStatusBarService = IStatusBarService.Stub.asInterface( |
| 579 | ServiceManager.getService("statusbar")); |
| 580 | } |
| 581 | return mStatusBarService; |
| 582 | } |
| 583 | } |
| 584 | |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 585 | /* |
| 586 | * We always let the sensor be switched on by default except when |
| 587 | * the user has explicitly disabled sensor based rotation or when the |
| 588 | * screen is switched off. |
| 589 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 590 | boolean needSensorRunningLp() { |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 591 | if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 592 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 593 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT |
| 594 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 595 | // If the application has explicitly requested to follow the |
| 596 | // orientation, then we need to turn the sensor or. |
| 597 | return true; |
| 598 | } |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 599 | if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) || |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 600 | (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 601 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 602 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) { |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 603 | // enable accelerometer if we are docked in a dock that enables accelerometer |
| 604 | // orientation management, |
| 605 | return true; |
| 606 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 607 | if (mUserRotationMode == USER_ROTATION_LOCKED) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 608 | // If the setting for using the sensor by default is enabled, then |
| 609 | // we will always leave it on. Note that the user could go to |
| 610 | // a window that forces an orientation that does not use the |
| 611 | // sensor and in theory we could turn it off... however, when next |
| 612 | // turning it on we won't have a good value for the current |
| 613 | // orientation for a little bit, which can cause orientation |
| 614 | // changes to lag, so we'd like to keep it always on. (It will |
| 615 | // still be turned off when the screen is off.) |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 616 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 617 | } |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 618 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 619 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 620 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 621 | /* |
| 622 | * Various use cases for invoking this function |
| 623 | * screen turning off, should always disable listeners if already enabled |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 624 | * screen turned on and current app has sensor based orientation, enable listeners |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 625 | * if not already enabled |
| 626 | * screen turned on and current app does not have sensor orientation, disable listeners if |
| 627 | * already enabled |
| 628 | * screen turning on and current app has sensor based orientation, enable listeners if needed |
| 629 | * screen turning on and current app has nosensor based orientation, do nothing |
| 630 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 631 | void updateOrientationListenerLp() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 632 | if (!mOrientationListener.canDetectOrientation()) { |
| 633 | // If sensor is turned off or nonexistent for some reason |
| 634 | return; |
| 635 | } |
| 636 | //Could have been invoked due to screen turning on or off or |
| 637 | //change of the currently visible window's orientation |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 638 | if (localLOGV) Slog.v(TAG, "Screen status="+mScreenOnEarly+ |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 639 | ", current orientation="+mCurrentAppOrientation+ |
| 640 | ", SensorEnabled="+mOrientationSensorEnabled); |
| 641 | boolean disable = true; |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 642 | if (mScreenOnEarly) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 643 | if (needSensorRunningLp()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 644 | disable = false; |
| 645 | //enable listener if not already enabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 646 | if (!mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 647 | mOrientationListener.enable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 648 | if(localLOGV) Slog.v(TAG, "Enabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 649 | mOrientationSensorEnabled = true; |
| 650 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 651 | } |
| 652 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 653 | //check if sensors need to be disabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 654 | if (disable && mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 655 | mOrientationListener.disable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 656 | if(localLOGV) Slog.v(TAG, "Disabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 657 | mOrientationSensorEnabled = false; |
| 658 | } |
| 659 | } |
| 660 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 661 | private void interceptPowerKeyDown(boolean handled) { |
| 662 | mPowerKeyHandled = handled; |
| 663 | if (!handled) { |
| 664 | mHandler.postDelayed(mPowerLongPress, ViewConfiguration.getGlobalActionKeyTimeout()); |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | private boolean interceptPowerKeyUp(boolean canceled) { |
| 669 | if (!mPowerKeyHandled) { |
| 670 | mHandler.removeCallbacks(mPowerLongPress); |
| 671 | return !canceled; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 672 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 673 | return false; |
| 674 | } |
| 675 | |
| 676 | private void cancelPendingPowerKeyAction() { |
| 677 | if (!mPowerKeyHandled) { |
| 678 | mHandler.removeCallbacks(mPowerLongPress); |
| 679 | } |
Jeff Brown | ff20471 | 2011-10-25 21:27:54 -0700 | [diff] [blame] | 680 | if (mPowerKeyTriggered) { |
| 681 | mPendingPowerKeyUpCanceled = true; |
| 682 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | private void interceptScreenshotChord() { |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 686 | if (mScreenshotChordEnabled |
| 687 | && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 688 | final long now = SystemClock.uptimeMillis(); |
| 689 | if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS |
| 690 | && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { |
| 691 | mVolumeDownKeyConsumedByScreenshotChord = true; |
| 692 | cancelPendingPowerKeyAction(); |
| 693 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 694 | mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay()); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 695 | } |
| 696 | } |
| 697 | } |
| 698 | |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 699 | private long getScreenshotChordLongPressDelay() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 700 | if (mKeyguardDelegate.isShowing()) { |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 701 | // Double the time it takes to take a screenshot from the keyguard |
| 702 | return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER * |
| 703 | ViewConfiguration.getGlobalActionKeyTimeout()); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 704 | } |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 705 | return ViewConfiguration.getGlobalActionKeyTimeout(); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 708 | private void cancelPendingScreenshotChordAction() { |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 709 | mHandler.removeCallbacks(mScreenshotRunnable); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | private final Runnable mPowerLongPress = new Runnable() { |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 713 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 714 | public void run() { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 715 | // The context isn't read |
| 716 | if (mLongPressOnPowerBehavior < 0) { |
Jeff Brown | 850c5b7 | 2012-10-01 15:17:22 -0700 | [diff] [blame] | 717 | mLongPressOnPowerBehavior = mContext.getResources().getInteger( |
| 718 | com.android.internal.R.integer.config_longPressOnPowerBehavior); |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 719 | } |
Jeff Brown | 850c5b7 | 2012-10-01 15:17:22 -0700 | [diff] [blame] | 720 | int resolvedBehavior = mLongPressOnPowerBehavior; |
| 721 | if (FactoryTest.isLongPressOnPowerOffEnabled()) { |
| 722 | resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM; |
| 723 | } |
| 724 | |
| 725 | switch (resolvedBehavior) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 726 | case LONG_PRESS_POWER_NOTHING: |
| 727 | break; |
| 728 | case LONG_PRESS_POWER_GLOBAL_ACTIONS: |
| 729 | mPowerKeyHandled = true; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 730 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 731 | performAuditoryFeedbackForAccessibilityIfNeed(); |
| 732 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 733 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
| 734 | showGlobalActionsDialog(); |
| 735 | break; |
| 736 | case LONG_PRESS_POWER_SHUT_OFF: |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 737 | case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM: |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 738 | mPowerKeyHandled = true; |
| 739 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 740 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
Jeff Brown | 850c5b7 | 2012-10-01 15:17:22 -0700 | [diff] [blame] | 741 | mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 742 | break; |
| 743 | } |
| 744 | } |
| 745 | }; |
| 746 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 747 | private final Runnable mScreenshotRunnable = new Runnable() { |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 748 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 749 | public void run() { |
| 750 | takeScreenshot(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 751 | } |
| 752 | }; |
| 753 | |
| 754 | void showGlobalActionsDialog() { |
| 755 | if (mGlobalActions == null) { |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 756 | mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 757 | } |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 758 | final boolean keyguardShowing = keyguardIsShowingTq(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 759 | mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned()); |
| 760 | if (keyguardShowing) { |
| 761 | // since it took two seconds of long press to bring this up, |
| 762 | // poke the wake lock so they have some time to see the dialog. |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 763 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 764 | } |
| 765 | } |
| 766 | |
| 767 | boolean isDeviceProvisioned() { |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 768 | return Settings.Global.getInt( |
| 769 | mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 770 | } |
| 771 | |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 772 | private void handleLongPressOnHome() { |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 773 | if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 774 | mHomeConsumed = true; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 775 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 776 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 777 | if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) { |
| 778 | toggleRecentApps(); |
| 779 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) { |
| 780 | launchAssistAction(); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 781 | } |
| 782 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 783 | } |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 784 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 785 | private void handleDoubleTapOnHome() { |
| 786 | if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 787 | mHomeConsumed = true; |
| 788 | toggleRecentApps(); |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() { |
| 793 | @Override |
| 794 | public void run() { |
| 795 | if (mHomeDoubleTapPending) { |
| 796 | mHomeDoubleTapPending = false; |
| 797 | launchHomeFromHotKey(); |
| 798 | } |
| 799 | } |
| 800 | }; |
| 801 | |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 802 | /** |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 803 | * Create (if necessary) and show or dismiss the recent apps dialog according |
| 804 | * according to the requested behavior. |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 805 | */ |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 806 | void showOrHideRecentAppsDialog(final int behavior) { |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 807 | mHandler.post(new Runnable() { |
| 808 | @Override |
| 809 | public void run() { |
| 810 | if (mRecentAppsDialog == null) { |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 811 | mRecentAppsDialog = new RecentApplicationsDialog(mContext); |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 812 | } |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 813 | if (mRecentAppsDialog.isShowing()) { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 814 | switch (behavior) { |
| 815 | case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS: |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 816 | case RECENT_APPS_BEHAVIOR_DISMISS: |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 817 | mRecentAppsDialog.dismiss(); |
| 818 | break; |
| 819 | case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH: |
| 820 | mRecentAppsDialog.dismissAndSwitch(); |
| 821 | break; |
| 822 | case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW: |
| 823 | default: |
| 824 | break; |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 825 | } |
| 826 | } else { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 827 | switch (behavior) { |
| 828 | case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS: |
| 829 | mRecentAppsDialog.show(); |
| 830 | break; |
| 831 | case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW: |
| 832 | try { |
| 833 | mWindowManager.setInTouchMode(false); |
| 834 | } catch (RemoteException e) { |
| 835 | } |
| 836 | mRecentAppsDialog.show(); |
| 837 | break; |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 838 | case RECENT_APPS_BEHAVIOR_DISMISS: |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 839 | case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH: |
| 840 | default: |
| 841 | break; |
| 842 | } |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 843 | } |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 844 | } |
| 845 | }); |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 846 | } |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 847 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 848 | /** {@inheritDoc} */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 849 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 850 | public void init(Context context, IWindowManager windowManager, |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 851 | WindowManagerFuncs windowManagerFuncs) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 852 | mContext = context; |
| 853 | mWindowManager = windowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 854 | mWindowManagerFuncs = windowManagerFuncs; |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 855 | mHeadless = "1".equals(SystemProperties.get("ro.config.headless", "0")); |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 856 | mHandler = new PolicyHandler(); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 857 | mOrientationListener = new MyOrientationListener(mContext, mHandler); |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 858 | try { |
| 859 | mOrientationListener.setCurrentRotation(windowManager.getRotation()); |
| 860 | } catch (RemoteException ex) { } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 861 | mSettingsObserver = new SettingsObserver(mHandler); |
| 862 | mSettingsObserver.observe(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 863 | mShortcutManager = new ShortcutManager(context, mHandler); |
| 864 | mShortcutManager.observe(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 865 | mUiMode = context.getResources().getInteger( |
| 866 | com.android.internal.R.integer.config_defaultUiModeType); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 867 | mHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 868 | mHomeIntent.addCategory(Intent.CATEGORY_HOME); |
| 869 | mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 870 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 871 | mCarDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 872 | mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK); |
| 873 | mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 874 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 875 | mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 876 | mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK); |
| 877 | mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 878 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 879 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 880 | mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 881 | mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 882 | "PhoneWindowManager.mBroadcastWakeLock"); |
| 883 | mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable")); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 884 | mLidOpenRotation = readRotation( |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 885 | com.android.internal.R.integer.config_lidOpenRotation); |
| 886 | mCarDockRotation = readRotation( |
| 887 | com.android.internal.R.integer.config_carDockRotation); |
| 888 | mDeskDockRotation = readRotation( |
| 889 | com.android.internal.R.integer.config_deskDockRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 890 | mUndockedHdmiRotation = readRotation( |
| 891 | com.android.internal.R.integer.config_undockedHdmiRotation); |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 892 | mCarDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 893 | com.android.internal.R.bool.config_carDockEnablesAccelerometer); |
| 894 | mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 895 | com.android.internal.R.bool.config_deskDockEnablesAccelerometer); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 896 | mLidKeyboardAccessibility = mContext.getResources().getInteger( |
| 897 | com.android.internal.R.integer.config_lidKeyboardAccessibility); |
| 898 | mLidNavigationAccessibility = mContext.getResources().getInteger( |
| 899 | com.android.internal.R.integer.config_lidNavigationAccessibility); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 900 | mLidControlsSleep = mContext.getResources().getBoolean( |
| 901 | com.android.internal.R.bool.config_lidControlsSleep); |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 902 | readConfigurationDependentBehaviors(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 903 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 904 | // register for dock events |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 905 | IntentFilter filter = new IntentFilter(); |
| 906 | filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE); |
| 907 | filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE); |
| 908 | filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE); |
| 909 | filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 910 | filter.addAction(Intent.ACTION_DOCK_EVENT); |
| 911 | Intent intent = context.registerReceiver(mDockReceiver, filter); |
| 912 | if (intent != null) { |
| 913 | // Retrieve current sticky dock event broadcast. |
| 914 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 915 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
| 916 | } |
Daniel Sandler | 7e37df5 | 2011-11-16 22:08:23 -0800 | [diff] [blame] | 917 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 918 | // register for dream-related broadcasts |
| 919 | filter = new IntentFilter(); |
| 920 | filter.addAction(Intent.ACTION_DREAMING_STARTED); |
| 921 | filter.addAction(Intent.ACTION_DREAMING_STOPPED); |
| 922 | context.registerReceiver(mDreamReceiver, filter); |
| 923 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 924 | // register for multiuser-relevant broadcasts |
| 925 | filter = new IntentFilter(Intent.ACTION_USER_SWITCHED); |
| 926 | context.registerReceiver(mMultiuserReceiver, filter); |
| 927 | |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 928 | // monitor for system gestures |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 929 | mSystemGestures = new SystemGesturesPointerEventListener(context, |
| 930 | new SystemGesturesPointerEventListener.Callbacks() { |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 931 | @Override |
| 932 | public void onSwipeFromTop() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 933 | if (mStatusBar != null) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 934 | requestTransientBars(mStatusBar); |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 935 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 936 | } |
| 937 | @Override |
| 938 | public void onSwipeFromBottom() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 939 | if (mNavigationBar != null && mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 940 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 941 | } |
| 942 | } |
| 943 | @Override |
| 944 | public void onSwipeFromRight() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 945 | if (mNavigationBar != null && !mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 946 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 947 | } |
| 948 | } |
| 949 | @Override |
| 950 | public void onDebug() { |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 951 | // no-op |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 952 | } |
| 953 | }); |
John Spurlock | 4cf6a94 | 2013-08-13 20:02:46 -0400 | [diff] [blame] | 954 | mTransientNavigationConfirmation = new TransientNavigationConfirmation(mContext); |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 955 | mWindowManagerFuncs.registerPointerEventListener(mSystemGestures); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 956 | |
Jeff Brown | c234613 | 2012-04-13 01:55:38 -0700 | [diff] [blame] | 957 | mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 958 | mLongPressVibePattern = getLongIntArray(mContext.getResources(), |
| 959 | com.android.internal.R.array.config_longPressVibePattern); |
| 960 | mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(), |
| 961 | com.android.internal.R.array.config_virtualKeyVibePattern); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 962 | mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(), |
| 963 | com.android.internal.R.array.config_keyboardTapVibePattern); |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame^] | 964 | mClockTickVibePattern = getLongIntArray(mContext.getResources(), |
| 965 | com.android.internal.R.array.config_clockTickVibePattern); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 966 | mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(), |
| 967 | com.android.internal.R.array.config_safeModeDisabledVibePattern); |
| 968 | mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), |
| 969 | com.android.internal.R.array.config_safeModeEnabledVibePattern); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 970 | |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 971 | mScreenshotChordEnabled = mContext.getResources().getBoolean( |
| 972 | com.android.internal.R.bool.config_enableScreenshotChord); |
| 973 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 974 | mGlobalKeyManager = new GlobalKeyManager(mContext); |
| 975 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 976 | // Controls rotation and the like. |
| 977 | initializeHdmiState(); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 978 | |
| 979 | // Match current screen state. |
| 980 | if (mPowerManager.isScreenOn()) { |
| 981 | screenTurningOn(null); |
| 982 | } else { |
| 983 | screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 984 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 985 | } |
| 986 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 987 | /** |
| 988 | * Read values from config.xml that may be overridden depending on |
| 989 | * the configuration of the device. |
| 990 | * eg. Disable long press on home goes to recents on sw600dp. |
| 991 | */ |
| 992 | private void readConfigurationDependentBehaviors() { |
| 993 | mLongPressOnHomeBehavior = mContext.getResources().getInteger( |
| 994 | com.android.internal.R.integer.config_longPressOnHomeBehavior); |
| 995 | if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING || |
| 996 | mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) { |
| 997 | mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 998 | } |
| 999 | |
| 1000 | mDoubleTapOnHomeBehavior = mContext.getResources().getInteger( |
| 1001 | com.android.internal.R.integer.config_doubleTapOnHomeBehavior); |
| 1002 | if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING || |
| 1003 | mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1004 | mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1005 | } |
| 1006 | } |
| 1007 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1008 | @Override |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1009 | public void setInitialDisplaySize(Display display, int width, int height, int density) { |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 1010 | // This method might be called before the policy has been fully initialized |
| 1011 | // or for other displays we don't care about. |
| 1012 | if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) { |
| 1013 | return; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1014 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1015 | mDisplay = display; |
| 1016 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1017 | final Resources res = mContext.getResources(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1018 | int shortSize, longSize; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1019 | if (width > height) { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1020 | shortSize = height; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1021 | longSize = width; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1022 | mLandscapeRotation = Surface.ROTATION_0; |
| 1023 | mSeascapeRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1024 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1025 | mPortraitRotation = Surface.ROTATION_90; |
| 1026 | mUpsideDownRotation = Surface.ROTATION_270; |
| 1027 | } else { |
| 1028 | mPortraitRotation = Surface.ROTATION_270; |
| 1029 | mUpsideDownRotation = Surface.ROTATION_90; |
| 1030 | } |
| 1031 | } else { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1032 | shortSize = width; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1033 | longSize = height; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1034 | mPortraitRotation = Surface.ROTATION_0; |
| 1035 | mUpsideDownRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1036 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1037 | mLandscapeRotation = Surface.ROTATION_270; |
| 1038 | mSeascapeRotation = Surface.ROTATION_90; |
| 1039 | } else { |
| 1040 | mLandscapeRotation = Surface.ROTATION_90; |
| 1041 | mSeascapeRotation = Surface.ROTATION_270; |
| 1042 | } |
| 1043 | } |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1044 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1045 | mStatusBarHeight = |
| 1046 | res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1047 | |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1048 | // Height of the navigation bar when presented horizontally at bottom |
| 1049 | mNavigationBarHeightForRotation[mPortraitRotation] = |
| 1050 | mNavigationBarHeightForRotation[mUpsideDownRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1051 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1052 | mNavigationBarHeightForRotation[mLandscapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1053 | mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize( |
| 1054 | com.android.internal.R.dimen.navigation_bar_height_landscape); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1055 | |
| 1056 | // Width of the navigation bar when presented vertically along one side |
| 1057 | mNavigationBarWidthForRotation[mPortraitRotation] = |
| 1058 | mNavigationBarWidthForRotation[mUpsideDownRotation] = |
| 1059 | mNavigationBarWidthForRotation[mLandscapeRotation] = |
| 1060 | mNavigationBarWidthForRotation[mSeascapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1061 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width); |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1062 | |
| 1063 | // SystemUI (status bar) layout policy |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1064 | int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1065 | int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1066 | |
Craig Mautner | d4ec3324 | 2013-07-22 10:37:43 -0700 | [diff] [blame] | 1067 | // Allow the navigation bar to move on small devices (phones). |
| 1068 | mNavigationBarCanMove = shortSizeDp < 600; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 1069 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1070 | mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar); |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1071 | // Allow a system property to override this. Used by the emulator. |
| 1072 | // See also hasNavigationBar(). |
| 1073 | String navBarOverride = SystemProperties.get("qemu.hw.mainkeys"); |
| 1074 | if ("1".equals(navBarOverride)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1075 | mHasNavigationBar = false; |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1076 | } else if ("0".equals(navBarOverride)) { |
| 1077 | mHasNavigationBar = true; |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 1078 | } |
| 1079 | |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1080 | if (mHasNavigationBar) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1081 | // The navigation bar is at the right in landscape; it seems always |
| 1082 | // useful to hide it for showing a video. |
| 1083 | mCanHideNavigationBar = true; |
| 1084 | } else { |
| 1085 | mCanHideNavigationBar = false; |
| 1086 | } |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1087 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 1088 | // For demo purposes, allow the rotation of the HDMI display to be controlled. |
| 1089 | // By default, HDMI locks rotation to landscape. |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1090 | if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1091 | mDemoHdmiRotation = mPortraitRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1092 | } else { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1093 | mDemoHdmiRotation = mLandscapeRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1094 | } |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1095 | mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1096 | |
| 1097 | // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per |
| 1098 | // http://developer.android.com/guide/practices/screens_support.html#range |
| 1099 | mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 && |
| 1100 | res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) && |
| 1101 | // For debug purposes the next line turns this feature off with: |
| 1102 | // $ adb shell setprop config.override_forced_orient true |
| 1103 | // $ adb shell wm size reset |
| 1104 | !"true".equals(SystemProperties.get("config.override_forced_orient")); |
| 1105 | } |
| 1106 | |
| 1107 | @Override |
| 1108 | public boolean isDefaultOrientationForced() { |
| 1109 | return mForceDefaultOrientation; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1110 | } |
| 1111 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1112 | @Override |
| 1113 | public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) { |
| 1114 | if (display.getDisplayId() == Display.DEFAULT_DISPLAY) { |
| 1115 | mOverscanLeft = left; |
| 1116 | mOverscanTop = top; |
| 1117 | mOverscanRight = right; |
| 1118 | mOverscanBottom = bottom; |
| 1119 | } |
| 1120 | } |
| 1121 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1122 | public void updateSettings() { |
| 1123 | ContentResolver resolver = mContext.getContentResolver(); |
| 1124 | boolean updateRotation = false; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1125 | synchronized (mLock) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1126 | mEndcallBehavior = Settings.System.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1127 | Settings.System.END_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1128 | Settings.System.END_BUTTON_BEHAVIOR_DEFAULT, |
| 1129 | UserHandle.USER_CURRENT); |
| 1130 | mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1131 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1132 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT, |
| 1133 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1134 | |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1135 | // Configure rotation lock. |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1136 | int userRotation = Settings.System.getIntForUser(resolver, |
| 1137 | Settings.System.USER_ROTATION, Surface.ROTATION_0, |
| 1138 | UserHandle.USER_CURRENT); |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1139 | if (mUserRotation != userRotation) { |
| 1140 | mUserRotation = userRotation; |
| 1141 | updateRotation = true; |
| 1142 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1143 | int userRotationMode = Settings.System.getIntForUser(resolver, |
| 1144 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1145 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 1146 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
| 1147 | if (mUserRotationMode != userRotationMode) { |
| 1148 | mUserRotationMode = userRotationMode; |
| 1149 | updateRotation = true; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1150 | updateOrientationListenerLp(); |
| 1151 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1152 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1153 | if (mSystemReady) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1154 | int pointerLocation = Settings.System.getIntForUser(resolver, |
| 1155 | Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1156 | if (mPointerLocationMode != pointerLocation) { |
| 1157 | mPointerLocationMode = pointerLocation; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1158 | mHandler.sendEmptyMessage(pointerLocation != 0 ? |
| 1159 | MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1160 | } |
| 1161 | } |
| 1162 | // use screen off timeout setting as the timeout for the lockscreen |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1163 | mLockScreenTimeout = Settings.System.getIntForUser(resolver, |
| 1164 | Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT); |
| 1165 | String imId = Settings.Secure.getStringForUser(resolver, |
| 1166 | Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1167 | boolean hasSoftInput = imId != null && imId.length() > 0; |
| 1168 | if (mHasSoftInput != hasSoftInput) { |
| 1169 | mHasSoftInput = hasSoftInput; |
| 1170 | updateRotation = true; |
| 1171 | } |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1172 | if (mTransientNavigationConfirmation != null) { |
| 1173 | mTransientNavigationConfirmation.loadSetting(); |
| 1174 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1175 | } |
| 1176 | if (updateRotation) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 1177 | updateRotation(true); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1178 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | private void enablePointerLocation() { |
| 1182 | if (mPointerLocationView == null) { |
| 1183 | mPointerLocationView = new PointerLocationView(mContext); |
| 1184 | mPointerLocationView.setPrintCoords(false); |
| 1185 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1186 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 1187 | WindowManager.LayoutParams.MATCH_PARENT, |
| 1188 | WindowManager.LayoutParams.MATCH_PARENT); |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1189 | lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1190 | lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 1191 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
| 1192 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1193 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
Jeff Brown | 90fc905 | 2012-10-01 14:44:24 -0700 | [diff] [blame] | 1194 | if (ActivityManager.isHighEndGfx()) { |
| 1195 | lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 1196 | lp.privateFlags |= |
| 1197 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED; |
| 1198 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1199 | lp.format = PixelFormat.TRANSLUCENT; |
| 1200 | lp.setTitle("PointerLocation"); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1201 | WindowManager wm = (WindowManager) |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1202 | mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1203 | lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1204 | wm.addView(mPointerLocationView, lp); |
| 1205 | |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1206 | mPointerLocationPointerEventListener = new PointerLocationPointerEventListener(); |
| 1207 | mWindowManagerFuncs.registerPointerEventListener(mPointerLocationPointerEventListener); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1208 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1209 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1210 | |
| 1211 | private void disablePointerLocation() { |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1212 | if (mPointerLocationPointerEventListener != null) { |
| 1213 | mWindowManagerFuncs.unregisterPointerEventListener( |
| 1214 | mPointerLocationPointerEventListener); |
| 1215 | mPointerLocationPointerEventListener = null; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | if (mPointerLocationView != null) { |
| 1219 | WindowManager wm = (WindowManager) |
| 1220 | mContext.getSystemService(Context.WINDOW_SERVICE); |
| 1221 | wm.removeView(mPointerLocationView); |
| 1222 | mPointerLocationView = null; |
| 1223 | } |
| 1224 | } |
| 1225 | |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1226 | private int readRotation(int resID) { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1227 | try { |
| 1228 | int rotation = mContext.getResources().getInteger(resID); |
| 1229 | switch (rotation) { |
| 1230 | case 0: |
| 1231 | return Surface.ROTATION_0; |
| 1232 | case 90: |
| 1233 | return Surface.ROTATION_90; |
| 1234 | case 180: |
| 1235 | return Surface.ROTATION_180; |
| 1236 | case 270: |
| 1237 | return Surface.ROTATION_270; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1238 | } |
| 1239 | } catch (Resources.NotFoundException e) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1240 | // fall through |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1241 | } |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1242 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | /** {@inheritDoc} */ |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1246 | @Override |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1247 | public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1248 | int type = attrs.type; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1249 | |
| 1250 | outAppOp[0] = AppOpsManager.OP_NONE; |
| 1251 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1252 | if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW |
| 1253 | || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1254 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1255 | } |
| 1256 | String permission = null; |
| 1257 | switch (type) { |
| 1258 | case TYPE_TOAST: |
| 1259 | // XXX right now the app process has complete control over |
| 1260 | // this... should introduce a token to let the system |
| 1261 | // monitor/control what they are doing. |
| 1262 | break; |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 1263 | case TYPE_DREAM: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1264 | case TYPE_INPUT_METHOD: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1265 | case TYPE_WALLPAPER: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1266 | case TYPE_PRIVATE_PRESENTATION: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1267 | // The window manager will check these. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1268 | break; |
| 1269 | case TYPE_PHONE: |
| 1270 | case TYPE_PRIORITY_PHONE: |
| 1271 | case TYPE_SYSTEM_ALERT: |
| 1272 | case TYPE_SYSTEM_ERROR: |
| 1273 | case TYPE_SYSTEM_OVERLAY: |
| 1274 | permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1275 | outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1276 | break; |
| 1277 | default: |
| 1278 | permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
| 1279 | } |
| 1280 | if (permission != null) { |
| 1281 | if (mContext.checkCallingOrSelfPermission(permission) |
| 1282 | != PackageManager.PERMISSION_GRANTED) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1283 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1284 | } |
| 1285 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1286 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1287 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1288 | |
| 1289 | @Override |
| 1290 | public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) { |
| 1291 | |
| 1292 | // If this switch statement is modified, modify the comment in the declarations of |
| 1293 | // the type in {@link WindowManager.LayoutParams} as well. |
| 1294 | switch (attrs.type) { |
| 1295 | default: |
| 1296 | // These are the windows that by default are shown only to the user that created |
| 1297 | // them. If this needs to be overridden, set |
| 1298 | // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in |
| 1299 | // {@link WindowManager.LayoutParams}. Note that permission |
| 1300 | // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well. |
| 1301 | if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) { |
| 1302 | return true; |
| 1303 | } |
| 1304 | break; |
| 1305 | |
| 1306 | // These are the windows that by default are shown to all users. However, to |
| 1307 | // protect against spoofing, check permissions below. |
| 1308 | case TYPE_APPLICATION_STARTING: |
| 1309 | case TYPE_BOOT_PROGRESS: |
| 1310 | case TYPE_DISPLAY_OVERLAY: |
| 1311 | case TYPE_HIDDEN_NAV_CONSUMER: |
| 1312 | case TYPE_KEYGUARD: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1313 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1314 | case TYPE_KEYGUARD_DIALOG: |
| 1315 | case TYPE_MAGNIFICATION_OVERLAY: |
| 1316 | case TYPE_NAVIGATION_BAR: |
| 1317 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1318 | case TYPE_PHONE: |
| 1319 | case TYPE_POINTER: |
| 1320 | case TYPE_PRIORITY_PHONE: |
| 1321 | case TYPE_RECENTS_OVERLAY: |
| 1322 | case TYPE_SEARCH_BAR: |
| 1323 | case TYPE_STATUS_BAR: |
| 1324 | case TYPE_STATUS_BAR_PANEL: |
| 1325 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 1326 | case TYPE_SYSTEM_DIALOG: |
| 1327 | case TYPE_UNIVERSE_BACKGROUND: |
| 1328 | case TYPE_VOLUME_OVERLAY: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1329 | case TYPE_PRIVATE_PRESENTATION: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1330 | break; |
| 1331 | } |
| 1332 | |
| 1333 | // Check if third party app has set window to system window type. |
| 1334 | return mContext.checkCallingOrSelfPermission( |
| 1335 | android.Manifest.permission.INTERNAL_SYSTEM_WINDOW) |
| 1336 | != PackageManager.PERMISSION_GRANTED; |
| 1337 | } |
| 1338 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1339 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1340 | public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) { |
| 1341 | switch (attrs.type) { |
| 1342 | case TYPE_SYSTEM_OVERLAY: |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1343 | case TYPE_SECURE_SYSTEM_OVERLAY: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1344 | // These types of windows can't receive input events. |
| 1345 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1346 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1347 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1348 | break; |
| 1349 | } |
| 1350 | } |
| 1351 | |
| 1352 | void readLidState() { |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 1353 | mLidState = mWindowManagerFuncs.getLidState(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1354 | } |
| 1355 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1356 | private boolean isHidden(int accessibilityMode) { |
| 1357 | switch (accessibilityMode) { |
| 1358 | case 1: |
| 1359 | return mLidState == LID_CLOSED; |
| 1360 | case 2: |
| 1361 | return mLidState == LID_OPEN; |
| 1362 | default: |
| 1363 | return false; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1364 | } |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1365 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1366 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1367 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1368 | @Override |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1369 | public void adjustConfigurationLw(Configuration config, int keyboardPresence, |
| 1370 | int navigationPresence) { |
| 1371 | mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0; |
| 1372 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1373 | readConfigurationDependentBehaviors(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1374 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1375 | applyLidSwitchState(); |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1376 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1377 | if (config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 1378 | || (keyboardPresence == PRESENCE_INTERNAL |
| 1379 | && isHidden(mLidKeyboardAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1380 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1381 | if (!mHasSoftInput) { |
| 1382 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES; |
| 1383 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1384 | } |
| 1385 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1386 | if (config.navigation == Configuration.NAVIGATION_NONAV |
| 1387 | || (navigationPresence == PRESENCE_INTERNAL |
| 1388 | && isHidden(mLidNavigationAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1389 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES; |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1390 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1391 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1392 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1393 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1394 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1395 | public int windowTypeToLayerLw(int type) { |
| 1396 | if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1397 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1398 | } |
| 1399 | switch (type) { |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1400 | case TYPE_UNIVERSE_BACKGROUND: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1401 | return 1; |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1402 | case TYPE_PRIVATE_PRESENTATION: |
| 1403 | return 2; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1404 | case TYPE_WALLPAPER: |
| 1405 | // wallpaper is at the bottom, though the window manager may move it. |
| 1406 | return 2; |
| 1407 | case TYPE_PHONE: |
| 1408 | return 3; |
| 1409 | case TYPE_SEARCH_BAR: |
| 1410 | return 4; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1411 | case TYPE_RECENTS_OVERLAY: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1412 | case TYPE_SYSTEM_DIALOG: |
| 1413 | return 5; |
| 1414 | case TYPE_TOAST: |
| 1415 | // toasts and the plugged-in battery thing |
| 1416 | return 6; |
| 1417 | case TYPE_PRIORITY_PHONE: |
| 1418 | // SIM errors and unlock. Not sure if this really should be in a high layer. |
| 1419 | return 7; |
| 1420 | case TYPE_DREAM: |
| 1421 | // used for Dreams (screensavers with TYPE_DREAM windows) |
| 1422 | return 8; |
| 1423 | case TYPE_SYSTEM_ALERT: |
| 1424 | // like the ANR / app crashed dialogs |
| 1425 | return 9; |
| 1426 | case TYPE_INPUT_METHOD: |
| 1427 | // on-screen keyboards and other such input method user interfaces go here. |
| 1428 | return 10; |
| 1429 | case TYPE_INPUT_METHOD_DIALOG: |
| 1430 | // on-screen keyboards and other such input method user interfaces go here. |
| 1431 | return 11; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1432 | case TYPE_KEYGUARD_SCRIM: |
| 1433 | // the safety window that shows behind keyguard while keyguard is starting |
| 1434 | return 12; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1435 | case TYPE_KEYGUARD: |
| 1436 | // the keyguard; nothing on top of these can take focus, since they are |
| 1437 | // responsible for power management when displayed. |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1438 | return 13; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1439 | case TYPE_KEYGUARD_DIALOG: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1440 | return 14; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1441 | case TYPE_STATUS_BAR_SUB_PANEL: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1442 | return 15; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1443 | case TYPE_STATUS_BAR: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1444 | return 16; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1445 | case TYPE_STATUS_BAR_PANEL: |
| 1446 | return 17; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1447 | case TYPE_VOLUME_OVERLAY: |
| 1448 | // the on-screen volume indicator and controller shown when the user |
| 1449 | // changes the device volume |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1450 | return 18; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1451 | case TYPE_SYSTEM_OVERLAY: |
| 1452 | // the on-screen volume indicator and controller shown when the user |
| 1453 | // changes the device volume |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1454 | return 19; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1455 | case TYPE_NAVIGATION_BAR: |
| 1456 | // the navigation bar, if available, shows atop most things |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1457 | return 20; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1458 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1459 | // some panels (e.g. search) need to show on top of the navigation bar |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1460 | return 21; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1461 | case TYPE_SYSTEM_ERROR: |
| 1462 | // system-level error dialogs |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1463 | return 22; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1464 | case TYPE_MAGNIFICATION_OVERLAY: |
| 1465 | // used to highlight the magnified portion of a display |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1466 | return 23; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1467 | case TYPE_DISPLAY_OVERLAY: |
| 1468 | // used to simulate secondary display devices |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1469 | return 24; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1470 | case TYPE_DRAG: |
| 1471 | // the drag layer: input for drag-and-drop is associated with this window, |
| 1472 | // which sits above all other focusable windows |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1473 | return 25; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1474 | case TYPE_SECURE_SYSTEM_OVERLAY: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1475 | return 26; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1476 | case TYPE_BOOT_PROGRESS: |
| 1477 | return 27; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1478 | case TYPE_POINTER: |
| 1479 | // the (mouse) pointer layer |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1480 | return 28; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1481 | case TYPE_HIDDEN_NAV_CONSUMER: |
| 1482 | return 29; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1483 | } |
| 1484 | Log.e(TAG, "Unknown window type: " + type); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1485 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1486 | } |
| 1487 | |
| 1488 | /** {@inheritDoc} */ |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1489 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1490 | public int subWindowTypeToLayerLw(int type) { |
| 1491 | switch (type) { |
| 1492 | case TYPE_APPLICATION_PANEL: |
| 1493 | case TYPE_APPLICATION_ATTACHED_DIALOG: |
| 1494 | return APPLICATION_PANEL_SUBLAYER; |
| 1495 | case TYPE_APPLICATION_MEDIA: |
| 1496 | return APPLICATION_MEDIA_SUBLAYER; |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 1497 | case TYPE_APPLICATION_MEDIA_OVERLAY: |
| 1498 | return APPLICATION_MEDIA_OVERLAY_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1499 | case TYPE_APPLICATION_SUB_PANEL: |
| 1500 | return APPLICATION_SUB_PANEL_SUBLAYER; |
| 1501 | } |
| 1502 | Log.e(TAG, "Unknown sub-window type: " + type); |
| 1503 | return 0; |
| 1504 | } |
| 1505 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1506 | @Override |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 1507 | public int getMaxWallpaperLayer() { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1508 | return windowTypeToLayerLw(TYPE_STATUS_BAR); |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 1509 | } |
| 1510 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1511 | @Override |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1512 | public int getAboveUniverseLayer() { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1513 | return windowTypeToLayerLw(TYPE_SYSTEM_ERROR); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1514 | } |
| 1515 | |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1516 | public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1517 | if (mHasNavigationBar) { |
| 1518 | // For a basic navigation bar, when we are in landscape mode we place |
| 1519 | // the navigation bar to the side. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1520 | if (mNavigationBarCanMove && fullWidth > fullHeight) { |
| 1521 | return fullWidth - mNavigationBarWidthForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1522 | } |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1523 | } |
| 1524 | return fullWidth; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1525 | } |
| 1526 | |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1527 | public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1528 | if (mHasNavigationBar) { |
| 1529 | // For a basic navigation bar, when we are in portrait mode we place |
| 1530 | // the navigation bar to the bottom. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1531 | if (!mNavigationBarCanMove || fullWidth < fullHeight) { |
| 1532 | return fullHeight - mNavigationBarHeightForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1533 | } |
| 1534 | } |
| 1535 | return fullHeight; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 1536 | } |
| 1537 | |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1538 | public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
| 1539 | return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 1540 | } |
| 1541 | |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1542 | public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1543 | // There is a separate status bar at the top of the display. We don't count that as part |
| 1544 | // of the fixed decor, since it can hide; however, for purposes of configurations, |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1545 | // we do want to exclude it since applications can't generally use that part |
| 1546 | // of the screen. |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1547 | return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1548 | } |
| 1549 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1550 | @Override |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1551 | public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs) { |
| 1552 | return attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD; |
| 1553 | } |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1554 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1555 | @Override |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1556 | public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) { |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1557 | switch (attrs.type) { |
| 1558 | case TYPE_STATUS_BAR: |
| 1559 | case TYPE_NAVIGATION_BAR: |
| 1560 | case TYPE_WALLPAPER: |
| 1561 | case TYPE_DREAM: |
| 1562 | case TYPE_UNIVERSE_BACKGROUND: |
| 1563 | case TYPE_KEYGUARD: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1564 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1565 | return false; |
| 1566 | default: |
| 1567 | return true; |
| 1568 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1569 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1570 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1571 | /** {@inheritDoc} */ |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1572 | @Override |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 1573 | public View addStartingWindow(IBinder appToken, String packageName, int theme, |
| 1574 | CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 1575 | int icon, int logo, int windowFlags) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1576 | if (!SHOW_STARTING_ANIMATIONS) { |
| 1577 | return null; |
| 1578 | } |
| 1579 | if (packageName == null) { |
| 1580 | return null; |
| 1581 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1582 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 1583 | WindowManager wm = null; |
| 1584 | View view = null; |
| 1585 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1586 | try { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1587 | Context context = mContext; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1588 | if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName |
| 1589 | + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme=" |
| 1590 | + Integer.toHexString(theme)); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 1591 | if (theme != context.getThemeResId() || labelRes != 0) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1592 | try { |
| 1593 | context = context.createPackageContext(packageName, 0); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 1594 | context.setTheme(theme); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1595 | } catch (PackageManager.NameNotFoundException e) { |
| 1596 | // Ignore |
| 1597 | } |
| 1598 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1599 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1600 | Window win = PolicyManager.makeNewWindow(context); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1601 | final TypedArray ta = win.getWindowStyle(); |
| 1602 | if (ta.getBoolean( |
| 1603 | com.android.internal.R.styleable.Window_windowDisablePreview, false) |
| 1604 | || ta.getBoolean( |
| 1605 | com.android.internal.R.styleable.Window_windowShowWallpaper,false)) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1606 | return null; |
| 1607 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1608 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1609 | Resources r = context.getResources(); |
| 1610 | win.setTitle(r.getText(labelRes, nonLocalizedLabel)); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1611 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1612 | win.setType( |
| 1613 | WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); |
| 1614 | // Force the window flags: this is a fake window, so it is not really |
| 1615 | // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM |
| 1616 | // flag because we do know that the next window will take input |
| 1617 | // focus, so we want to get the IME window up on top of us right away. |
| 1618 | win.setFlags( |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1619 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1620 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 1621 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 1622 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1623 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1624 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 1625 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 1626 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1627 | |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 1628 | if (!compatInfo.supportsScreen()) { |
| 1629 | win.addFlags(WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW); |
| 1630 | } |
| 1631 | |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 1632 | win.setDefaultIcon(icon); |
| 1633 | win.setDefaultLogo(logo); |
| 1634 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1635 | win.setLayout(WindowManager.LayoutParams.MATCH_PARENT, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 1636 | WindowManager.LayoutParams.MATCH_PARENT); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1637 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1638 | final WindowManager.LayoutParams params = win.getAttributes(); |
| 1639 | params.token = appToken; |
| 1640 | params.packageName = packageName; |
| 1641 | params.windowAnimations = win.getWindowStyle().getResourceId( |
| 1642 | com.android.internal.R.styleable.Window_windowAnimationStyle, 0); |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 1643 | params.privateFlags |= |
| 1644 | WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1645 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1646 | params.setTitle("Starting " + packageName); |
| 1647 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 1648 | wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); |
| 1649 | view = win.getDecorView(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1650 | |
| 1651 | if (win.isFloating()) { |
| 1652 | // Whoops, there is no way to display an animation/preview |
| 1653 | // of such a thing! After all that work... let's skip it. |
| 1654 | // (Note that we must do this here because it is in |
| 1655 | // getDecorView() where the theme is evaluated... maybe |
| 1656 | // we should peek the floating attribute from the theme |
| 1657 | // earlier.) |
| 1658 | return null; |
| 1659 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1660 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1661 | if (DEBUG_STARTING_WINDOW) Slog.d( |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1662 | TAG, "Adding starting window for " + packageName |
| 1663 | + " / " + appToken + ": " |
| 1664 | + (view.getParent() != null ? view : null)); |
| 1665 | |
| 1666 | wm.addView(view, params); |
| 1667 | |
| 1668 | // Only return the view if it was successfully added to the |
| 1669 | // window manager... which we can tell by it having a parent. |
| 1670 | return view.getParent() != null ? view : null; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1671 | } catch (WindowManager.BadTokenException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1672 | // ignore |
| 1673 | Log.w(TAG, appToken + " already running, starting window not displayed"); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1674 | } catch (RuntimeException e) { |
| 1675 | // don't crash if something else bad happens, for example a |
| 1676 | // failure loading resources because we are loading from an app |
| 1677 | // on external storage that has been unmounted. |
| 1678 | Log.w(TAG, appToken + " failed creating starting window", e); |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 1679 | } finally { |
| 1680 | if (view != null && view.getParent() == null) { |
| 1681 | Log.w(TAG, "view not successfully added to wm, removing view"); |
| 1682 | wm.removeViewImmediate(view); |
| 1683 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1684 | } |
| 1685 | |
| 1686 | return null; |
| 1687 | } |
| 1688 | |
| 1689 | /** {@inheritDoc} */ |
| 1690 | public void removeStartingWindow(IBinder appToken, View window) { |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1691 | if (DEBUG_STARTING_WINDOW) { |
| 1692 | RuntimeException e = new RuntimeException("here"); |
| 1693 | e.fillInStackTrace(); |
| 1694 | Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e); |
| 1695 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1696 | |
| 1697 | if (window != null) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1698 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1699 | wm.removeView(window); |
| 1700 | } |
| 1701 | } |
| 1702 | |
| 1703 | /** |
| 1704 | * Preflight adding a window to the system. |
| 1705 | * |
| 1706 | * Currently enforces that three window types are singletons: |
| 1707 | * <ul> |
| 1708 | * <li>STATUS_BAR_TYPE</li> |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1709 | * <li>KEYGUARD_TYPE</li> |
| 1710 | * </ul> |
| 1711 | * |
| 1712 | * @param win The window to be added |
| 1713 | * @param attrs Information about the window to be added |
| 1714 | * |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1715 | * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, |
| 1716 | * WindowManagerImpl.ADD_MULTIPLE_SINGLETON |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1717 | */ |
| 1718 | public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) { |
| 1719 | switch (attrs.type) { |
| 1720 | case TYPE_STATUS_BAR: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 1721 | mContext.enforceCallingOrSelfPermission( |
| 1722 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1723 | "PhoneWindowManager"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1724 | if (mStatusBar != null) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1725 | if (mStatusBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1726 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1727 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1728 | } |
| 1729 | mStatusBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 1730 | mStatusBarController.setWindow(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1731 | break; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1732 | case TYPE_NAVIGATION_BAR: |
| 1733 | mContext.enforceCallingOrSelfPermission( |
| 1734 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1735 | "PhoneWindowManager"); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1736 | if (mNavigationBar != null) { |
| 1737 | if (mNavigationBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1738 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1739 | } |
| 1740 | } |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1741 | mNavigationBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 1742 | mNavigationBarController.setWindow(win); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 1743 | if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1744 | break; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 1745 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1746 | mContext.enforceCallingOrSelfPermission( |
| 1747 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1748 | "PhoneWindowManager"); |
| 1749 | break; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 1750 | case TYPE_STATUS_BAR_PANEL: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 1751 | mContext.enforceCallingOrSelfPermission( |
| 1752 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1753 | "PhoneWindowManager"); |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 1754 | break; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 1755 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 1756 | mContext.enforceCallingOrSelfPermission( |
| 1757 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1758 | "PhoneWindowManager"); |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 1759 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1760 | case TYPE_KEYGUARD: |
| 1761 | if (mKeyguard != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1762 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1763 | } |
| 1764 | mKeyguard = win; |
| 1765 | break; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1766 | case TYPE_KEYGUARD_SCRIM: |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 1767 | if (mKeyguardScrim != null) { |
| 1768 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
| 1769 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1770 | mKeyguardScrim = win; |
| 1771 | break; |
| 1772 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1773 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1774 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | /** {@inheritDoc} */ |
| 1778 | public void removeWindowLw(WindowState win) { |
| 1779 | if (mStatusBar == win) { |
| 1780 | mStatusBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 1781 | mStatusBarController.setWindow(null); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1782 | } else if (mKeyguard == win) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1783 | Log.v(TAG, "Removing keyguard window (Did it crash?)"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1784 | mKeyguard = null; |
Jim Miller | c0b676d | 2013-03-22 16:11:08 -0700 | [diff] [blame] | 1785 | mKeyguardDelegate.showScrim(); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1786 | } else if (mKeyguardScrim == win) { |
| 1787 | Log.v(TAG, "Removing keyguard scrim"); |
| 1788 | mKeyguardScrim = null; |
| 1789 | } if (mNavigationBar == win) { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1790 | mNavigationBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 1791 | mNavigationBarController.setWindow(null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1792 | } |
| 1793 | } |
| 1794 | |
| 1795 | static final boolean PRINT_ANIM = false; |
| 1796 | |
| 1797 | /** {@inheritDoc} */ |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1798 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1799 | public int selectAnimationLw(WindowState win, int transit) { |
| 1800 | if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win |
| 1801 | + ": transit=" + transit); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1802 | if (win == mStatusBar) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1803 | if (transit == TRANSIT_EXIT |
| 1804 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1805 | return R.anim.dock_top_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1806 | } else if (transit == TRANSIT_ENTER |
| 1807 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1808 | return R.anim.dock_top_enter; |
| 1809 | } |
| 1810 | } else if (win == mNavigationBar) { |
| 1811 | // This can be on either the bottom or the right. |
| 1812 | if (mNavigationBarOnBottom) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1813 | if (transit == TRANSIT_EXIT |
| 1814 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1815 | return R.anim.dock_bottom_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1816 | } else if (transit == TRANSIT_ENTER |
| 1817 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1818 | return R.anim.dock_bottom_enter; |
| 1819 | } |
| 1820 | } else { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1821 | if (transit == TRANSIT_EXIT |
| 1822 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1823 | return R.anim.dock_right_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1824 | } else if (transit == TRANSIT_ENTER |
| 1825 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1826 | return R.anim.dock_right_enter; |
| 1827 | } |
| 1828 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1829 | } |
| 1830 | |
| 1831 | if (transit == TRANSIT_PREVIEW_DONE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1832 | if (win.hasAppShownWindows()) { |
| 1833 | if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT"); |
| 1834 | return com.android.internal.R.anim.app_starting_exit; |
| 1835 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 1836 | } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1837 | && transit == TRANSIT_ENTER) { |
| 1838 | // Special case: we are animating in a dream, while the keyguard |
| 1839 | // is shown. We don't want an animation on the dream, because |
| 1840 | // we need it shown immediately with the keyguard animating away |
| 1841 | // to reveal it. |
| 1842 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | return 0; |
| 1846 | } |
| 1847 | |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 1848 | @Override |
| 1849 | public void selectRotationAnimationLw(int anim[]) { |
| 1850 | if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen=" |
| 1851 | + mTopFullscreenOpaqueWindowState + " rotationAnimation=" |
| 1852 | + (mTopFullscreenOpaqueWindowState == null ? |
| 1853 | "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation)); |
| 1854 | if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) { |
| 1855 | switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) { |
| 1856 | case ROTATION_ANIMATION_CROSSFADE: |
| 1857 | anim[0] = R.anim.rotation_animation_xfade_exit; |
| 1858 | anim[1] = R.anim.rotation_animation_enter; |
| 1859 | break; |
| 1860 | case ROTATION_ANIMATION_JUMPCUT: |
| 1861 | anim[0] = R.anim.rotation_animation_jump_exit; |
| 1862 | anim[1] = R.anim.rotation_animation_enter; |
| 1863 | break; |
| 1864 | case ROTATION_ANIMATION_ROTATE: |
| 1865 | default: |
| 1866 | anim[0] = anim[1] = 0; |
| 1867 | break; |
| 1868 | } |
| 1869 | } else { |
| 1870 | anim[0] = anim[1] = 0; |
| 1871 | } |
| 1872 | } |
| 1873 | |
| 1874 | @Override |
| 1875 | public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId, |
| 1876 | boolean forceDefault) { |
| 1877 | switch (exitAnimId) { |
| 1878 | case R.anim.rotation_animation_xfade_exit: |
| 1879 | case R.anim.rotation_animation_jump_exit: |
| 1880 | // These are the only cases that matter. |
| 1881 | if (forceDefault) { |
| 1882 | return false; |
| 1883 | } |
| 1884 | int anim[] = new int[2]; |
| 1885 | selectRotationAnimationLw(anim); |
| 1886 | return (exitAnimId == anim[0] && enterAnimId == anim[1]); |
| 1887 | default: |
| 1888 | return true; |
| 1889 | } |
| 1890 | } |
| 1891 | |
| 1892 | @Override |
Dianne Hackborn | 0c2acff | 2012-04-12 15:17:07 -0700 | [diff] [blame] | 1893 | public Animation createForceHideEnterAnimation(boolean onWallpaper) { |
| 1894 | return AnimationUtils.loadAnimation(mContext, onWallpaper |
| 1895 | ? com.android.internal.R.anim.lock_screen_wallpaper_behind_enter |
| 1896 | : com.android.internal.R.anim.lock_screen_behind_enter); |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1897 | } |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 1898 | |
| 1899 | private static void awakenDreams() { |
| 1900 | IDreamManager dreamManager = getDreamManager(); |
| 1901 | if (dreamManager != null) { |
| 1902 | try { |
| 1903 | dreamManager.awaken(); |
| 1904 | } catch (RemoteException e) { |
| 1905 | // fine, stay asleep then |
| 1906 | } |
| 1907 | } |
| 1908 | } |
| 1909 | |
| 1910 | static IDreamManager getDreamManager() { |
| 1911 | return IDreamManager.Stub.asInterface( |
| 1912 | ServiceManager.checkService(DreamService.DREAM_SERVICE)); |
| 1913 | } |
| 1914 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1915 | static ITelephony getTelephonyService() { |
Mike Lockwood | f5f4ec9 | 2011-11-08 14:05:31 -0800 | [diff] [blame] | 1916 | return ITelephony.Stub.asInterface( |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1917 | ServiceManager.checkService(Context.TELEPHONY_SERVICE)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1918 | } |
| 1919 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1920 | static IAudioService getAudioService() { |
| 1921 | IAudioService audioService = IAudioService.Stub.asInterface( |
| 1922 | ServiceManager.checkService(Context.AUDIO_SERVICE)); |
| 1923 | if (audioService == null) { |
| 1924 | Log.w(TAG, "Unable to find IAudioService interface."); |
| 1925 | } |
| 1926 | return audioService; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1927 | } |
| 1928 | |
| 1929 | boolean keyguardOn() { |
| 1930 | return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode(); |
| 1931 | } |
| 1932 | |
| 1933 | private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = { |
| 1934 | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, |
| 1935 | WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, |
| 1936 | }; |
| 1937 | |
| 1938 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1939 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1940 | public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1941 | final boolean keyguardOn = keyguardOn(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1942 | final int keyCode = event.getKeyCode(); |
| 1943 | final int repeatCount = event.getRepeatCount(); |
| 1944 | final int metaState = event.getMetaState(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1945 | final int flags = event.getFlags(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1946 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 1947 | final boolean canceled = event.isCanceled(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1948 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 1949 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1950 | Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 1951 | + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed |
| 1952 | + " canceled=" + canceled); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1953 | } |
| 1954 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1955 | // If we think we might have a volume down & power key chord on the way |
| 1956 | // but we're not sure, then tell the dispatcher to wait a little while and |
| 1957 | // try again later before dispatching. |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1958 | if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1959 | if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) { |
| 1960 | final long now = SystemClock.uptimeMillis(); |
| 1961 | final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS; |
| 1962 | if (now < timeoutTime) { |
| 1963 | return timeoutTime - now; |
| 1964 | } |
| 1965 | } |
| 1966 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
| 1967 | && mVolumeDownKeyConsumedByScreenshotChord) { |
| 1968 | if (!down) { |
| 1969 | mVolumeDownKeyConsumedByScreenshotChord = false; |
| 1970 | } |
| 1971 | return -1; |
| 1972 | } |
| 1973 | } |
| 1974 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1975 | // First we always handle the home key here, so applications |
| 1976 | // can never break it, although if keyguard is on, we do let |
| 1977 | // it handle it, because that gives us the correct 5 second |
| 1978 | // timeout. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1979 | if (keyCode == KeyEvent.KEYCODE_HOME) { |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1980 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1981 | // If we have released the home key, and didn't do anything else |
| 1982 | // while it was pressed, then it is time to go home! |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1983 | if (!down) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1984 | cancelPreloadRecentApps(); |
| 1985 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1986 | mHomePressed = false; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1987 | if (mHomeConsumed) { |
| 1988 | mHomeConsumed = false; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1989 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1990 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1991 | |
| 1992 | if (canceled) { |
| 1993 | Log.i(TAG, "Ignoring HOME; event canceled."); |
| 1994 | return -1; |
| 1995 | } |
| 1996 | |
| 1997 | // If an incoming call is ringing, HOME is totally disabled. |
| 1998 | // (The user is already on the InCallScreen at this point, |
| 1999 | // and his ONLY options are to answer or reject the call.) |
| 2000 | try { |
| 2001 | ITelephony telephonyService = getTelephonyService(); |
| 2002 | if (telephonyService != null && telephonyService.isRinging()) { |
| 2003 | Log.i(TAG, "Ignoring HOME; there's a ringing incoming call."); |
| 2004 | return -1; |
| 2005 | } |
| 2006 | } catch (RemoteException ex) { |
| 2007 | Log.w(TAG, "RemoteException from getPhoneInterface()", ex); |
| 2008 | } |
| 2009 | |
| 2010 | // Delay handling home if a double-tap is possible. |
| 2011 | if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) { |
| 2012 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case |
| 2013 | mHomeDoubleTapPending = true; |
| 2014 | mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable, |
| 2015 | ViewConfiguration.getDoubleTapTimeout()); |
| 2016 | return -1; |
| 2017 | } |
| 2018 | |
| 2019 | // Go home! |
| 2020 | launchHomeFromHotKey(); |
| 2021 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2022 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2023 | |
| 2024 | // If a system window has focus, then it doesn't make sense |
| 2025 | // right now to interact with applications. |
| 2026 | WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null; |
| 2027 | if (attrs != null) { |
| 2028 | final int type = attrs.type; |
| 2029 | if (type == WindowManager.LayoutParams.TYPE_KEYGUARD |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2030 | || type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2031 | || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) { |
| 2032 | // the "app" is keyguard, so give it the key |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2033 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2034 | } |
| 2035 | final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length; |
| 2036 | for (int i=0; i<typeCount; i++) { |
| 2037 | if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) { |
| 2038 | // don't do anything, but also don't pass it to the app |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2039 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2040 | } |
| 2041 | } |
| 2042 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2043 | |
| 2044 | // Remember that home is pressed and handle special actions. |
| 2045 | if (repeatCount == 0) { |
| 2046 | mHomePressed = true; |
| 2047 | if (mHomeDoubleTapPending) { |
| 2048 | mHomeDoubleTapPending = false; |
| 2049 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); |
| 2050 | handleDoubleTapOnHome(); |
| 2051 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI |
| 2052 | || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 2053 | preloadRecentApps(); |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2054 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2055 | } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) { |
| 2056 | if (!keyguardOn) { |
| 2057 | handleLongPressOnHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2058 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2059 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2060 | return -1; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2061 | } else if (keyCode == KeyEvent.KEYCODE_MENU) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2062 | // Hijack modified menu keys for debugging features |
| 2063 | final int chordBug = KeyEvent.META_SHIFT_ON; |
| 2064 | |
| 2065 | if (down && repeatCount == 0) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2066 | if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2067 | Intent intent = new Intent(Intent.ACTION_BUG_REPORT); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 2068 | mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, |
| 2069 | null, null, null, 0, null, null); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2070 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2071 | } else if (SHOW_PROCESSES_ON_ALT_MENU && |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2072 | (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2073 | Intent service = new Intent(); |
| 2074 | service.setClassName(mContext, "com.android.server.LoadAverageService"); |
| 2075 | ContentResolver res = mContext.getContentResolver(); |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2076 | boolean shown = Settings.Global.getInt( |
| 2077 | res, Settings.Global.SHOW_PROCESSES, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2078 | if (!shown) { |
| 2079 | mContext.startService(service); |
| 2080 | } else { |
| 2081 | mContext.stopService(service); |
| 2082 | } |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2083 | Settings.Global.putInt( |
| 2084 | res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2085 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2086 | } |
| 2087 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2088 | } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2089 | if (down) { |
| 2090 | if (repeatCount == 0) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2091 | mSearchKeyShortcutPending = true; |
| 2092 | mConsumeSearchKeyUp = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2093 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2094 | } else { |
| 2095 | mSearchKeyShortcutPending = false; |
| 2096 | if (mConsumeSearchKeyUp) { |
| 2097 | mConsumeSearchKeyUp = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2098 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2099 | } |
| 2100 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2101 | return 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2102 | } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) { |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2103 | if (!keyguardOn) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2104 | if (down && repeatCount == 0) { |
| 2105 | preloadRecentApps(); |
| 2106 | } else if (!down) { |
| 2107 | toggleRecentApps(); |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2108 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2109 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2110 | return -1; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2111 | } else if (keyCode == KeyEvent.KEYCODE_ASSIST) { |
| 2112 | if (down) { |
| 2113 | if (repeatCount == 0) { |
| 2114 | mAssistKeyLongPressed = false; |
| 2115 | } else if (repeatCount == 1) { |
| 2116 | mAssistKeyLongPressed = true; |
| 2117 | if (!keyguardOn) { |
| 2118 | launchAssistLongPressAction(); |
| 2119 | } |
| 2120 | } |
| 2121 | } else { |
| 2122 | if (mAssistKeyLongPressed) { |
| 2123 | mAssistKeyLongPressed = false; |
| 2124 | } else { |
| 2125 | if (!keyguardOn) { |
| 2126 | launchAssistAction(); |
| 2127 | } |
| 2128 | } |
| 2129 | } |
| 2130 | return -1; |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 2131 | } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) { |
| 2132 | if (down && repeatCount == 0) { |
| 2133 | mHandler.post(mScreenshotRunnable); |
| 2134 | } |
| 2135 | return -1; |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 2136 | } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP |
| 2137 | || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) { |
| 2138 | if (down) { |
| 2139 | int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1; |
| 2140 | |
| 2141 | // Disable autobrightness if it's on |
| 2142 | int auto = Settings.System.getIntForUser( |
| 2143 | mContext.getContentResolver(), |
| 2144 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 2145 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 2146 | UserHandle.USER_CURRENT_OR_SELF); |
| 2147 | if (auto != 0) { |
| 2148 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2149 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 2150 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 2151 | UserHandle.USER_CURRENT_OR_SELF); |
| 2152 | } |
| 2153 | |
| 2154 | int min = mPowerManager.getMinimumScreenBrightnessSetting(); |
| 2155 | int max = mPowerManager.getMaximumScreenBrightnessSetting(); |
| 2156 | int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction; |
| 2157 | int brightness = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 2158 | Settings.System.SCREEN_BRIGHTNESS, |
| 2159 | mPowerManager.getDefaultScreenBrightnessSetting(), |
| 2160 | UserHandle.USER_CURRENT_OR_SELF); |
| 2161 | brightness += step; |
| 2162 | // Make sure we don't go beyond the limits. |
| 2163 | brightness = Math.min(max, brightness); |
| 2164 | brightness = Math.max(min, brightness); |
| 2165 | |
| 2166 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2167 | Settings.System.SCREEN_BRIGHTNESS, brightness, |
| 2168 | UserHandle.USER_CURRENT_OR_SELF); |
| 2169 | Intent intent = new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG); |
| 2170 | mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF); |
| 2171 | } |
| 2172 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2173 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2174 | |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 2175 | // Shortcuts are invoked through Search+key, so intercept those here |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2176 | // Any printing key that is chorded with Search should be consumed |
| 2177 | // even if no shortcut was invoked. This prevents text from being |
| 2178 | // inadvertently inserted when using a keyboard that has built-in macro |
| 2179 | // shortcut keys (that emit Search+x) and some of them are not registered. |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2180 | if (mSearchKeyShortcutPending) { |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2181 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 2182 | if (kcm.isPrintingKey(keyCode)) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2183 | mConsumeSearchKeyUp = true; |
| 2184 | mSearchKeyShortcutPending = false; |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2185 | if (down && repeatCount == 0 && !keyguardOn) { |
| 2186 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState); |
| 2187 | if (shortcutIntent != null) { |
| 2188 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2189 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2190 | mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2191 | } catch (ActivityNotFoundException ex) { |
| 2192 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2193 | + "the activity to which it is registered was not found: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2194 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2195 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2196 | } else { |
| 2197 | Slog.i(TAG, "Dropping unregistered shortcut key combination: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2198 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2199 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2200 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2201 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2202 | } |
| 2203 | } |
| 2204 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2205 | // Invoke shortcuts using Meta. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2206 | if (down && repeatCount == 0 && !keyguardOn |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2207 | && (metaState & KeyEvent.META_META_ON) != 0) { |
| 2208 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2209 | if (kcm.isPrintingKey(keyCode)) { |
| 2210 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, |
| 2211 | metaState & ~(KeyEvent.META_META_ON |
| 2212 | | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON)); |
| 2213 | if (shortcutIntent != null) { |
| 2214 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2215 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2216 | mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2217 | } catch (ActivityNotFoundException ex) { |
| 2218 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2219 | + "the activity to which it is registered was not found: " |
| 2220 | + "META+" + KeyEvent.keyCodeToString(keyCode), ex); |
| 2221 | } |
| 2222 | return -1; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2223 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2224 | } |
| 2225 | } |
| 2226 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2227 | // Handle application launch keys. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2228 | if (down && repeatCount == 0 && !keyguardOn) { |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2229 | String category = sApplicationLaunchKeyCategories.get(keyCode); |
| 2230 | if (category != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 2231 | Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2232 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2233 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2234 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2235 | } catch (ActivityNotFoundException ex) { |
| 2236 | Slog.w(TAG, "Dropping application launch key because " |
| 2237 | + "the activity to which it is registered was not found: " |
| 2238 | + "keyCode=" + keyCode + ", category=" + category, ex); |
| 2239 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2240 | return -1; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2241 | } |
| 2242 | } |
| 2243 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2244 | // Display task switcher for ALT-TAB or Meta-TAB. |
| 2245 | if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) { |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2246 | if (mRecentAppsDialogHeldModifiers == 0 && !keyguardOn) { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2247 | final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK; |
| 2248 | if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON) |
| 2249 | || KeyEvent.metaStateHasModifiers( |
| 2250 | shiftlessModifiers, KeyEvent.META_META_ON)) { |
| 2251 | mRecentAppsDialogHeldModifiers = shiftlessModifiers; |
| 2252 | showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW); |
| 2253 | return -1; |
| 2254 | } |
| 2255 | } |
| 2256 | } else if (!down && mRecentAppsDialogHeldModifiers != 0 |
| 2257 | && (metaState & mRecentAppsDialogHeldModifiers) == 0) { |
| 2258 | mRecentAppsDialogHeldModifiers = 0; |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2259 | showOrHideRecentAppsDialog(keyguardOn ? RECENT_APPS_BEHAVIOR_DISMISS : |
| 2260 | RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2261 | } |
| 2262 | |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 2263 | // Handle keyboard language switching. |
| 2264 | if (down && repeatCount == 0 |
| 2265 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 2266 | || (keyCode == KeyEvent.KEYCODE_SPACE |
| 2267 | && (metaState & KeyEvent.META_CTRL_MASK) != 0))) { |
| 2268 | int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1; |
| 2269 | mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction); |
| 2270 | return -1; |
| 2271 | } |
| 2272 | if (mLanguageSwitchKeyPressed && !down |
| 2273 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 2274 | || keyCode == KeyEvent.KEYCODE_SPACE)) { |
| 2275 | mLanguageSwitchKeyPressed = false; |
| 2276 | return -1; |
| 2277 | } |
| 2278 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 2279 | if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) { |
| 2280 | return -1; |
| 2281 | } |
| 2282 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2283 | // Let the application handle the key. |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2284 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2285 | } |
| 2286 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2287 | /** {@inheritDoc} */ |
| 2288 | @Override |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2289 | public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 2290 | // Note: This method is only called if the initial down was unhandled. |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2291 | if (DEBUG_INPUT) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2292 | Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction() |
| 2293 | + ", flags=" + event.getFlags() |
| 2294 | + ", keyCode=" + event.getKeyCode() |
| 2295 | + ", scanCode=" + event.getScanCode() |
| 2296 | + ", metaState=" + event.getMetaState() |
| 2297 | + ", repeatCount=" + event.getRepeatCount() |
| 2298 | + ", policyFlags=" + policyFlags); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2299 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2300 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2301 | KeyEvent fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2302 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 2303 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 2304 | final int keyCode = event.getKeyCode(); |
| 2305 | final int metaState = event.getMetaState(); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2306 | final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN |
| 2307 | && event.getRepeatCount() == 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2308 | |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 2309 | // Check for fallback actions specified by the key character map. |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2310 | final FallbackAction fallbackAction; |
| 2311 | if (initialDown) { |
| 2312 | fallbackAction = kcm.getFallbackAction(keyCode, metaState); |
| 2313 | } else { |
| 2314 | fallbackAction = mFallbackActions.get(keyCode); |
| 2315 | } |
| 2316 | |
| 2317 | if (fallbackAction != null) { |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2318 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2319 | Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode |
| 2320 | + " metaState=" + Integer.toHexString(fallbackAction.metaState)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2321 | } |
| 2322 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2323 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 2324 | fallbackEvent = KeyEvent.obtain( |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2325 | event.getDownTime(), event.getEventTime(), |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2326 | event.getAction(), fallbackAction.keyCode, |
| 2327 | event.getRepeatCount(), fallbackAction.metaState, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2328 | event.getDeviceId(), event.getScanCode(), |
| 2329 | flags, event.getSource(), null); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2330 | |
| 2331 | if (!interceptFallback(win, fallbackEvent, policyFlags)) { |
| 2332 | fallbackEvent.recycle(); |
| 2333 | fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2334 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2335 | |
| 2336 | if (initialDown) { |
| 2337 | mFallbackActions.put(keyCode, fallbackAction); |
| 2338 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 2339 | mFallbackActions.remove(keyCode); |
| 2340 | fallbackAction.recycle(); |
| 2341 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2342 | } |
| 2343 | } |
| 2344 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2345 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2346 | if (fallbackEvent == null) { |
| 2347 | Slog.d(TAG, "No fallback."); |
| 2348 | } else { |
| 2349 | Slog.d(TAG, "Performing fallback: " + fallbackEvent); |
| 2350 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2351 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2352 | return fallbackEvent; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2353 | } |
| 2354 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2355 | private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) { |
| 2356 | int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags, true); |
| 2357 | if ((actions & ACTION_PASS_TO_USER) != 0) { |
| 2358 | long delayMillis = interceptKeyBeforeDispatching( |
| 2359 | win, fallbackEvent, policyFlags); |
| 2360 | if (delayMillis == 0) { |
| 2361 | return true; |
| 2362 | } |
| 2363 | } |
| 2364 | return false; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2365 | } |
| 2366 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2367 | private void launchAssistLongPressAction() { |
| 2368 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 2369 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
| 2370 | |
| 2371 | // launch the search activity |
| 2372 | Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS); |
| 2373 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2374 | try { |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2375 | // TODO: This only stops the factory-installed search manager. |
| 2376 | // Need to formalize an API to handle others |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2377 | SearchManager searchManager = getSearchManager(); |
| 2378 | if (searchManager != null) { |
| 2379 | searchManager.stopSearch(); |
| 2380 | } |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2381 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2382 | } catch (ActivityNotFoundException e) { |
| 2383 | Slog.w(TAG, "No activity to handle assist long press action.", e); |
| 2384 | } |
| 2385 | } |
| 2386 | |
| 2387 | private void launchAssistAction() { |
| 2388 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 2389 | Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)) |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2390 | .getAssistIntent(mContext, true, UserHandle.USER_CURRENT); |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2391 | if (intent != null) { |
| 2392 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 2393 | | Intent.FLAG_ACTIVITY_SINGLE_TOP |
| 2394 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 2395 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2396 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2397 | } catch (ActivityNotFoundException e) { |
| 2398 | Slog.w(TAG, "No activity to handle assist action.", e); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2399 | } |
| 2400 | } |
| 2401 | } |
| 2402 | |
| 2403 | private SearchManager getSearchManager() { |
| 2404 | if (mSearchManager == null) { |
| 2405 | mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE); |
| 2406 | } |
| 2407 | return mSearchManager; |
| 2408 | } |
| 2409 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2410 | private void preloadRecentApps() { |
| 2411 | mPreloadedRecentApps = true; |
| 2412 | try { |
| 2413 | IStatusBarService statusbar = getStatusBarService(); |
| 2414 | if (statusbar != null) { |
| 2415 | statusbar.preloadRecentApps(); |
| 2416 | } |
| 2417 | } catch (RemoteException e) { |
| 2418 | Slog.e(TAG, "RemoteException when preloading recent apps", e); |
| 2419 | // re-acquire status bar service next time it is needed. |
| 2420 | mStatusBarService = null; |
| 2421 | } |
| 2422 | } |
| 2423 | |
| 2424 | private void cancelPreloadRecentApps() { |
| 2425 | if (mPreloadedRecentApps) { |
| 2426 | mPreloadedRecentApps = false; |
| 2427 | try { |
| 2428 | IStatusBarService statusbar = getStatusBarService(); |
| 2429 | if (statusbar != null) { |
| 2430 | statusbar.cancelPreloadRecentApps(); |
| 2431 | } |
| 2432 | } catch (RemoteException e) { |
| 2433 | Slog.e(TAG, "RemoteException when showing recent apps", e); |
| 2434 | // re-acquire status bar service next time it is needed. |
| 2435 | mStatusBarService = null; |
| 2436 | } |
| 2437 | } |
| 2438 | } |
| 2439 | |
| 2440 | private void toggleRecentApps() { |
| 2441 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
| 2442 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS); |
| 2443 | try { |
| 2444 | IStatusBarService statusbar = getStatusBarService(); |
| 2445 | if (statusbar != null) { |
| 2446 | statusbar.toggleRecentApps(); |
| 2447 | } |
| 2448 | } catch (RemoteException e) { |
| 2449 | Slog.e(TAG, "RemoteException when showing recent apps", e); |
| 2450 | // re-acquire status bar service next time it is needed. |
| 2451 | mStatusBarService = null; |
| 2452 | } |
| 2453 | } |
| 2454 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2455 | /** |
| 2456 | * A home key -> launch home action was detected. Take the appropriate action |
| 2457 | * given the situation with the keyguard. |
| 2458 | */ |
| 2459 | void launchHomeFromHotKey() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2460 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotHidden()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2461 | // don't launch home if keyguard showing |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2462 | } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2463 | // when in keyguard restricted mode, must first verify unlock |
| 2464 | // before launching home |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2465 | mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2466 | public void onKeyguardExitResult(boolean success) { |
| 2467 | if (success) { |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 2468 | try { |
| 2469 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 2470 | } catch (RemoteException e) { |
| 2471 | } |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 2472 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2473 | startDockOrHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2474 | } |
| 2475 | } |
| 2476 | }); |
| 2477 | } else { |
| 2478 | // no keyguard stuff to worry about, just launch home! |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 2479 | try { |
| 2480 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 2481 | } catch (RemoteException e) { |
| 2482 | } |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 2483 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2484 | startDockOrHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2485 | } |
| 2486 | } |
| 2487 | |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 2488 | private final Runnable mClearHideNavigationFlag = new Runnable() { |
| 2489 | @Override |
| 2490 | public void run() { |
| 2491 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 2492 | // Clear flags. |
| 2493 | mForceClearedSystemUiFlags &= |
| 2494 | ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 2495 | } |
| 2496 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2497 | } |
| 2498 | }; |
| 2499 | |
| 2500 | /** |
| 2501 | * Input handler used while nav bar is hidden. Captures any touch on the screen, |
| 2502 | * to determine when the nav bar should be shown and prevent applications from |
| 2503 | * receiving those touches. |
| 2504 | */ |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2505 | final class HideNavInputEventReceiver extends InputEventReceiver { |
| 2506 | public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 2507 | super(inputChannel, looper); |
| 2508 | } |
| 2509 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2510 | @Override |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2511 | public void onInputEvent(InputEvent event) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2512 | boolean handled = false; |
| 2513 | try { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 2514 | if (event instanceof MotionEvent |
| 2515 | && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 2516 | final MotionEvent motionEvent = (MotionEvent)event; |
| 2517 | if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2518 | // When the user taps down, we re-show the nav bar. |
| 2519 | boolean changed = false; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 2520 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2521 | // Any user activity always causes us to show the |
| 2522 | // navigation controls, if they had been hidden. |
| 2523 | // We also clear the low profile and only content |
| 2524 | // flags so that tapping on the screen will atomically |
| 2525 | // restore all currently hidden screen decorations. |
| 2526 | int newVal = mResettingSystemUiFlags | |
| 2527 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | |
| 2528 | View.SYSTEM_UI_FLAG_LOW_PROFILE | |
| 2529 | View.SYSTEM_UI_FLAG_FULLSCREEN; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2530 | if (mResettingSystemUiFlags != newVal) { |
| 2531 | mResettingSystemUiFlags = newVal; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2532 | changed = true; |
| 2533 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2534 | // We don't allow the system's nav bar to be hidden |
| 2535 | // again for 1 second, to prevent applications from |
| 2536 | // spamming us and keeping it from being shown. |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2537 | newVal = mForceClearedSystemUiFlags | |
| 2538 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2539 | if (mForceClearedSystemUiFlags != newVal) { |
| 2540 | mForceClearedSystemUiFlags = newVal; |
| 2541 | changed = true; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 2542 | mHandler.postDelayed(mClearHideNavigationFlag, 1000); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2543 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2544 | } |
| 2545 | if (changed) { |
| 2546 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 2547 | } |
| 2548 | } |
| 2549 | } |
| 2550 | } finally { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2551 | finishInputEvent(event, handled); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2552 | } |
| 2553 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2554 | } |
| 2555 | final InputEventReceiver.Factory mHideNavInputEventReceiverFactory = |
| 2556 | new InputEventReceiver.Factory() { |
| 2557 | @Override |
| 2558 | public InputEventReceiver createInputEventReceiver( |
| 2559 | InputChannel inputChannel, Looper looper) { |
| 2560 | return new HideNavInputEventReceiver(inputChannel, looper); |
| 2561 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2562 | }; |
| 2563 | |
| 2564 | @Override |
| 2565 | public int adjustSystemUiVisibilityLw(int visibility) { |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 2566 | mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
| 2567 | mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2568 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2569 | // Reset any bits in mForceClearingStatusBarVisibility that |
| 2570 | // are now clear. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2571 | mResettingSystemUiFlags &= visibility; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2572 | // Clear any bits in the new visibility that are currently being |
| 2573 | // force cleared, before reporting it. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2574 | return visibility & ~mResettingSystemUiFlags |
| 2575 | & ~mForceClearedSystemUiFlags; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2576 | } |
| 2577 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2578 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2579 | public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) { |
| 2580 | final int fl = attrs.flags; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2581 | final int systemUiVisibility = (attrs.systemUiVisibility|attrs.subtreeSystemUiVisibility); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2582 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2583 | if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2584 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2585 | int availRight, availBottom; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2586 | if (mCanHideNavigationBar && |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2587 | (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2588 | availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 2589 | availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
| 2590 | } else { |
| 2591 | availRight = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 2592 | availBottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
| 2593 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2594 | if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 2595 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 2596 | contentInset.set(mStableFullscreenLeft, mStableFullscreenTop, |
| 2597 | availRight - mStableFullscreenRight, |
| 2598 | availBottom - mStableFullscreenBottom); |
| 2599 | } else { |
| 2600 | contentInset.set(mStableLeft, mStableTop, |
| 2601 | availRight - mStableRight, availBottom - mStableBottom); |
| 2602 | } |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2603 | } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) { |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2604 | contentInset.setEmpty(); |
| 2605 | } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2606 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) { |
| 2607 | contentInset.set(mCurLeft, mCurTop, |
| 2608 | availRight - mCurRight, availBottom - mCurBottom); |
| 2609 | } else { |
| 2610 | contentInset.set(mCurLeft, mCurTop, |
| 2611 | availRight - mCurRight, availBottom - mCurBottom); |
| 2612 | } |
| 2613 | return; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2614 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2615 | contentInset.setEmpty(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2616 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2617 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2618 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2619 | @Override |
| 2620 | public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight, |
| 2621 | int displayRotation) { |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2622 | final int overscanLeft, overscanTop, overscanRight, overscanBottom; |
| 2623 | if (isDefaultDisplay) { |
| 2624 | switch (displayRotation) { |
| 2625 | case Surface.ROTATION_90: |
| 2626 | overscanLeft = mOverscanTop; |
| 2627 | overscanTop = mOverscanRight; |
| 2628 | overscanRight = mOverscanBottom; |
| 2629 | overscanBottom = mOverscanLeft; |
| 2630 | break; |
| 2631 | case Surface.ROTATION_180: |
| 2632 | overscanLeft = mOverscanRight; |
| 2633 | overscanTop = mOverscanBottom; |
| 2634 | overscanRight = mOverscanLeft; |
| 2635 | overscanBottom = mOverscanTop; |
| 2636 | break; |
| 2637 | case Surface.ROTATION_270: |
| 2638 | overscanLeft = mOverscanBottom; |
| 2639 | overscanTop = mOverscanLeft; |
| 2640 | overscanRight = mOverscanTop; |
| 2641 | overscanBottom = mOverscanRight; |
| 2642 | break; |
| 2643 | default: |
| 2644 | overscanLeft = mOverscanLeft; |
| 2645 | overscanTop = mOverscanTop; |
| 2646 | overscanRight = mOverscanRight; |
| 2647 | overscanBottom = mOverscanBottom; |
| 2648 | break; |
| 2649 | } |
| 2650 | } else { |
| 2651 | overscanLeft = 0; |
| 2652 | overscanTop = 0; |
| 2653 | overscanRight = 0; |
| 2654 | overscanBottom = 0; |
| 2655 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 2656 | mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0; |
| 2657 | mOverscanScreenTop = mRestrictedOverscanScreenTop = 0; |
| 2658 | mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth; |
| 2659 | mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2660 | mSystemLeft = 0; |
| 2661 | mSystemTop = 0; |
| 2662 | mSystemRight = displayWidth; |
| 2663 | mSystemBottom = displayHeight; |
| 2664 | mUnrestrictedScreenLeft = overscanLeft; |
| 2665 | mUnrestrictedScreenTop = overscanTop; |
| 2666 | mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight; |
| 2667 | mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom; |
| 2668 | mRestrictedScreenLeft = mUnrestrictedScreenLeft; |
| 2669 | mRestrictedScreenTop = mUnrestrictedScreenTop; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2670 | mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth; |
| 2671 | mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2672 | mDockLeft = mContentLeft = mStableLeft = mStableFullscreenLeft |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2673 | = mCurLeft = mUnrestrictedScreenLeft; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2674 | mDockTop = mContentTop = mStableTop = mStableFullscreenTop |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2675 | = mCurTop = mUnrestrictedScreenTop; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2676 | mDockRight = mContentRight = mStableRight = mStableFullscreenRight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2677 | = mCurRight = displayWidth - overscanRight; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2678 | mDockBottom = mContentBottom = mStableBottom = mStableFullscreenBottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2679 | = mCurBottom = displayHeight - overscanBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2680 | mDockLayer = 0x10000000; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 2681 | mStatusBarLayer = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2682 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2683 | // start with the current dock rect, which will be (0,0,displayWidth,displayHeight) |
| 2684 | final Rect pf = mTmpParentFrame; |
| 2685 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2686 | final Rect of = mTmpOverscanFrame; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2687 | final Rect vf = mTmpVisibleFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2688 | pf.left = df.left = of.left = vf.left = mDockLeft; |
| 2689 | pf.top = df.top = of.top = vf.top = mDockTop; |
| 2690 | pf.right = df.right = of.right = vf.right = mDockRight; |
| 2691 | pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2692 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2693 | if (isDefaultDisplay) { |
| 2694 | // For purposes of putting out fake window up to steal focus, we will |
| 2695 | // drive nav being hidden only by whether it is requested. |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 2696 | final int sysui = mLastSystemUiFlags; |
| 2697 | boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0; |
| 2698 | boolean navTransparent = (sysui & View.SYSTEM_UI_FLAG_TRANSPARENT_NAVIGATION) != 0; |
John Spurlock | e47193d | 2013-08-27 14:23:33 -0400 | [diff] [blame] | 2699 | boolean transientAllowed = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 2700 | navTransparent &= !transientAllowed; // transient trumps transparent |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2701 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2702 | // When the navigation bar isn't visible, we put up a fake |
| 2703 | // input window to catch all touch events. This way we can |
| 2704 | // detect when the user presses anywhere to bring back the nav |
| 2705 | // bar and ensure the application doesn't see the event. |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 2706 | if (navVisible || transientAllowed) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2707 | if (mHideNavFakeWindow != null) { |
| 2708 | mHideNavFakeWindow.dismiss(); |
| 2709 | mHideNavFakeWindow = null; |
| 2710 | } |
| 2711 | } else if (mHideNavFakeWindow == null) { |
| 2712 | mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow( |
| 2713 | mHandler.getLooper(), mHideNavInputEventReceiverFactory, |
| 2714 | "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, |
| 2715 | 0, false, false, true); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2716 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2717 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2718 | // For purposes of positioning and showing the nav bar, if we have |
| 2719 | // decided that it can't be hidden (because of the screen aspect ratio), |
| 2720 | // then take that into account. |
| 2721 | navVisible |= !mCanHideNavigationBar; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2722 | |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2723 | boolean updateSysUiVisibility = false; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2724 | if (mNavigationBar != null) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2725 | boolean transientNavBarShowing = mNavigationBarController.isTransientShowing(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2726 | // Force the navigation bar to its appropriate place and |
| 2727 | // size. We need to do this directly, instead of relying on |
| 2728 | // it to bubble up from the nav bar, because this needs to |
| 2729 | // change atomically with screen rotations. |
| 2730 | mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight); |
| 2731 | if (mNavigationBarOnBottom) { |
| 2732 | // It's a system nav bar or a portrait screen; nav bar goes on bottom. |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2733 | int top = displayHeight - overscanBottom |
| 2734 | - mNavigationBarHeightForRotation[displayRotation]; |
| 2735 | mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2736 | mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top; |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 2737 | if (transientNavBarShowing || navTransparent) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2738 | mNavigationBarController.setBarShowingLw(true); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2739 | } else if (navVisible) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2740 | mNavigationBarController.setBarShowingLw(true); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2741 | mDockBottom = mTmpNavigationFrame.top; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 2742 | mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop; |
| 2743 | mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2744 | } else { |
| 2745 | // We currently want to hide the navigation UI. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2746 | mNavigationBarController.setBarShowingLw(false); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2747 | } |
John Spurlock | b77edbf | 2013-08-21 21:04:12 -0400 | [diff] [blame] | 2748 | if (navVisible && !navTransparent && !mNavigationBar.isAnimatingLw() |
| 2749 | && !mNavigationBarController.wasRecentlyTransparent()) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 2750 | // If the opaque nav bar is currently requested to be visible, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2751 | // and not in the process of animating on or off, then |
| 2752 | // we can tell the app that it is covered by it. |
| 2753 | mSystemBottom = mTmpNavigationFrame.top; |
| 2754 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2755 | } else { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2756 | // Landscape screen; nav bar goes to the right. |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2757 | int left = displayWidth - overscanRight |
| 2758 | - mNavigationBarWidthForRotation[displayRotation]; |
| 2759 | mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2760 | mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left; |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 2761 | if (transientNavBarShowing || navTransparent) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2762 | mNavigationBarController.setBarShowingLw(true); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2763 | } else if (navVisible) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2764 | mNavigationBarController.setBarShowingLw(true); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2765 | mDockRight = mTmpNavigationFrame.left; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 2766 | mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft; |
| 2767 | mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2768 | } else { |
| 2769 | // We currently want to hide the navigation UI. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2770 | mNavigationBarController.setBarShowingLw(false); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2771 | } |
John Spurlock | b77edbf | 2013-08-21 21:04:12 -0400 | [diff] [blame] | 2772 | if (navVisible && !navTransparent && !mNavigationBar.isAnimatingLw() |
| 2773 | && !mNavigationBarController.wasRecentlyTransparent()) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2774 | // If the nav bar is currently requested to be visible, |
| 2775 | // and not in the process of animating on or off, then |
| 2776 | // we can tell the app that it is covered by it. |
| 2777 | mSystemRight = mTmpNavigationFrame.left; |
| 2778 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2779 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2780 | // Make sure the content and current rectangles are updated to |
| 2781 | // account for the restrictions from the navigation bar. |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2782 | mContentTop = mCurTop = mDockTop; |
| 2783 | mContentBottom = mCurBottom = mDockBottom; |
| 2784 | mContentLeft = mCurLeft = mDockLeft; |
| 2785 | mContentRight = mCurRight = mDockRight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2786 | mStatusBarLayer = mNavigationBar.getSurfaceLayer(); |
| 2787 | // And compute the final frame. |
| 2788 | mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame, |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2789 | mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2790 | if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2791 | if (mNavigationBarController.checkHiddenLw()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2792 | updateSysUiVisibility = true; |
| 2793 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2794 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2795 | if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)", |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2796 | mDockLeft, mDockTop, mDockRight, mDockBottom)); |
| 2797 | |
| 2798 | // decide where the status bar goes ahead of time |
| 2799 | if (mStatusBar != null) { |
| 2800 | // apply any navigation bar insets |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2801 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 2802 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 2803 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 2804 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight |
| 2805 | + mUnrestrictedScreenTop; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2806 | vf.left = mStableLeft; |
| 2807 | vf.top = mStableTop; |
| 2808 | vf.right = mStableRight; |
| 2809 | vf.bottom = mStableBottom; |
| 2810 | |
| 2811 | mStatusBarLayer = mStatusBar.getSurfaceLayer(); |
| 2812 | |
| 2813 | // Let the status bar determine its size. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2814 | mStatusBar.computeFrameLw(pf, df, vf, vf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2815 | |
| 2816 | // For layout, the status bar is always at the top with our fixed height. |
| 2817 | mStableTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 2818 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 2819 | boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0; |
| 2820 | boolean statusBarTransparent = (sysui & View.SYSTEM_UI_FLAG_TRANSPARENT_STATUS) != 0; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 2821 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2822 | // If the status bar is hidden, we don't want to cause |
| 2823 | // windows behind it to scroll. |
John Spurlock | eda1f69 | 2013-09-16 11:38:44 -0400 | [diff] [blame] | 2824 | if (mStatusBar.isVisibleLw() && !statusBarTransient) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2825 | // Status bar may go away, so the screen area it occupies |
| 2826 | // is available to apps but just covering them when the |
| 2827 | // status bar is visible. |
| 2828 | mDockTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 2829 | |
| 2830 | mContentTop = mCurTop = mDockTop; |
| 2831 | mContentBottom = mCurBottom = mDockBottom; |
| 2832 | mContentLeft = mCurLeft = mDockLeft; |
| 2833 | mContentRight = mCurRight = mDockRight; |
| 2834 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2835 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " + |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2836 | String.format( |
| 2837 | "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]", |
| 2838 | mDockLeft, mDockTop, mDockRight, mDockBottom, |
| 2839 | mContentLeft, mContentTop, mContentRight, mContentBottom, |
| 2840 | mCurLeft, mCurTop, mCurRight, mCurBottom)); |
| 2841 | } |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 2842 | if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw() |
John Spurlock | b77edbf | 2013-08-21 21:04:12 -0400 | [diff] [blame] | 2843 | && !statusBarTransient && !statusBarTransparent |
| 2844 | && !mStatusBarController.wasRecentlyTransparent()) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 2845 | // If the opaque status bar is currently requested to be visible, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2846 | // and not in the process of animating on or off, then |
| 2847 | // we can tell the app that it is covered by it. |
| 2848 | mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 2849 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2850 | if (mStatusBarController.checkHiddenLw()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2851 | updateSysUiVisibility = true; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 2852 | } |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 2853 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2854 | if (updateSysUiVisibility) { |
| 2855 | updateSystemUiVisibilityLw(); |
| 2856 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2857 | } |
| 2858 | } |
| 2859 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 2860 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2861 | @Override |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 2862 | public int getSystemDecorRectLw(Rect systemRect) { |
| 2863 | systemRect.left = mSystemLeft; |
| 2864 | systemRect.top = mSystemTop; |
| 2865 | systemRect.right = mSystemRight; |
| 2866 | systemRect.bottom = mSystemBottom; |
| 2867 | if (mStatusBar != null) return mStatusBar.getSurfaceLayer(); |
| 2868 | if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer(); |
| 2869 | return 0; |
| 2870 | } |
| 2871 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2872 | @Override |
| 2873 | public void getContentRectLw(Rect r) { |
| 2874 | r.set(mContentLeft, mContentTop, mContentRight, mContentBottom); |
| 2875 | } |
| 2876 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2877 | void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached, |
| 2878 | boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2879 | if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) { |
| 2880 | // Here's a special case: if this attached window is a panel that is |
| 2881 | // above the dock window, and the window it is attached to is below |
| 2882 | // the dock window, then the frames we computed for the window it is |
| 2883 | // attached to can not be used because the dock is effectively part |
| 2884 | // of the underlying window and the attached window is floating on top |
| 2885 | // of the whole thing. So, we ignore the attached window and explicitly |
| 2886 | // compute the frames that would be appropriate without the dock. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2887 | df.left = of.left = cf.left = vf.left = mDockLeft; |
| 2888 | df.top = of.top = cf.top = vf.top = mDockTop; |
| 2889 | df.right = of.right = cf.right = vf.right = mDockRight; |
| 2890 | df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2891 | } else { |
| 2892 | // The effective display frame of the attached window depends on |
| 2893 | // whether it is taking care of insetting its content. If not, |
| 2894 | // we need to use the parent's content frame so that the entire |
| 2895 | // window is positioned within that content. Otherwise we can use |
| 2896 | // the display frame and let the attached window take care of |
| 2897 | // positioning its content appropriately. |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 2898 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2899 | cf.set(attached.getOverscanFrameLw()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2900 | } else { |
| 2901 | // If the window is resizing, then we want to base the content |
| 2902 | // frame on our attached content frame to resize... however, |
| 2903 | // things can be tricky if the attached window is NOT in resize |
| 2904 | // mode, in which case its content frame will be larger. |
| 2905 | // Ungh. So to deal with that, make sure the content frame |
| 2906 | // we end up using is not covering the IM dock. |
| 2907 | cf.set(attached.getContentFrameLw()); |
| 2908 | if (attached.getSurfaceLayer() < mDockLayer) { |
| 2909 | if (cf.left < mContentLeft) cf.left = mContentLeft; |
| 2910 | if (cf.top < mContentTop) cf.top = mContentTop; |
| 2911 | if (cf.right > mContentRight) cf.right = mContentRight; |
| 2912 | if (cf.bottom > mContentBottom) cf.bottom = mContentBottom; |
| 2913 | } |
| 2914 | } |
| 2915 | df.set(insetDecors ? attached.getDisplayFrameLw() : cf); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2916 | of.set(insetDecors ? attached.getOverscanFrameLw() : cf); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2917 | vf.set(attached.getVisibleFrameLw()); |
| 2918 | } |
| 2919 | // The LAYOUT_IN_SCREEN flag is used to determine whether the attached |
| 2920 | // window should be positioned relative to its parent or the entire |
| 2921 | // screen. |
| 2922 | pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0 |
| 2923 | ? attached.getFrameLw() : df); |
| 2924 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2925 | |
| 2926 | private void applyStableConstraints(int sysui, int fl, Rect r) { |
| 2927 | if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 2928 | // If app is requesting a stable layout, don't let the |
| 2929 | // content insets go below the stable values. |
| 2930 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 2931 | if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft; |
| 2932 | if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop; |
| 2933 | if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight; |
| 2934 | if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom; |
| 2935 | } else { |
| 2936 | if (r.left < mStableLeft) r.left = mStableLeft; |
| 2937 | if (r.top < mStableTop) r.top = mStableTop; |
| 2938 | if (r.right > mStableRight) r.right = mStableRight; |
| 2939 | if (r.bottom > mStableBottom) r.bottom = mStableBottom; |
| 2940 | } |
| 2941 | } |
| 2942 | } |
| 2943 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2944 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2945 | @Override |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 2946 | public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs, |
| 2947 | WindowState attached) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2948 | // we've already done the status bar |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2949 | if (win == mStatusBar || win == mNavigationBar) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2950 | return; |
| 2951 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2952 | final boolean isDefaultDisplay = win.isDefaultDisplay(); |
| 2953 | final boolean needsToOffsetInputMethodTarget = isDefaultDisplay && |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 2954 | (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null); |
| 2955 | if (needsToOffsetInputMethodTarget) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2956 | if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state"); |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 2957 | offsetInputMethodWindowLw(mLastInputMethodWindow); |
| 2958 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2959 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2960 | final int fl = attrs.flags; |
| 2961 | final int sim = attrs.softInputMode; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2962 | final int sysUiFl = win.getSystemUiVisibility(); |
| 2963 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2964 | final Rect pf = mTmpParentFrame; |
| 2965 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2966 | final Rect of = mTmpOverscanFrame; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2967 | final Rect cf = mTmpContentFrame; |
| 2968 | final Rect vf = mTmpVisibleFrame; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2969 | |
| 2970 | final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 2971 | && mNavigationBar != null && mNavigationBar.isVisibleLw()); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2972 | |
Craig Mautner | f683b56 | 2012-10-02 11:10:57 -0700 | [diff] [blame] | 2973 | final int adjust = sim & SOFT_INPUT_MASK_ADJUST; |
| 2974 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2975 | if (!isDefaultDisplay) { |
| 2976 | if (attached != null) { |
| 2977 | // If this window is attached to another, our display |
| 2978 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2979 | setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2980 | } else { |
| 2981 | // Give the window full screen. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2982 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 2983 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 2984 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2985 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2986 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2987 | = mOverscanScreenTop + mOverscanScreenHeight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2988 | } |
| 2989 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2990 | pf.left = df.left = of.left = cf.left = vf.left = mDockLeft; |
| 2991 | pf.top = df.top = of.top = cf.top = vf.top = mDockTop; |
| 2992 | pf.right = df.right = of.right = cf.right = vf.right = mDockRight; |
John Spurlock | d4e6575 | 2013-08-28 14:17:09 -0400 | [diff] [blame] | 2993 | // IM dock windows always go above the nav bar. |
| 2994 | pf.bottom = df.bottom = of.bottom = cf.bottom = vf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2995 | // IM dock windows always go to the bottom of the screen. |
| 2996 | attrs.gravity = Gravity.BOTTOM; |
| 2997 | mDockLayer = win.getSurfaceLayer(); |
| 2998 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2999 | if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) |
| 3000 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3001 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3002 | + "): IN_SCREEN, INSET_DECOR"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3003 | // This is the case for a normal activity window: we want it |
| 3004 | // to cover all of the screen space, and it can take care of |
| 3005 | // moving its contents to account for screen decorations that |
| 3006 | // intrude into that space. |
| 3007 | if (attached != null) { |
| 3008 | // If this window is attached to another, our display |
| 3009 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3010 | setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3011 | } else { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3012 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 3013 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3014 | // Status bar panels are the only windows who can go on top of |
| 3015 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 3016 | // permission, so they have the same privileges as the status |
| 3017 | // bar itself. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3018 | // |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3019 | // However, they should still dodge the navigation bar if it exists. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3020 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3021 | pf.left = df.left = of.left = hasNavBar |
| 3022 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 3023 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3024 | pf.right = df.right = of.right = hasNavBar |
| 3025 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
| 3026 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3027 | pf.bottom = df.bottom = of.bottom = hasNavBar |
| 3028 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
| 3029 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3030 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3031 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3032 | "Laying out status bar window: (%d,%d - %d,%d)", |
| 3033 | pf.left, pf.top, pf.right, pf.bottom)); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3034 | } else if ((attrs.flags&FLAG_LAYOUT_IN_OVERSCAN) != 0 |
| 3035 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3036 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3037 | // Asking to layout into the overscan region, so give it that pure |
| 3038 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3039 | pf.left = df.left = of.left = mOverscanScreenLeft; |
| 3040 | pf.top = df.top = of.top = mOverscanScreenTop; |
| 3041 | pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3042 | pf.bottom = df.bottom = of.bottom = mOverscanScreenTop |
| 3043 | + mOverscanScreenHeight; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3044 | } else if (mCanHideNavigationBar |
| 3045 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3046 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3047 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3048 | // Asking for layout as if the nav bar is hidden, lets the |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3049 | // application extend into the unrestricted overscan screen area. We |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3050 | // only do this for application windows to ensure no window that |
| 3051 | // can be above the nav bar can do this. |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3052 | pf.left = df.left = mOverscanScreenLeft; |
| 3053 | pf.top = df.top = mOverscanScreenTop; |
| 3054 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3055 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3056 | // We need to tell the app about where the frame inside the overscan |
| 3057 | // is, so it can inset its content by that amount -- it didn't ask |
| 3058 | // to actually extend itself into the overscan region. |
| 3059 | of.left = mUnrestrictedScreenLeft; |
| 3060 | of.top = mUnrestrictedScreenTop; |
| 3061 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3062 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3063 | } else { |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3064 | pf.left = df.left = mRestrictedOverscanScreenLeft; |
| 3065 | pf.top = df.top = mRestrictedOverscanScreenTop; |
| 3066 | pf.right = df.right = mRestrictedOverscanScreenLeft |
| 3067 | + mRestrictedOverscanScreenWidth; |
| 3068 | pf.bottom = df.bottom = mRestrictedOverscanScreenTop |
| 3069 | + mRestrictedOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3070 | // We need to tell the app about where the frame inside the overscan |
| 3071 | // is, so it can inset its content by that amount -- it didn't ask |
| 3072 | // to actually extend itself into the overscan region. |
| 3073 | of.left = mUnrestrictedScreenLeft; |
| 3074 | of.top = mUnrestrictedScreenTop; |
| 3075 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3076 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3077 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3078 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3079 | if ((attrs.flags&FLAG_FULLSCREEN) == 0) { |
| 3080 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 3081 | cf.left = mDockLeft; |
| 3082 | cf.top = mDockTop; |
| 3083 | cf.right = mDockRight; |
| 3084 | cf.bottom = mDockBottom; |
| 3085 | } else { |
| 3086 | cf.left = mContentLeft; |
| 3087 | cf.top = mContentTop; |
| 3088 | cf.right = mContentRight; |
| 3089 | cf.bottom = mContentBottom; |
| 3090 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3091 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3092 | // Full screen windows are always given a layout that is as if the |
| 3093 | // status bar and other transient decors are gone. This is to avoid |
| 3094 | // bad states when moving from a window that is not hding the |
| 3095 | // status bar to one that is. |
| 3096 | cf.left = mRestrictedScreenLeft; |
| 3097 | cf.top = mRestrictedScreenTop; |
| 3098 | cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 3099 | cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3100 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3101 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3102 | applyStableConstraints(sysUiFl, fl, cf); |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3103 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3104 | vf.left = mCurLeft; |
| 3105 | vf.top = mCurTop; |
| 3106 | vf.right = mCurRight; |
| 3107 | vf.bottom = mCurBottom; |
| 3108 | } else { |
| 3109 | vf.set(cf); |
| 3110 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3111 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3112 | } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl |
| 3113 | & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 3114 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3115 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3116 | "): IN_SCREEN"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3117 | // A window that has requested to fill the entire screen just |
| 3118 | // gets everything, period. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3119 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 3120 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3121 | pf.left = df.left = of.left = cf.left = hasNavBar |
| 3122 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 3123 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 3124 | pf.right = df.right = of.right = cf.right = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3125 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3126 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3127 | pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3128 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3129 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3130 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 3131 | "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)", |
| 3132 | pf.left, pf.top, pf.right, pf.bottom)); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 3133 | } else if (attrs.type == TYPE_NAVIGATION_BAR |
| 3134 | || attrs.type == TYPE_NAVIGATION_BAR_PANEL) { |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3135 | // The navigation bar has Real Ultimate Power. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3136 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3137 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3138 | pf.right = df.right = of.right = mUnrestrictedScreenLeft |
| 3139 | + mUnrestrictedScreenWidth; |
| 3140 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop |
| 3141 | + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3142 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3143 | "Laying out navigation bar window: (%d,%d - %d,%d)", |
| 3144 | pf.left, pf.top, pf.right, pf.bottom)); |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 3145 | } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY |
| 3146 | || attrs.type == TYPE_BOOT_PROGRESS) |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 3147 | && ((fl & FLAG_FULLSCREEN) != 0)) { |
| 3148 | // Fullscreen secure system overlays get what they ask for. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3149 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3150 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3151 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 3152 | + mOverscanScreenWidth; |
| 3153 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 3154 | + mOverscanScreenHeight; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 3155 | } else if (attrs.type == TYPE_BOOT_PROGRESS |
| 3156 | || attrs.type == TYPE_UNIVERSE_BACKGROUND) { |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 3157 | // Boot progress screen always covers entire display. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3158 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3159 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3160 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 3161 | + mOverscanScreenWidth; |
| 3162 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 3163 | + mOverscanScreenHeight; |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 3164 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 3165 | // The wallpaper also has Real Ultimate Power. |
| 3166 | pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft; |
| 3167 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3168 | pf.right = df.right = of.right = cf.right |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 3169 | = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3170 | pf.bottom = df.bottom = of.bottom = cf.bottom |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 3171 | = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3172 | } else if ((attrs.flags & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
| 3173 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3174 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3175 | // Asking to layout into the overscan region, so give it that pure |
| 3176 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3177 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3178 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3179 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3180 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3181 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3182 | = mOverscanScreenTop + mOverscanScreenHeight; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3183 | } else if (mCanHideNavigationBar |
| 3184 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 3185 | && (attrs.type == TYPE_TOAST |
| 3186 | || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3187 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3188 | // Asking for layout as if the nav bar is hidden, lets the |
| 3189 | // application extend into the unrestricted screen area. We |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 3190 | // only do this for application windows (or toasts) to ensure no window that |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3191 | // can be above the nav bar can do this. |
| 3192 | // XXX This assumes that an app asking for this will also |
| 3193 | // ask for layout in only content. We can't currently figure out |
| 3194 | // what the screen would be if only laying out to hide the nav bar. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3195 | pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft; |
| 3196 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 3197 | pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft |
| 3198 | + mUnrestrictedScreenWidth; |
| 3199 | pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop |
| 3200 | + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3201 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3202 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 3203 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 3204 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 3205 | + mRestrictedScreenWidth; |
| 3206 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 3207 | + mRestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3208 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3209 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3210 | applyStableConstraints(sysUiFl, fl, cf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3211 | |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3212 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3213 | vf.left = mCurLeft; |
| 3214 | vf.top = mCurTop; |
| 3215 | vf.right = mCurRight; |
| 3216 | vf.bottom = mCurBottom; |
| 3217 | } else { |
| 3218 | vf.set(cf); |
| 3219 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3220 | } else if (attached != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3221 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3222 | "): attached to " + attached); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3223 | // A child window should be placed inside of the same visible |
| 3224 | // frame that its parent had. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3225 | setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3226 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3227 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3228 | "): normal window"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3229 | // Otherwise, a normal window must be placed inside the content |
| 3230 | // of all screen decorations. |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3231 | if (attrs.type == TYPE_STATUS_BAR_PANEL) { |
| 3232 | // Status bar panels are the only windows who can go on top of |
| 3233 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 3234 | // permission, so they have the same privileges as the status |
| 3235 | // bar itself. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3236 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 3237 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 3238 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 3239 | + mRestrictedScreenWidth; |
| 3240 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 3241 | + mRestrictedScreenHeight; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3242 | } else { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3243 | pf.left = mContentLeft; |
| 3244 | pf.top = mContentTop; |
| 3245 | pf.right = mContentRight; |
| 3246 | pf.bottom = mContentBottom; |
| 3247 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3248 | df.left = of.left = cf.left = mDockLeft; |
| 3249 | df.top = of.top = cf.top = mDockTop; |
| 3250 | df.right = of.right = cf.right = mDockRight; |
| 3251 | df.bottom = of.bottom = cf.bottom = mDockBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3252 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3253 | df.left = of.left = cf.left = mContentLeft; |
| 3254 | df.top = of.top = cf.top = mContentTop; |
| 3255 | df.right = of.right = cf.right = mContentRight; |
| 3256 | df.bottom = of.bottom = cf.bottom = mContentBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3257 | } |
| 3258 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3259 | vf.left = mCurLeft; |
| 3260 | vf.top = mCurTop; |
| 3261 | vf.right = mCurRight; |
| 3262 | vf.bottom = mCurBottom; |
| 3263 | } else { |
| 3264 | vf.set(cf); |
| 3265 | } |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3266 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3267 | } |
| 3268 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3269 | |
Craig Mautner | b816bed | 2013-07-23 10:26:17 -0700 | [diff] [blame] | 3270 | // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it. |
| 3271 | if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3272 | df.left = df.top = of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000; |
| 3273 | df.right = df.bottom = of.right = of.bottom = cf.right = cf.bottom |
| 3274 | = vf.right = vf.bottom = 10000; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3275 | } |
| 3276 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3277 | if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle() |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 3278 | + ": sim=#" + Integer.toHexString(sim) |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3279 | + " attach=" + attached + " type=" + attrs.type |
| 3280 | + String.format(" flags=0x%08x", fl) |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 3281 | + " pf=" + pf.toShortString() + " df=" + df.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3282 | + " of=" + of.toShortString() |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 3283 | + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3284 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3285 | win.computeFrameLw(pf, df, of, cf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3286 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3287 | // Dock windows carve out the bottom of the screen, so normal windows |
| 3288 | // can't appear underneath them. |
Craig Mautner | 8bd206b | 2012-10-03 10:32:02 -0700 | [diff] [blame] | 3289 | if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw() |
| 3290 | && !win.getGivenInsetsPendingLw()) { |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3291 | setLastInputMethodWindowLw(null, null); |
| 3292 | offsetInputMethodWindowLw(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3293 | } |
| 3294 | } |
| 3295 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3296 | private void offsetInputMethodWindowLw(WindowState win) { |
| 3297 | int top = win.getContentFrameLw().top; |
| 3298 | top += win.getGivenContentInsetsLw().top; |
| 3299 | if (mContentBottom > top) { |
| 3300 | mContentBottom = top; |
| 3301 | } |
| 3302 | top = win.getVisibleFrameLw().top; |
| 3303 | top += win.getGivenVisibleInsetsLw().top; |
| 3304 | if (mCurBottom > top) { |
| 3305 | mCurBottom = top; |
| 3306 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3307 | if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom=" |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3308 | + mDockBottom + " mContentBottom=" |
| 3309 | + mContentBottom + " mCurBottom=" + mCurBottom); |
| 3310 | } |
| 3311 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3312 | /** {@inheritDoc} */ |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 3313 | @Override |
| 3314 | public void finishLayoutLw() { |
| 3315 | return; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3316 | } |
| 3317 | |
| 3318 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3319 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3320 | public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3321 | mTopFullscreenOpaqueWindowState = null; |
| 3322 | mForceStatusBar = false; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3323 | mForceStatusBarFromKeyguard = false; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 3324 | mForcingShowNavBar = false; |
| 3325 | mForcingShowNavBarLayer = -1; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3326 | |
| 3327 | mHideLockScreen = false; |
| 3328 | mAllowLockscreenWhenOn = false; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3329 | mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3330 | mShowingLockscreen = false; |
| 3331 | mShowingDream = false; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3332 | } |
| 3333 | |
| 3334 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3335 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3336 | public void applyPostLayoutPolicyLw(WindowState win, |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3337 | WindowManager.LayoutParams attrs) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 3338 | if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw=" |
| 3339 | + win.isVisibleOrBehindKeyguardLw()); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 3340 | if (mTopFullscreenOpaqueWindowState == null && (win.getAttrs().privateFlags |
John Spurlock | 9e7884a | 2013-09-05 09:37:56 -0400 | [diff] [blame] | 3341 | &WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_SHOW_NAV_BAR) != 0 |
| 3342 | || (win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD)) { |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 3343 | if (mForcingShowNavBarLayer < 0) { |
| 3344 | mForcingShowNavBar = true; |
| 3345 | mForcingShowNavBarLayer = win.getSurfaceLayer(); |
| 3346 | } |
| 3347 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3348 | if (mTopFullscreenOpaqueWindowState == null && |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 3349 | win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3350 | if ((attrs.flags & FLAG_FORCE_NOT_FULLSCREEN) != 0) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3351 | if (attrs.type == TYPE_KEYGUARD) { |
| 3352 | mForceStatusBarFromKeyguard = true; |
| 3353 | } else { |
| 3354 | mForceStatusBar = true; |
| 3355 | } |
| 3356 | } |
| 3357 | if (attrs.type == TYPE_KEYGUARD) { |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3358 | mShowingLockscreen = true; |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 3359 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3360 | boolean applyWindow = attrs.type >= FIRST_APPLICATION_WINDOW |
| 3361 | && attrs.type <= LAST_APPLICATION_WINDOW; |
| 3362 | if (attrs.type == TYPE_DREAM) { |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 3363 | // If the lockscreen was showing when the dream started then wait |
| 3364 | // for the dream to draw before hiding the lockscreen. |
| 3365 | if (!mDreamingLockscreen |
| 3366 | || (win.isVisibleLw() && win.hasDrawnLw())) { |
| 3367 | mShowingDream = true; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3368 | applyWindow = true; |
| 3369 | } |
| 3370 | } |
| 3371 | if (applyWindow |
Dianne Hackborn | 6493e64 | 2010-10-01 13:06:30 -0700 | [diff] [blame] | 3372 | && attrs.x == 0 && attrs.y == 0 |
| 3373 | && attrs.width == WindowManager.LayoutParams.MATCH_PARENT |
| 3374 | && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3375 | if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3376 | mTopFullscreenOpaqueWindowState = win; |
| 3377 | if ((attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3378 | if (DEBUG_LAYOUT) Slog.v(TAG, "Setting mHideLockScreen to true by win " + win); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3379 | mHideLockScreen = true; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3380 | mForceStatusBarFromKeyguard = false; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3381 | } |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3382 | if ((attrs.flags & FLAG_DISMISS_KEYGUARD) != 0 |
| 3383 | && mDismissKeyguard == DISMISS_KEYGUARD_NONE) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3384 | if (DEBUG_LAYOUT) Slog.v(TAG, "Setting mDismissKeyguard true by win " + win); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3385 | mDismissKeyguard = mWinDismissingKeyguard == win ? |
| 3386 | DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START; |
| 3387 | mWinDismissingKeyguard = win; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3388 | mForceStatusBarFromKeyguard = mShowingLockscreen && isKeyguardSecure(); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3389 | } |
| 3390 | if ((attrs.flags & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) { |
| 3391 | mAllowLockscreenWhenOn = true; |
| 3392 | } |
| 3393 | } |
| 3394 | } |
| 3395 | } |
| 3396 | |
| 3397 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3398 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3399 | public int finishPostLayoutPolicyLw() { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3400 | int changes = 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3401 | boolean topIsFullscreen = false; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 3402 | |
| 3403 | final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null) |
| 3404 | ? mTopFullscreenOpaqueWindowState.getAttrs() |
| 3405 | : null; |
| 3406 | |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 3407 | // If we are not currently showing a dream then remember the current |
| 3408 | // lockscreen state. We will use this to determine whether the dream |
| 3409 | // started while the lockscreen was showing and remember this state |
| 3410 | // while the dream is showing. |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3411 | if (!mShowingDream) { |
| 3412 | mDreamingLockscreen = mShowingLockscreen; |
| 3413 | } |
| 3414 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3415 | if (mStatusBar != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3416 | if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3417 | + " forcefkg=" + mForceStatusBarFromKeyguard |
Dianne Hackborn | d70bc2f | 2009-10-06 23:25:51 -0700 | [diff] [blame] | 3418 | + " top=" + mTopFullscreenOpaqueWindowState); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3419 | if (mForceStatusBar || mForceStatusBarFromKeyguard) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3420 | if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3421 | if (mStatusBarController.setBarShowingLw(true)) { |
| 3422 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 3423 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3424 | } else if (mTopFullscreenOpaqueWindowState != null) { |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3425 | if (localLOGV) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3426 | Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw() |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3427 | + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw()); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3428 | Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs() |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3429 | + " lp.flags=0x" + Integer.toHexString(lp.flags)); |
| 3430 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3431 | topIsFullscreen = (lp.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0 |
| 3432 | || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3433 | // The subtle difference between the window for mTopFullscreenOpaqueWindowState |
| 3434 | // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window |
| 3435 | // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the |
| 3436 | // case though. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3437 | if (mStatusBarController.isTransientShowing()) { |
| 3438 | if (mStatusBarController.setBarShowingLw(true)) { |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 3439 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 3440 | } |
| 3441 | } else if (topIsFullscreen) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3442 | if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3443 | if (mStatusBarController.setBarShowingLw(false)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3444 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3445 | } else { |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 3446 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding"); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 3447 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3448 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3449 | if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3450 | if (mStatusBarController.setBarShowingLw(true)) { |
| 3451 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 3452 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3453 | } |
| 3454 | } |
| 3455 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 3456 | |
Joe Onorato | 644f9c3 | 2011-01-25 12:06:23 -0800 | [diff] [blame] | 3457 | mTopIsFullscreen = topIsFullscreen; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 3458 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3459 | // Hide the key guard if a visible window explicitly specifies that it wants to be |
| 3460 | // displayed when the screen is locked. |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 3461 | if (mKeyguard != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3462 | if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard=" |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3463 | + mHideLockScreen); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3464 | if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardDelegate.isSecure()) { |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3465 | if (mKeyguard.hideLw(true)) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3466 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3467 | | FINISH_LAYOUT_REDO_CONFIG |
| 3468 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3469 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3470 | if (mKeyguardDelegate.isShowing()) { |
Dianne Hackborn | b446e97 | 2009-09-20 15:23:25 -0700 | [diff] [blame] | 3471 | mHandler.post(new Runnable() { |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3472 | @Override |
Dianne Hackborn | b446e97 | 2009-09-20 15:23:25 -0700 | [diff] [blame] | 3473 | public void run() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3474 | mKeyguardDelegate.keyguardDone(false, false); |
Dianne Hackborn | b446e97 | 2009-09-20 15:23:25 -0700 | [diff] [blame] | 3475 | } |
| 3476 | }); |
| 3477 | } |
Dianne Hackborn | 0572658 | 2009-09-22 17:28:24 -0700 | [diff] [blame] | 3478 | } else if (mHideLockScreen) { |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3479 | if (mKeyguard.hideLw(true)) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3480 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3481 | | FINISH_LAYOUT_REDO_CONFIG |
| 3482 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3483 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3484 | mKeyguardDelegate.setHidden(true); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3485 | } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) { |
| 3486 | // This is the case of keyguard isSecure() and not mHideLockScreen. |
| 3487 | if (mDismissKeyguard == DISMISS_KEYGUARD_START) { |
| 3488 | // Only launch the next keyguard unlock window once per window. |
| 3489 | if (mKeyguard.showLw(true)) { |
| 3490 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3491 | | FINISH_LAYOUT_REDO_CONFIG |
| 3492 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3493 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3494 | mKeyguardDelegate.setHidden(false); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3495 | mHandler.post(new Runnable() { |
| 3496 | @Override |
| 3497 | public void run() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3498 | mKeyguardDelegate.dismiss(); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3499 | } |
| 3500 | }); |
| 3501 | } |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 3502 | } else { |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3503 | mWinDismissingKeyguard = null; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3504 | if (mKeyguard.showLw(true)) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3505 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3506 | | FINISH_LAYOUT_REDO_CONFIG |
| 3507 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3508 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3509 | mKeyguardDelegate.setHidden(false); |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 3510 | } |
| 3511 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 3512 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3513 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3514 | // If the navigation bar has been hidden or shown, we need to do another |
| 3515 | // layout pass to update that window. |
| 3516 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 3517 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 3518 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 3519 | // update since mAllowLockscreenWhenOn might have changed |
| 3520 | updateLockScreenTimeout(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3521 | return changes; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3522 | } |
| 3523 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3524 | public boolean allowAppAnimationsLw() { |
Craig Mautner | f03e4c5 | 2012-06-14 14:11:27 -0700 | [diff] [blame] | 3525 | if (mKeyguard != null && mKeyguard.isVisibleLw() && !mKeyguard.isAnimatingLw()) { |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3526 | // If keyguard is currently visible, no reason to animate |
| 3527 | // behind it. |
| 3528 | return false; |
| 3529 | } |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3530 | return true; |
| 3531 | } |
| 3532 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3533 | public int focusChangedLw(WindowState lastFocus, WindowState newFocus) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 3534 | mFocusedWindow = newFocus; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3535 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3536 | // If the navigation bar has been hidden or shown, we need to do another |
| 3537 | // layout pass to update that window. |
| 3538 | return FINISH_LAYOUT_REDO_LAYOUT; |
| 3539 | } |
| 3540 | return 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 3541 | } |
| 3542 | |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 3543 | /** {@inheritDoc} */ |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3544 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 3545 | // do nothing if headless |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 3546 | if (mHeadless) return; |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 3547 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3548 | // lid changed state |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 3549 | final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED; |
| 3550 | if (newLidState == mLidState) { |
| 3551 | return; |
| 3552 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 3553 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 3554 | mLidState = newLidState; |
| 3555 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 3556 | updateRotation(true); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 3557 | |
| 3558 | if (lidOpen) { |
Jim Miller | e51cf7ae | 2013-06-25 18:31:56 -0700 | [diff] [blame] | 3559 | mPowerManager.wakeUp(SystemClock.uptimeMillis()); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 3560 | } else if (!mLidControlsSleep) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3561 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3562 | } |
| 3563 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3564 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 3565 | void setHdmiPlugged(boolean plugged) { |
| 3566 | if (mHdmiPlugged != plugged) { |
| 3567 | mHdmiPlugged = plugged; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3568 | updateRotation(true, true); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 3569 | Intent intent = new Intent(ACTION_HDMI_PLUGGED); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 3570 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 3571 | intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 3572 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 3573 | } |
| 3574 | } |
| 3575 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 3576 | void initializeHdmiState() { |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 3577 | boolean plugged = false; |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 3578 | // watch for HDMI plug messages if the hdmi switch exists |
| 3579 | if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) { |
| 3580 | mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi"); |
| 3581 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 3582 | final String filename = "/sys/class/switch/hdmi/state"; |
| 3583 | FileReader reader = null; |
| 3584 | try { |
| 3585 | reader = new FileReader(filename); |
| 3586 | char[] buf = new char[15]; |
| 3587 | int n = reader.read(buf); |
| 3588 | if (n > 1) { |
| 3589 | plugged = 0 != Integer.parseInt(new String(buf, 0, n-1)); |
| 3590 | } |
| 3591 | } catch (IOException ex) { |
| 3592 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 3593 | } catch (NumberFormatException ex) { |
| 3594 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 3595 | } finally { |
| 3596 | if (reader != null) { |
| 3597 | try { |
| 3598 | reader.close(); |
| 3599 | } catch (IOException ex) { |
| 3600 | } |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 3601 | } |
| 3602 | } |
| 3603 | } |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 3604 | // This dance forces the code in setHdmiPlugged to run. |
| 3605 | // Always do this so the sticky intent is stuck (to false) if there is no hdmi. |
| 3606 | mHdmiPlugged = !plugged; |
| 3607 | setHdmiPlugged(!mHdmiPlugged); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 3608 | } |
| 3609 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3610 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3611 | * @return Whether music is being played right now. |
| 3612 | */ |
| 3613 | boolean isMusicActive() { |
Eric Laurent | 413cb9d | 2009-07-17 11:52:43 -0700 | [diff] [blame] | 3614 | final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE); |
| 3615 | if (am == null) { |
| 3616 | Log.w(TAG, "isMusicActive: couldn't get AudioManager reference"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3617 | return false; |
| 3618 | } |
Eric Laurent | 413cb9d | 2009-07-17 11:52:43 -0700 | [diff] [blame] | 3619 | return am.isMusicActive(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3620 | } |
| 3621 | |
| 3622 | /** |
| 3623 | * Tell the audio service to adjust the volume appropriate to the event. |
| 3624 | * @param keycode |
| 3625 | */ |
Mike Lockwood | a53e381 | 2009-09-25 10:51:39 -0400 | [diff] [blame] | 3626 | void handleVolumeKey(int stream, int keycode) { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3627 | IAudioService audioService = getAudioService(); |
| 3628 | if (audioService == null) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3629 | return; |
| 3630 | } |
| 3631 | try { |
| 3632 | // since audio is playing, we shouldn't have to hold a wake lock |
| 3633 | // during the call, but we do it as a precaution for the rare possibility |
| 3634 | // that the music stops right before we call this |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 3635 | // TODO: Actually handle MUTE. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3636 | mBroadcastWakeLock.acquire(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3637 | audioService.adjustStreamVolume(stream, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3638 | keycode == KeyEvent.KEYCODE_VOLUME_UP |
| 3639 | ? AudioManager.ADJUST_RAISE |
| 3640 | : AudioManager.ADJUST_LOWER, |
Dianne Hackborn | ba50b97c | 2013-04-30 15:04:46 -0700 | [diff] [blame] | 3641 | 0, |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 3642 | mContext.getOpPackageName()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3643 | } catch (RemoteException e) { |
| 3644 | Log.w(TAG, "IAudioService.adjustStreamVolume() threw RemoteException " + e); |
| 3645 | } finally { |
| 3646 | mBroadcastWakeLock.release(); |
| 3647 | } |
| 3648 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3649 | |
Dianne Hackborn | c0e3f24 | 2011-08-19 14:19:10 -0700 | [diff] [blame] | 3650 | final Object mScreenshotLock = new Object(); |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 3651 | ServiceConnection mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 3652 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3653 | final Runnable mScreenshotTimeout = new Runnable() { |
| 3654 | @Override public void run() { |
| 3655 | synchronized (mScreenshotLock) { |
| 3656 | if (mScreenshotConnection != null) { |
| 3657 | mContext.unbindService(mScreenshotConnection); |
| 3658 | mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 3659 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 3660 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3661 | } |
| 3662 | }; |
| 3663 | |
| 3664 | // Assume this is called from the Handler thread. |
| 3665 | private void takeScreenshot() { |
| 3666 | synchronized (mScreenshotLock) { |
| 3667 | if (mScreenshotConnection != null) { |
| 3668 | return; |
| 3669 | } |
| 3670 | ComponentName cn = new ComponentName("com.android.systemui", |
| 3671 | "com.android.systemui.screenshot.TakeScreenshotService"); |
| 3672 | Intent intent = new Intent(); |
| 3673 | intent.setComponent(cn); |
| 3674 | ServiceConnection conn = new ServiceConnection() { |
| 3675 | @Override |
| 3676 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 3677 | synchronized (mScreenshotLock) { |
| 3678 | if (mScreenshotConnection != this) { |
| 3679 | return; |
| 3680 | } |
| 3681 | Messenger messenger = new Messenger(service); |
| 3682 | Message msg = Message.obtain(null, 1); |
| 3683 | final ServiceConnection myConn = this; |
| 3684 | Handler h = new Handler(mHandler.getLooper()) { |
| 3685 | @Override |
| 3686 | public void handleMessage(Message msg) { |
| 3687 | synchronized (mScreenshotLock) { |
| 3688 | if (mScreenshotConnection == myConn) { |
| 3689 | mContext.unbindService(mScreenshotConnection); |
| 3690 | mScreenshotConnection = null; |
| 3691 | mHandler.removeCallbacks(mScreenshotTimeout); |
| 3692 | } |
| 3693 | } |
| 3694 | } |
| 3695 | }; |
| 3696 | msg.replyTo = new Messenger(h); |
Winson Chung | a63bb84 | 2011-10-17 10:26:28 -0700 | [diff] [blame] | 3697 | msg.arg1 = msg.arg2 = 0; |
| 3698 | if (mStatusBar != null && mStatusBar.isVisibleLw()) |
| 3699 | msg.arg1 = 1; |
| 3700 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) |
| 3701 | msg.arg2 = 1; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3702 | try { |
| 3703 | messenger.send(msg); |
| 3704 | } catch (RemoteException e) { |
| 3705 | } |
| 3706 | } |
| 3707 | } |
| 3708 | @Override |
| 3709 | public void onServiceDisconnected(ComponentName name) {} |
| 3710 | }; |
Amith Yamasani | 27b89e6 | 2013-01-16 12:30:11 -0800 | [diff] [blame] | 3711 | if (mContext.bindServiceAsUser( |
| 3712 | intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3713 | mScreenshotConnection = conn; |
| 3714 | mHandler.postDelayed(mScreenshotTimeout, 10000); |
| 3715 | } |
| 3716 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 3717 | } |
| 3718 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3719 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3720 | @Override |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 3721 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3722 | if (!mSystemBooted) { |
| 3723 | // If we have not yet booted, don't let key events do anything. |
| 3724 | return 0; |
| 3725 | } |
| 3726 | |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 3727 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 3728 | final boolean canceled = event.isCanceled(); |
| 3729 | final int keyCode = event.getKeyCode(); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 3730 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 3731 | final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 3732 | |
Mike Lockwood | c72b15f | 2009-11-28 20:58:22 -0500 | [diff] [blame] | 3733 | // If screen is off then we treat the case where the keyguard is open but hidden |
| 3734 | // the same as if it were open and in front. |
| 3735 | // This will prevent any keys other than the power button from waking the screen |
| 3736 | // when the keyguard is hidden by another activity. |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3737 | final boolean keyguardActive = (mKeyguardDelegate == null ? false : |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 3738 | (isScreenOn ? |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3739 | mKeyguardDelegate.isShowingAndNotHidden() : |
| 3740 | mKeyguardDelegate.isShowing())); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3741 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3742 | if (keyCode == KeyEvent.KEYCODE_POWER) { |
| 3743 | policyFlags |= WindowManagerPolicy.FLAG_WAKE; |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 3744 | } |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3745 | final boolean isWakeKey = (policyFlags & (WindowManagerPolicy.FLAG_WAKE |
| 3746 | | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0; |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 3747 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3748 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3749 | Log.d(TAG, "interceptKeyTq keycode=" + keyCode |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3750 | + " screenIsOn=" + isScreenOn + " keyguardActive=" + keyguardActive |
| 3751 | + " policyFlags=" + Integer.toHexString(policyFlags) |
| 3752 | + " isWakeKey=" + isWakeKey); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3753 | } |
| 3754 | |
Jeff Brown | 98392ef | 2011-09-12 18:24:59 -0700 | [diff] [blame] | 3755 | if (down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0 |
| 3756 | && event.getRepeatCount() == 0) { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3757 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 3758 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3759 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3760 | // Basic policy based on screen state and keyguard. |
| 3761 | // FIXME: This policy isn't quite correct. We shouldn't care whether the screen |
| 3762 | // is on or off, really. We should care about whether the device is in an |
| 3763 | // interactive state or is in suspend pretending to be "off". |
| 3764 | // The primary screen might be turned off due to proximity sensor or |
| 3765 | // because we are presenting media on an auxiliary screen or remotely controlling |
| 3766 | // the device some other way (which is why we have an exemption here for injected |
| 3767 | // events). |
| 3768 | int result; |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 3769 | if ((isScreenOn && !mHeadless) || (isInjected && !isWakeKey)) { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3770 | // When the screen is on or if the key is injected pass the key to the application. |
| 3771 | result = ACTION_PASS_TO_USER; |
| 3772 | } else { |
| 3773 | // When the screen is off and the key is not injected, determine whether |
| 3774 | // to wake the device but don't pass the key to the application. |
| 3775 | result = 0; |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 3776 | if (down && isWakeKey && isWakeKeyWhenScreenOff(keyCode)) { |
Jim Miller | e51cf7ae | 2013-06-25 18:31:56 -0700 | [diff] [blame] | 3777 | result |= ACTION_WAKE_UP; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3778 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3779 | } |
| 3780 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 3781 | // If the key would be handled globally, just return the result, don't worry about special |
| 3782 | // key processing. |
| 3783 | if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) { |
| 3784 | return result; |
| 3785 | } |
| 3786 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3787 | // Handle special keys. |
| 3788 | switch (keyCode) { |
| 3789 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 3790 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 3791 | case KeyEvent.KEYCODE_VOLUME_MUTE: { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3792 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { |
| 3793 | if (down) { |
| 3794 | if (isScreenOn && !mVolumeDownKeyTriggered |
| 3795 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 3796 | mVolumeDownKeyTriggered = true; |
| 3797 | mVolumeDownKeyTime = event.getDownTime(); |
| 3798 | mVolumeDownKeyConsumedByScreenshotChord = false; |
| 3799 | cancelPendingPowerKeyAction(); |
| 3800 | interceptScreenshotChord(); |
| 3801 | } |
| 3802 | } else { |
| 3803 | mVolumeDownKeyTriggered = false; |
| 3804 | cancelPendingScreenshotChordAction(); |
| 3805 | } |
| 3806 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { |
| 3807 | if (down) { |
| 3808 | if (isScreenOn && !mVolumeUpKeyTriggered |
| 3809 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 3810 | mVolumeUpKeyTriggered = true; |
| 3811 | cancelPendingPowerKeyAction(); |
| 3812 | cancelPendingScreenshotChordAction(); |
| 3813 | } |
| 3814 | } else { |
| 3815 | mVolumeUpKeyTriggered = false; |
| 3816 | cancelPendingScreenshotChordAction(); |
| 3817 | } |
| 3818 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3819 | if (down) { |
| 3820 | ITelephony telephonyService = getTelephonyService(); |
| 3821 | if (telephonyService != null) { |
| 3822 | try { |
| 3823 | if (telephonyService.isRinging()) { |
| 3824 | // If an incoming call is ringing, either VOLUME key means |
| 3825 | // "silence ringer". We handle these keys here, rather than |
| 3826 | // in the InCallScreen, to make sure we'll respond to them |
| 3827 | // even if the InCallScreen hasn't come to the foreground yet. |
| 3828 | // Look for the DOWN event here, to agree with the "fallback" |
| 3829 | // behavior in the InCallScreen. |
| 3830 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 3831 | + " VOLUME key-down while ringing: Silence ringer!"); |
| 3832 | |
| 3833 | // Silence the ringer. (It's safe to call this |
| 3834 | // even if the ringer has already been silenced.) |
| 3835 | telephonyService.silenceRinger(); |
| 3836 | |
| 3837 | // And *don't* pass this key thru to the current activity |
| 3838 | // (which is probably the InCallScreen.) |
| 3839 | result &= ~ACTION_PASS_TO_USER; |
| 3840 | break; |
| 3841 | } |
| 3842 | if (telephonyService.isOffhook() |
| 3843 | && (result & ACTION_PASS_TO_USER) == 0) { |
| 3844 | // If we are in call but we decided not to pass the key to |
| 3845 | // the application, handle the volume change here. |
| 3846 | handleVolumeKey(AudioManager.STREAM_VOICE_CALL, keyCode); |
| 3847 | break; |
| 3848 | } |
| 3849 | } catch (RemoteException ex) { |
| 3850 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
| 3851 | } |
| 3852 | } |
| 3853 | |
| 3854 | if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) { |
| 3855 | // If music is playing but we decided not to pass the key to the |
| 3856 | // application, handle the volume change here. |
| 3857 | handleVolumeKey(AudioManager.STREAM_MUSIC, keyCode); |
| 3858 | break; |
| 3859 | } |
| 3860 | } |
| 3861 | break; |
| 3862 | } |
| 3863 | |
| 3864 | case KeyEvent.KEYCODE_ENDCALL: { |
| 3865 | result &= ~ACTION_PASS_TO_USER; |
| 3866 | if (down) { |
| 3867 | ITelephony telephonyService = getTelephonyService(); |
| 3868 | boolean hungUp = false; |
| 3869 | if (telephonyService != null) { |
| 3870 | try { |
| 3871 | hungUp = telephonyService.endCall(); |
| 3872 | } catch (RemoteException ex) { |
| 3873 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
| 3874 | } |
| 3875 | } |
| 3876 | interceptPowerKeyDown(!isScreenOn || hungUp); |
| 3877 | } else { |
| 3878 | if (interceptPowerKeyUp(canceled)) { |
| 3879 | if ((mEndcallBehavior |
| 3880 | & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) { |
| 3881 | if (goHome()) { |
| 3882 | break; |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 3883 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3884 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3885 | if ((mEndcallBehavior |
| 3886 | & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3887 | result = (result & ~ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3888 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3889 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3890 | } |
| 3891 | break; |
| 3892 | } |
| 3893 | |
| 3894 | case KeyEvent.KEYCODE_POWER: { |
| 3895 | result &= ~ACTION_PASS_TO_USER; |
| 3896 | if (down) { |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 3897 | mTransientNavigationConfirmation.onPowerKeyDown(isScreenOn, event.getDownTime(), |
| 3898 | isTransientNavigationAllowed(mLastSystemUiFlags)); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3899 | if (isScreenOn && !mPowerKeyTriggered |
| 3900 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 3901 | mPowerKeyTriggered = true; |
| 3902 | mPowerKeyTime = event.getDownTime(); |
| 3903 | interceptScreenshotChord(); |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 3904 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 3905 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3906 | ITelephony telephonyService = getTelephonyService(); |
| 3907 | boolean hungUp = false; |
| 3908 | if (telephonyService != null) { |
| 3909 | try { |
| 3910 | if (telephonyService.isRinging()) { |
| 3911 | // Pressing Power while there's a ringing incoming |
| 3912 | // call should silence the ringer. |
| 3913 | telephonyService.silenceRinger(); |
| 3914 | } else if ((mIncallPowerBehavior |
| 3915 | & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 |
| 3916 | && telephonyService.isOffhook()) { |
| 3917 | // Otherwise, if "Power button ends call" is enabled, |
| 3918 | // the Power button will hang up any current active call. |
| 3919 | hungUp = telephonyService.endCall(); |
| 3920 | } |
| 3921 | } catch (RemoteException ex) { |
| 3922 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
| 3923 | } |
| 3924 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3925 | interceptPowerKeyDown(!isScreenOn || hungUp |
| 3926 | || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3927 | } else { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3928 | mPowerKeyTriggered = false; |
| 3929 | cancelPendingScreenshotChordAction(); |
| 3930 | if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3931 | result = (result & ~ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3932 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3933 | mPendingPowerKeyUpCanceled = false; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3934 | } |
| 3935 | break; |
| 3936 | } |
| 3937 | |
| 3938 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 3939 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 3940 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 3941 | if (down) { |
| 3942 | ITelephony telephonyService = getTelephonyService(); |
| 3943 | if (telephonyService != null) { |
| 3944 | try { |
| 3945 | if (!telephonyService.isIdle()) { |
| 3946 | // Suppress PLAY/PAUSE toggle when phone is ringing or in-call |
| 3947 | // to avoid music playback. |
| 3948 | break; |
| 3949 | } |
| 3950 | } catch (RemoteException ex) { |
| 3951 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 3952 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3953 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3954 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3955 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 3956 | case KeyEvent.KEYCODE_MUTE: |
| 3957 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 3958 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 3959 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 3960 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 3961 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 3962 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
| 3963 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3964 | if ((result & ACTION_PASS_TO_USER) == 0) { |
| 3965 | // Only do this if we would otherwise not pass it to the user. In that |
| 3966 | // case, the PhoneWindow class will do the same thing, except it will |
| 3967 | // only do it if the showing app doesn't process the key on its own. |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3968 | // Note that we need to make a copy of the key event here because the |
| 3969 | // original key event will be recycled when we return. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3970 | mBroadcastWakeLock.acquire(); |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3971 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK, |
| 3972 | new KeyEvent(event)); |
| 3973 | msg.setAsynchronous(true); |
| 3974 | msg.sendToTarget(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3975 | } |
| 3976 | break; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3977 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3978 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3979 | case KeyEvent.KEYCODE_CALL: { |
| 3980 | if (down) { |
| 3981 | ITelephony telephonyService = getTelephonyService(); |
| 3982 | if (telephonyService != null) { |
| 3983 | try { |
| 3984 | if (telephonyService.isRinging()) { |
| 3985 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 3986 | + " CALL key-down while ringing: Answer the call!"); |
| 3987 | telephonyService.answerRingingCall(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3988 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3989 | // And *don't* pass this key thru to the current activity |
| 3990 | // (which is presumably the InCallScreen.) |
| 3991 | result &= ~ACTION_PASS_TO_USER; |
| 3992 | } |
| 3993 | } catch (RemoteException ex) { |
| 3994 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3995 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3996 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3997 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3998 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3999 | } |
| 4000 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4001 | return result; |
| 4002 | } |
| 4003 | |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 4004 | /** |
| 4005 | * When the screen is off we ignore some keys that might otherwise typically |
| 4006 | * be considered wake keys. We filter them out here. |
| 4007 | * |
| 4008 | * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it |
| 4009 | * is always considered a wake key. |
| 4010 | */ |
| 4011 | private boolean isWakeKeyWhenScreenOff(int keyCode) { |
| 4012 | switch (keyCode) { |
| 4013 | // ignore volume keys unless docked |
| 4014 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 4015 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 4016 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 4017 | return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 4018 | |
| 4019 | // ignore media and camera keys |
| 4020 | case KeyEvent.KEYCODE_MUTE: |
| 4021 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 4022 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 4023 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 4024 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 4025 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 4026 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 4027 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 4028 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 4029 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
| 4030 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 4031 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 4032 | case KeyEvent.KEYCODE_CAMERA: |
| 4033 | return false; |
| 4034 | } |
| 4035 | return true; |
| 4036 | } |
| 4037 | |
| 4038 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 4039 | /** {@inheritDoc} */ |
| 4040 | @Override |
| 4041 | public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) { |
| 4042 | int result = 0; |
| 4043 | |
| 4044 | final boolean isWakeMotion = (policyFlags |
| 4045 | & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0; |
| 4046 | if (isWakeMotion) { |
Jim Miller | e51cf7ae | 2013-06-25 18:31:56 -0700 | [diff] [blame] | 4047 | result |= ACTION_WAKE_UP; |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 4048 | } |
| 4049 | return result; |
| 4050 | } |
| 4051 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4052 | void dispatchMediaKeyWithWakeLock(KeyEvent event) { |
| 4053 | if (DEBUG_INPUT) { |
| 4054 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4055 | } |
| 4056 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4057 | if (mHavePendingMediaKeyRepeatWithWakeLock) { |
| 4058 | if (DEBUG_INPUT) { |
| 4059 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat"); |
| 4060 | } |
| 4061 | |
| 4062 | mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK); |
| 4063 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 4064 | mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock |
| 4065 | } |
| 4066 | |
| 4067 | dispatchMediaKeyWithWakeLockToAudioService(event); |
| 4068 | |
| 4069 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 4070 | && event.getRepeatCount() == 0) { |
| 4071 | mHavePendingMediaKeyRepeatWithWakeLock = true; |
| 4072 | |
| 4073 | Message msg = mHandler.obtainMessage( |
| 4074 | MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event); |
| 4075 | msg.setAsynchronous(true); |
| 4076 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout()); |
| 4077 | } else { |
| 4078 | mBroadcastWakeLock.release(); |
| 4079 | } |
| 4080 | } |
| 4081 | |
| 4082 | void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) { |
| 4083 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 4084 | |
| 4085 | KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event, |
| 4086 | SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 4087 | if (DEBUG_INPUT) { |
| 4088 | Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent); |
| 4089 | } |
| 4090 | |
| 4091 | dispatchMediaKeyWithWakeLockToAudioService(repeatEvent); |
| 4092 | mBroadcastWakeLock.release(); |
| 4093 | } |
| 4094 | |
| 4095 | void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) { |
| 4096 | if (ActivityManagerNative.isSystemReady()) { |
| 4097 | IAudioService audioService = getAudioService(); |
| 4098 | if (audioService != null) { |
| 4099 | try { |
| 4100 | audioService.dispatchMediaKeyEventUnderWakelock(event); |
| 4101 | } catch (RemoteException e) { |
| 4102 | Log.e(TAG, "dispatchMediaKeyEvent threw exception " + e); |
Jean-Michel Trivi | c680222 | 2012-04-30 11:15:03 -0700 | [diff] [blame] | 4103 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4104 | } |
| 4105 | } |
| 4106 | } |
| 4107 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 4108 | BroadcastReceiver mDockReceiver = new BroadcastReceiver() { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 4109 | @Override |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 4110 | public void onReceive(Context context, Intent intent) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 4111 | if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) { |
| 4112 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 4113 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 4114 | } else { |
| 4115 | try { |
| 4116 | IUiModeManager uiModeService = IUiModeManager.Stub.asInterface( |
| 4117 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 4118 | mUiMode = uiModeService.getCurrentModeType(); |
| 4119 | } catch (RemoteException e) { |
| 4120 | } |
Dianne Hackborn | 80fa166 | 2009-10-07 14:02:10 -0700 | [diff] [blame] | 4121 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4122 | updateRotation(true); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 4123 | synchronized (mLock) { |
| 4124 | updateOrientationListenerLp(); |
| 4125 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 4126 | } |
| 4127 | }; |
| 4128 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 4129 | BroadcastReceiver mDreamReceiver = new BroadcastReceiver() { |
| 4130 | @Override |
| 4131 | public void onReceive(Context context, Intent intent) { |
| 4132 | if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4133 | if (mKeyguardDelegate != null) { |
| 4134 | mKeyguardDelegate.onDreamingStarted(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 4135 | } |
| 4136 | } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4137 | if (mKeyguardDelegate != null) { |
| 4138 | mKeyguardDelegate.onDreamingStopped(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 4139 | } |
| 4140 | } |
| 4141 | } |
| 4142 | }; |
| 4143 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4144 | BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() { |
| 4145 | @Override |
| 4146 | public void onReceive(Context context, Intent intent) { |
| 4147 | if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) { |
| 4148 | // tickle the settings observer: this first ensures that we're |
| 4149 | // observing the relevant settings for the newly-active user, |
| 4150 | // and then updates our own bookkeeping based on the now- |
| 4151 | // current user. |
| 4152 | mSettingsObserver.onChange(false); |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 4153 | |
| 4154 | // force a re-application of focused window sysui visibility. |
| 4155 | // the window may never have been shown for this user |
| 4156 | // e.g. the keyguard when going through the new-user setup flow |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 4157 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 4158 | mLastSystemUiFlags = 0; |
| 4159 | updateSystemUiVisibilityLw(); |
| 4160 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4161 | } |
| 4162 | } |
| 4163 | }; |
| 4164 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 4165 | private void requestTransientBars(WindowState swipeTarget) { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 4166 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4167 | boolean sb = mStatusBarController.checkShowTransientBarLw(); |
| 4168 | boolean nb = mNavigationBarController.checkShowTransientBarLw(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4169 | if (sb || nb) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 4170 | WindowState barTarget = sb ? mStatusBar : mNavigationBar; |
| 4171 | if (sb ^ nb && barTarget != swipeTarget) { |
| 4172 | if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target"); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4173 | return; |
| 4174 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4175 | if (sb) mStatusBarController.showTransient(); |
| 4176 | if (nb) mNavigationBarController.showTransient(); |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 4177 | mTransientNavigationConfirmation.confirmCurrentPrompt(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4178 | updateSystemUiVisibilityLw(); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 4179 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4180 | } |
| 4181 | } |
| 4182 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4183 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4184 | public void screenTurnedOff(int why) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 4185 | EventLog.writeEvent(70000, 0); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4186 | synchronized (mLock) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4187 | mScreenOnEarly = false; |
| 4188 | mScreenOnFully = false; |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 4189 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4190 | if (mKeyguardDelegate != null) { |
| 4191 | mKeyguardDelegate.onScreenTurnedOff(why); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4192 | } |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 4193 | synchronized (mLock) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4194 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4195 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4196 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4197 | } |
| 4198 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4199 | @Override |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 4200 | public void screenTurningOn(final ScreenOnListener screenOnListener) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 4201 | EventLog.writeEvent(70000, 1); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 4202 | if (false) { |
| 4203 | RuntimeException here = new RuntimeException("here"); |
| 4204 | here.fillInStackTrace(); |
| 4205 | Slog.i(TAG, "Screen turning on...", here); |
| 4206 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4207 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4208 | synchronized (mLock) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4209 | mScreenOnEarly = true; |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4210 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4211 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4212 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4213 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4214 | waitForKeyguard(screenOnListener); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4215 | } |
| 4216 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4217 | private void waitForKeyguard(final ScreenOnListener screenOnListener) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4218 | if (mKeyguardDelegate != null) { |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4219 | if (screenOnListener != null) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4220 | mKeyguardDelegate.onScreenTurnedOn(new KeyguardServiceDelegate.ShowListener() { |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4221 | @Override |
| 4222 | public void onShown(IBinder windowToken) { |
| 4223 | waitForKeyguardWindowDrawn(windowToken, screenOnListener); |
| 4224 | } |
| 4225 | }); |
| 4226 | return; |
| 4227 | } else { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4228 | mKeyguardDelegate.onScreenTurnedOn(null); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4229 | } |
| 4230 | } else { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4231 | Slog.i(TAG, "No keyguard interface!"); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4232 | } |
| 4233 | finishScreenTurningOn(screenOnListener); |
| 4234 | } |
| 4235 | |
| 4236 | private void waitForKeyguardWindowDrawn(IBinder windowToken, |
| 4237 | final ScreenOnListener screenOnListener) { |
| 4238 | if (windowToken != null) { |
| 4239 | try { |
| 4240 | if (mWindowManager.waitForWindowDrawn( |
| 4241 | windowToken, new IRemoteCallback.Stub() { |
| 4242 | @Override |
| 4243 | public void sendResult(Bundle data) { |
| 4244 | Slog.i(TAG, "Lock screen displayed!"); |
| 4245 | finishScreenTurningOn(screenOnListener); |
| 4246 | } |
| 4247 | })) { |
| 4248 | return; |
| 4249 | } |
| 4250 | } catch (RemoteException ex) { |
| 4251 | // Can't happen in system process. |
| 4252 | } |
| 4253 | } |
| 4254 | |
| 4255 | Slog.i(TAG, "No lock screen!"); |
| 4256 | finishScreenTurningOn(screenOnListener); |
| 4257 | } |
| 4258 | |
| 4259 | private void finishScreenTurningOn(ScreenOnListener screenOnListener) { |
| 4260 | synchronized (mLock) { |
| 4261 | mScreenOnFully = true; |
| 4262 | } |
| 4263 | |
Jeff Brown | 4fc4527 | 2012-10-10 18:28:14 -0700 | [diff] [blame] | 4264 | try { |
| 4265 | mWindowManager.setEventDispatching(true); |
| 4266 | } catch (RemoteException unhandled) { |
| 4267 | } |
| 4268 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4269 | if (screenOnListener != null) { |
| 4270 | screenOnListener.onScreenOn(); |
| 4271 | } |
| 4272 | } |
| 4273 | |
| 4274 | @Override |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4275 | public boolean isScreenOnEarly() { |
| 4276 | return mScreenOnEarly; |
| 4277 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4278 | |
| 4279 | @Override |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4280 | public boolean isScreenOnFully() { |
| 4281 | return mScreenOnFully; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4282 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4283 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4284 | /** {@inheritDoc} */ |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4285 | public void enableKeyguard(boolean enabled) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4286 | if (mKeyguardDelegate != null) { |
| 4287 | mKeyguardDelegate.setKeyguardEnabled(enabled); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4288 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4289 | } |
| 4290 | |
| 4291 | /** {@inheritDoc} */ |
| 4292 | public void exitKeyguardSecurely(OnKeyguardExitResult callback) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4293 | if (mKeyguardDelegate != null) { |
| 4294 | mKeyguardDelegate.verifyUnlock(callback); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4295 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4296 | } |
| 4297 | |
Mike Lockwood | f791330 | 2009-11-28 22:27:10 -0500 | [diff] [blame] | 4298 | private boolean keyguardIsShowingTq() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4299 | if (mKeyguardDelegate == null) return false; |
| 4300 | return mKeyguardDelegate.isShowingAndNotHidden(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4301 | } |
| 4302 | |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 4303 | |
| 4304 | /** {@inheritDoc} */ |
| 4305 | public boolean isKeyguardLocked() { |
| 4306 | return keyguardOn(); |
| 4307 | } |
| 4308 | |
| 4309 | /** {@inheritDoc} */ |
| 4310 | public boolean isKeyguardSecure() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4311 | if (mKeyguardDelegate == null) return false; |
| 4312 | return mKeyguardDelegate.isSecure(); |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 4313 | } |
| 4314 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4315 | /** {@inheritDoc} */ |
| 4316 | public boolean inKeyguardRestrictedKeyInputMode() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4317 | if (mKeyguardDelegate == null) return false; |
| 4318 | return mKeyguardDelegate.isInputRestricted(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4319 | } |
| 4320 | |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 4321 | public void dismissKeyguardLw() { |
Jim Miller | 195b551 | 2013-02-28 03:35:57 -0800 | [diff] [blame] | 4322 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) { |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 4323 | mHandler.post(new Runnable() { |
| 4324 | public void run() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4325 | if (mKeyguardDelegate.isDismissable()) { |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 4326 | // Can we just finish the keyguard straight away? |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4327 | mKeyguardDelegate.keyguardDone(false, true); |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 4328 | } else { |
| 4329 | // ask the keyguard to prompt the user to authenticate if necessary |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4330 | mKeyguardDelegate.dismiss(); |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 4331 | } |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 4332 | } |
| 4333 | }); |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 4334 | } |
| 4335 | } |
| 4336 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4337 | void sendCloseSystemWindows() { |
| 4338 | sendCloseSystemWindows(mContext, null); |
| 4339 | } |
| 4340 | |
| 4341 | void sendCloseSystemWindows(String reason) { |
| 4342 | sendCloseSystemWindows(mContext, reason); |
| 4343 | } |
| 4344 | |
| 4345 | static void sendCloseSystemWindows(Context context, String reason) { |
| 4346 | if (ActivityManagerNative.isSystemReady()) { |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 4347 | try { |
| 4348 | ActivityManagerNative.getDefault().closeSystemDialogs(reason); |
| 4349 | } catch (RemoteException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4350 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4351 | } |
| 4352 | } |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 4353 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4354 | @Override |
| 4355 | public int rotationForOrientationLw(int orientation, int lastRotation) { |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 4356 | if (false) { |
| 4357 | Slog.v(TAG, "rotationForOrientationLw(orient=" |
| 4358 | + orientation + ", last=" + lastRotation |
| 4359 | + "); user=" + mUserRotation + " " |
| 4360 | + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) |
| 4361 | ? "USER_ROTATION_LOCKED" : "") |
| 4362 | ); |
| 4363 | } |
| 4364 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 4365 | if (mForceDefaultOrientation) { |
| 4366 | return Surface.ROTATION_0; |
| 4367 | } |
| 4368 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4369 | synchronized (mLock) { |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4370 | int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1 |
| 4371 | if (sensorRotation < 0) { |
Jeff Brown | 0f862b4 | 2012-09-27 21:11:01 -0700 | [diff] [blame] | 4372 | sensorRotation = lastRotation; |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4373 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4374 | |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4375 | final int preferredRotation; |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 4376 | if (mLidState == LID_OPEN && mLidOpenRotation >= 0) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4377 | // Ignore sensor when lid switch is open and rotation is forced. |
| 4378 | preferredRotation = mLidOpenRotation; |
| 4379 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4380 | && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4381 | // Ignore sensor when in car dock unless explicitly enabled. |
| 4382 | // This case can override the behavior of NOSENSOR, and can also |
| 4383 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4384 | preferredRotation = mCarDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4385 | ? sensorRotation : mCarDockRotation; |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 4386 | } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 4387 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 4388 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK) |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4389 | && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4390 | // Ignore sensor when in desk dock unless explicitly enabled. |
| 4391 | // This case can override the behavior of NOSENSOR, and can also |
| 4392 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4393 | preferredRotation = mDeskDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4394 | ? sensorRotation : mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 4395 | } else if (mHdmiPlugged && mDemoHdmiRotationLock) { |
| 4396 | // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled. |
Jeff Brown | eb3e4b9 | 2011-12-06 19:54:24 -0800 | [diff] [blame] | 4397 | // Note that the dock orientation overrides the HDMI orientation. |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 4398 | preferredRotation = mDemoHdmiRotation; |
| 4399 | } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED |
| 4400 | && mUndockedHdmiRotation >= 0) { |
| 4401 | // Ignore sensor when plugged into HDMI and an undocked orientation has |
| 4402 | // been specified in the configuration (only for legacy devices without |
| 4403 | // full multi-display support). |
| 4404 | // Note that the dock orientation overrides the HDMI orientation. |
| 4405 | preferredRotation = mUndockedHdmiRotation; |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 4406 | } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) { |
| 4407 | // Application just wants to remain locked in the last rotation. |
| 4408 | preferredRotation = lastRotation; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 4409 | } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4410 | && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 4411 | || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 4412 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE |
| 4413 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT |
| 4414 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER)) |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4415 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 4416 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 4417 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE |
| 4418 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { |
| 4419 | // Otherwise, use sensor only if requested by the application or enabled |
| 4420 | // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR. |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 4421 | if (mAllowAllRotations < 0) { |
| 4422 | // Can't read this during init() because the context doesn't |
| 4423 | // have display metrics at that time so we cannot determine |
| 4424 | // tablet vs. phone then. |
| 4425 | mAllowAllRotations = mContext.getResources().getBoolean( |
| 4426 | com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0; |
| 4427 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4428 | if (sensorRotation != Surface.ROTATION_180 |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 4429 | || mAllowAllRotations == 1 |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 4430 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 4431 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4432 | preferredRotation = sensorRotation; |
| 4433 | } else { |
| 4434 | preferredRotation = lastRotation; |
| 4435 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 4436 | } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED |
| 4437 | && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { |
| 4438 | // Apply rotation lock. Does not apply to NOSENSOR. |
| 4439 | // The idea is that the user rotation expresses a weak preference for the direction |
| 4440 | // of gravity and as NOSENSOR is never affected by gravity, then neither should |
| 4441 | // NOSENSOR be affected by rotation lock (although it will be affected by docks). |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 4442 | preferredRotation = mUserRotation; |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4443 | } else { |
| 4444 | // No overriding preference. |
| 4445 | // We will do exactly what the application asked us to do. |
| 4446 | preferredRotation = -1; |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4447 | } |
| 4448 | |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4449 | switch (orientation) { |
| 4450 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4451 | // Return portrait unless overridden. |
| 4452 | if (isAnyPortrait(preferredRotation)) { |
| 4453 | return preferredRotation; |
| 4454 | } |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4455 | return mPortraitRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4456 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4457 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4458 | // Return landscape unless overridden. |
| 4459 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 4460 | return preferredRotation; |
| 4461 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4462 | return mLandscapeRotation; |
| 4463 | |
| 4464 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4465 | // Return reverse portrait unless overridden. |
| 4466 | if (isAnyPortrait(preferredRotation)) { |
| 4467 | return preferredRotation; |
| 4468 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4469 | return mUpsideDownRotation; |
| 4470 | |
| 4471 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4472 | // Return seascape unless overridden. |
| 4473 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 4474 | return preferredRotation; |
| 4475 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4476 | return mSeascapeRotation; |
| 4477 | |
| 4478 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 4479 | case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4480 | // Return either landscape rotation. |
| 4481 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 4482 | return preferredRotation; |
| 4483 | } |
| 4484 | if (isLandscapeOrSeascape(lastRotation)) { |
Jeff Brown | 4519f07 | 2011-01-23 13:16:01 -0800 | [diff] [blame] | 4485 | return lastRotation; |
| 4486 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4487 | return mLandscapeRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4488 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4489 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 4490 | case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4491 | // Return either portrait rotation. |
| 4492 | if (isAnyPortrait(preferredRotation)) { |
| 4493 | return preferredRotation; |
| 4494 | } |
| 4495 | if (isAnyPortrait(lastRotation)) { |
| 4496 | return lastRotation; |
| 4497 | } |
| 4498 | return mPortraitRotation; |
| 4499 | |
| 4500 | default: |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 4501 | // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR, |
| 4502 | // just return the preferred orientation we already calculated. |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4503 | if (preferredRotation >= 0) { |
| 4504 | return preferredRotation; |
| 4505 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 4506 | return Surface.ROTATION_0; |
Daniel Sandler | e7e5ac2 | 2011-02-22 16:10:21 -0500 | [diff] [blame] | 4507 | } |
| 4508 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 4509 | } |
| 4510 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4511 | @Override |
| 4512 | public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) { |
| 4513 | switch (orientation) { |
| 4514 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
| 4515 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
| 4516 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
| 4517 | return isAnyPortrait(rotation); |
| 4518 | |
| 4519 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
| 4520 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
| 4521 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
| 4522 | return isLandscapeOrSeascape(rotation); |
| 4523 | |
| 4524 | default: |
| 4525 | return true; |
| 4526 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 4527 | } |
| 4528 | |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4529 | @Override |
| 4530 | public void setRotationLw(int rotation) { |
| 4531 | mOrientationListener.setCurrentRotation(rotation); |
| 4532 | } |
| 4533 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4534 | private boolean isLandscapeOrSeascape(int rotation) { |
| 4535 | return rotation == mLandscapeRotation || rotation == mSeascapeRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4536 | } |
| 4537 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4538 | private boolean isAnyPortrait(int rotation) { |
| 4539 | return rotation == mPortraitRotation || rotation == mUpsideDownRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4540 | } |
| 4541 | |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 4542 | public int getUserRotationMode() { |
| 4543 | return Settings.System.getIntForUser(mContext.getContentResolver(), |
Brett Chabot | 7e55c40 | 2013-05-16 19:38:08 -0700 | [diff] [blame] | 4544 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
| 4545 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 4546 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 4547 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4548 | |
| 4549 | // User rotation: to be used when all else fails in assigning an orientation to the device |
| 4550 | public void setUserRotationMode(int mode, int rot) { |
| 4551 | ContentResolver res = mContext.getContentResolver(); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 4552 | |
| 4553 | // mUserRotationMode and mUserRotation will be assigned by the content observer |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4554 | if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4555 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4556 | Settings.System.USER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4557 | rot, |
| 4558 | UserHandle.USER_CURRENT); |
| 4559 | Settings.System.putIntForUser(res, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 4560 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4561 | 0, |
| 4562 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4563 | } else { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4564 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4565 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4566 | 1, |
| 4567 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4568 | } |
| 4569 | } |
| 4570 | |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 4571 | public void setSafeMode(boolean safeMode) { |
| 4572 | mSafeMode = safeMode; |
| 4573 | performHapticFeedbackLw(null, safeMode |
| 4574 | ? HapticFeedbackConstants.SAFE_MODE_ENABLED |
| 4575 | : HapticFeedbackConstants.SAFE_MODE_DISABLED, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4576 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4577 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 4578 | static long[] getLongIntArray(Resources r, int resid) { |
| 4579 | int[] ar = r.getIntArray(resid); |
| 4580 | if (ar == null) { |
| 4581 | return null; |
| 4582 | } |
| 4583 | long[] out = new long[ar.length]; |
| 4584 | for (int i=0; i<ar.length; i++) { |
| 4585 | out[i] = ar[i]; |
| 4586 | } |
| 4587 | return out; |
| 4588 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4589 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4590 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4591 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4592 | public void systemReady() { |
Jim Miller | 195b551 | 2013-02-28 03:35:57 -0800 | [diff] [blame] | 4593 | if (!mHeadless) { |
| 4594 | mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4595 | mKeyguardDelegate.onSystemReady(); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4596 | } |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 4597 | synchronized (mLock) { |
| 4598 | updateOrientationListenerLp(); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 4599 | mSystemReady = true; |
| 4600 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4601 | @Override |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 4602 | public void run() { |
| 4603 | updateSettings(); |
| 4604 | } |
| 4605 | }); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4606 | } |
| 4607 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4608 | |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 4609 | /** {@inheritDoc} */ |
| 4610 | public void systemBooted() { |
| 4611 | synchronized (mLock) { |
| 4612 | mSystemBooted = true; |
| 4613 | } |
| 4614 | } |
| 4615 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4616 | ProgressDialog mBootMsgDialog = null; |
| 4617 | |
| 4618 | /** {@inheritDoc} */ |
| 4619 | public void showBootMessage(final CharSequence msg, final boolean always) { |
Mike Lockwood | aa5bf14 | 2011-09-21 13:03:40 -0400 | [diff] [blame] | 4620 | if (mHeadless) return; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4621 | mHandler.post(new Runnable() { |
| 4622 | @Override public void run() { |
| 4623 | if (mBootMsgDialog == null) { |
Dianne Hackborn | 295e3c2 | 2011-08-25 13:19:08 -0700 | [diff] [blame] | 4624 | mBootMsgDialog = new ProgressDialog(mContext) { |
| 4625 | // This dialog will consume all events coming in to |
| 4626 | // it, to avoid it trying to do things too early in boot. |
| 4627 | @Override public boolean dispatchKeyEvent(KeyEvent event) { |
| 4628 | return true; |
| 4629 | } |
| 4630 | @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 4631 | return true; |
| 4632 | } |
| 4633 | @Override public boolean dispatchTouchEvent(MotionEvent ev) { |
| 4634 | return true; |
| 4635 | } |
| 4636 | @Override public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 4637 | return true; |
| 4638 | } |
| 4639 | @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 4640 | return true; |
| 4641 | } |
| 4642 | @Override public boolean dispatchPopulateAccessibilityEvent( |
| 4643 | AccessibilityEvent event) { |
| 4644 | return true; |
| 4645 | } |
| 4646 | }; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4647 | mBootMsgDialog.setTitle(R.string.android_upgrading_title); |
| 4648 | mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
| 4649 | mBootMsgDialog.setIndeterminate(true); |
| 4650 | mBootMsgDialog.getWindow().setType( |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 4651 | WindowManager.LayoutParams.TYPE_BOOT_PROGRESS); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4652 | mBootMsgDialog.getWindow().addFlags( |
| 4653 | WindowManager.LayoutParams.FLAG_DIM_BEHIND |
| 4654 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); |
| 4655 | mBootMsgDialog.getWindow().setDimAmount(1); |
Dianne Hackborn | d9efb95 | 2011-12-07 14:56:51 -0800 | [diff] [blame] | 4656 | WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes(); |
| 4657 | lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; |
| 4658 | mBootMsgDialog.getWindow().setAttributes(lp); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4659 | mBootMsgDialog.setCancelable(false); |
| 4660 | mBootMsgDialog.show(); |
| 4661 | } |
| 4662 | mBootMsgDialog.setMessage(msg); |
| 4663 | } |
| 4664 | }); |
| 4665 | } |
| 4666 | |
| 4667 | /** {@inheritDoc} */ |
| 4668 | public void hideBootMessages() { |
| 4669 | mHandler.post(new Runnable() { |
| 4670 | @Override public void run() { |
| 4671 | if (mBootMsgDialog != null) { |
| 4672 | mBootMsgDialog.dismiss(); |
| 4673 | mBootMsgDialog = null; |
| 4674 | } |
| 4675 | } |
| 4676 | }); |
| 4677 | } |
| 4678 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4679 | /** {@inheritDoc} */ |
| 4680 | public void userActivity() { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4681 | // *************************************** |
| 4682 | // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE |
| 4683 | // *************************************** |
| 4684 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 4685 | // WITH ITS LOCKS HELD. |
| 4686 | // |
| 4687 | // This code must be VERY careful about the locks |
| 4688 | // it acquires. |
| 4689 | // In fact, the current code acquires way too many, |
| 4690 | // and probably has lurking deadlocks. |
| 4691 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4692 | synchronized (mScreenLockTimeout) { |
| 4693 | if (mLockScreenTimerActive) { |
| 4694 | // reset the timer |
| 4695 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 4696 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 4697 | } |
| 4698 | } |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 4699 | } |
| 4700 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 4701 | class ScreenLockTimeout implements Runnable { |
| 4702 | Bundle options; |
| 4703 | |
| 4704 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4705 | public void run() { |
| 4706 | synchronized (this) { |
| 4707 | if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4708 | if (mKeyguardDelegate != null) { |
| 4709 | mKeyguardDelegate.doKeyguardTimeout(options); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4710 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4711 | mLockScreenTimerActive = false; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 4712 | options = null; |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4713 | } |
| 4714 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4715 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 4716 | public void setLockOptions(Bundle options) { |
| 4717 | this.options = options; |
| 4718 | } |
| 4719 | } |
| 4720 | |
| 4721 | ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout(); |
| 4722 | |
| 4723 | public void lockNow(Bundle options) { |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 4724 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); |
| 4725 | mHandler.removeCallbacks(mScreenLockTimeout); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 4726 | if (options != null) { |
| 4727 | // In case multiple calls are made to lockNow, we don't wipe out the options |
| 4728 | // until the runnable actually executes. |
| 4729 | mScreenLockTimeout.setLockOptions(options); |
| 4730 | } |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 4731 | mHandler.post(mScreenLockTimeout); |
| 4732 | } |
| 4733 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4734 | private void updateLockScreenTimeout() { |
| 4735 | synchronized (mScreenLockTimeout) { |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4736 | boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly && |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4737 | mKeyguardDelegate != null && mKeyguardDelegate.isSecure()); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4738 | if (mLockScreenTimerActive != enable) { |
| 4739 | if (enable) { |
| 4740 | if (localLOGV) Log.v(TAG, "setting lockscreen timer"); |
| 4741 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 4742 | } else { |
| 4743 | if (localLOGV) Log.v(TAG, "clearing lockscreen timer"); |
| 4744 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 4745 | } |
| 4746 | mLockScreenTimerActive = enable; |
| 4747 | } |
| 4748 | } |
| 4749 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4750 | |
| 4751 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4752 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4753 | public void enableScreenAfterBoot() { |
| 4754 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4755 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4756 | updateRotation(true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4757 | } |
Dianne Hackborn | f54c8f9 | 2009-09-19 14:03:57 -0700 | [diff] [blame] | 4758 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4759 | private void applyLidSwitchState() { |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4760 | if (mLidState == LID_CLOSED && mLidControlsSleep) { |
| 4761 | mPowerManager.goToSleep(SystemClock.uptimeMillis()); |
| 4762 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4763 | } |
| 4764 | |
| 4765 | void updateRotation(boolean alwaysSendConfiguration) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4766 | try { |
| 4767 | //set orientation on WindowManager |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4768 | mWindowManager.updateRotation(alwaysSendConfiguration, false); |
| 4769 | } catch (RemoteException e) { |
| 4770 | // Ignore |
| 4771 | } |
| 4772 | } |
| 4773 | |
| 4774 | void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) { |
| 4775 | try { |
| 4776 | //set orientation on WindowManager |
| 4777 | mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4778 | } catch (RemoteException e) { |
| 4779 | // Ignore |
| 4780 | } |
| 4781 | } |
| 4782 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 4783 | /** |
| 4784 | * Return an Intent to launch the currently active dock app as home. Returns |
| 4785 | * null if the standard home should be launched, which is the case if any of the following is |
| 4786 | * true: |
| 4787 | * <ul> |
| 4788 | * <li>The device is not in either car mode or desk mode |
| 4789 | * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false |
| 4790 | * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false |
| 4791 | * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME |
| 4792 | * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME |
| 4793 | * </ul> |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4794 | * @return A dock intent. |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 4795 | */ |
| 4796 | Intent createHomeDockIntent() { |
| 4797 | Intent intent = null; |
| 4798 | |
| 4799 | // What home does is based on the mode, not the dock state. That |
| 4800 | // is, when in car mode you should be taken to car home regardless |
| 4801 | // of whether we are actually in a car dock. |
| 4802 | if (mUiMode == Configuration.UI_MODE_TYPE_CAR) { |
| 4803 | if (ENABLE_CAR_DOCK_HOME_CAPTURE) { |
| 4804 | intent = mCarDockIntent; |
| 4805 | } |
| 4806 | } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) { |
| 4807 | if (ENABLE_DESK_DOCK_HOME_CAPTURE) { |
| 4808 | intent = mDeskDockIntent; |
| 4809 | } |
| 4810 | } |
| 4811 | |
| 4812 | if (intent == null) { |
| 4813 | return null; |
| 4814 | } |
| 4815 | |
| 4816 | ActivityInfo ai = null; |
| 4817 | ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser( |
| 4818 | intent, |
John Spurlock | f56bef1 | 2013-07-09 09:51:46 -0400 | [diff] [blame] | 4819 | PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA, |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 4820 | mCurrentUserId); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 4821 | if (info != null) { |
| 4822 | ai = info.activityInfo; |
| 4823 | } |
| 4824 | if (ai != null |
| 4825 | && ai.metaData != null |
| 4826 | && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) { |
| 4827 | intent = new Intent(intent); |
| 4828 | intent.setClassName(ai.packageName, ai.name); |
| 4829 | return intent; |
| 4830 | } |
| 4831 | |
| 4832 | return null; |
| 4833 | } |
| 4834 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4835 | void startDockOrHome() { |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 4836 | awakenDreams(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 4837 | |
| 4838 | Intent dock = createHomeDockIntent(); |
| 4839 | if (dock != null) { |
| 4840 | try { |
| 4841 | mContext.startActivityAsUser(dock, UserHandle.CURRENT); |
| 4842 | return; |
| 4843 | } catch (ActivityNotFoundException e) { |
| 4844 | } |
| 4845 | } |
| 4846 | |
Dianne Hackborn | d888399 | 2012-09-07 15:58:52 -0700 | [diff] [blame] | 4847 | mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4848 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4849 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4850 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4851 | * goes to the home screen |
| 4852 | * @return whether it did anything |
| 4853 | */ |
| 4854 | boolean goHome() { |
| 4855 | if (false) { |
| 4856 | // This code always brings home to the front. |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 4857 | try { |
| 4858 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 4859 | } catch (RemoteException e) { |
| 4860 | } |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 4861 | sendCloseSystemWindows(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4862 | startDockOrHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4863 | } else { |
| 4864 | // This code brings home to the front or, if it is already |
| 4865 | // at the front, puts the device to sleep. |
| 4866 | try { |
Wink Saville | d2e6a33 | 2010-02-12 12:12:06 -0800 | [diff] [blame] | 4867 | if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) { |
| 4868 | /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry. |
| 4869 | Log.d(TAG, "UTS-TEST-MODE"); |
| 4870 | } else { |
| 4871 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 4872 | sendCloseSystemWindows(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 4873 | Intent dock = createHomeDockIntent(); |
| 4874 | if (dock != null) { |
| 4875 | int result = ActivityManagerNative.getDefault() |
| 4876 | .startActivityAsUser(null, null, dock, |
| 4877 | dock.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 4878 | null, null, 0, |
| 4879 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
| 4880 | null, null, null, UserHandle.USER_CURRENT); |
| 4881 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
| 4882 | return false; |
| 4883 | } |
| 4884 | } |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4885 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4886 | int result = ActivityManagerNative.getDefault() |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 4887 | .startActivityAsUser(null, null, mHomeIntent, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4888 | mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4889 | null, null, 0, |
| 4890 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Dianne Hackborn | 5e03e2c | 2012-09-06 14:21:19 -0700 | [diff] [blame] | 4891 | null, null, null, UserHandle.USER_CURRENT); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4892 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4893 | return false; |
| 4894 | } |
| 4895 | } catch (RemoteException ex) { |
| 4896 | // bummer, the activity manager, which is in this process, is dead |
| 4897 | } |
| 4898 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4899 | return true; |
| 4900 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4901 | |
| 4902 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4903 | public void setCurrentOrientationLw(int newOrientation) { |
| 4904 | synchronized (mLock) { |
| 4905 | if (newOrientation != mCurrentAppOrientation) { |
| 4906 | mCurrentAppOrientation = newOrientation; |
| 4907 | updateOrientationListenerLp(); |
| 4908 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4909 | } |
| 4910 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4911 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 4912 | private void performAuditoryFeedbackForAccessibilityIfNeed() { |
| 4913 | if (!isGlobalAccessibilityGestureEnabled()) { |
| 4914 | return; |
| 4915 | } |
| 4916 | AudioManager audioManager = (AudioManager) mContext.getSystemService( |
| 4917 | Context.AUDIO_SERVICE); |
| 4918 | if (audioManager.isSilentMode()) { |
| 4919 | return; |
| 4920 | } |
| 4921 | Ringtone ringTone = RingtoneManager.getRingtone(mContext, |
| 4922 | Settings.System.DEFAULT_NOTIFICATION_URI); |
| 4923 | ringTone.setStreamType(AudioManager.STREAM_MUSIC); |
| 4924 | ringTone.play(); |
| 4925 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4926 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 4927 | private boolean isGlobalAccessibilityGestureEnabled() { |
| 4928 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 4929 | Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1; |
| 4930 | } |
| 4931 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4932 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4933 | public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) { |
Svetoslav Ganov | 9617921 | 2012-10-10 14:17:45 -0700 | [diff] [blame] | 4934 | if (!mVibrator.hasVibrator()) { |
| 4935 | return false; |
| 4936 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4937 | final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 4938 | Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4939 | if (!always && (hapticsDisabled || mKeyguardDelegate.isShowingAndNotHidden())) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4940 | return false; |
| 4941 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4942 | long[] pattern = null; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4943 | switch (effectId) { |
| 4944 | case HapticFeedbackConstants.LONG_PRESS: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4945 | pattern = mLongPressVibePattern; |
| 4946 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 4947 | case HapticFeedbackConstants.VIRTUAL_KEY: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4948 | pattern = mVirtualKeyVibePattern; |
| 4949 | break; |
| 4950 | case HapticFeedbackConstants.KEYBOARD_TAP: |
| 4951 | pattern = mKeyboardTapVibePattern; |
| 4952 | break; |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame^] | 4953 | case HapticFeedbackConstants.CLOCK_TICK: |
| 4954 | pattern = mClockTickVibePattern; |
| 4955 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 4956 | case HapticFeedbackConstants.SAFE_MODE_DISABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4957 | pattern = mSafeModeDisabledVibePattern; |
| 4958 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 4959 | case HapticFeedbackConstants.SAFE_MODE_ENABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4960 | pattern = mSafeModeEnabledVibePattern; |
| 4961 | break; |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4962 | default: |
| 4963 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4964 | } |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 4965 | int owningUid; |
| 4966 | String owningPackage; |
| 4967 | if (win != null) { |
| 4968 | owningUid = win.getOwningUid(); |
| 4969 | owningPackage = win.getOwningPackage(); |
| 4970 | } else { |
| 4971 | owningUid = android.os.Process.myUid(); |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 4972 | owningPackage = mContext.getOpPackageName(); |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 4973 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4974 | if (pattern.length == 1) { |
| 4975 | // One-shot vibration |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 4976 | mVibrator.vibrate(owningUid, owningPackage, pattern[0]); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4977 | } else { |
| 4978 | // Pattern vibration |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 4979 | mVibrator.vibrate(owningUid, owningPackage, pattern, -1); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4980 | } |
| 4981 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4982 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4983 | |
| 4984 | @Override |
| 4985 | public void keepScreenOnStartedLw() { |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 4986 | } |
| 4987 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4988 | @Override |
| 4989 | public void keepScreenOnStoppedLw() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4990 | if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotHidden()) { |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4991 | long curTime = SystemClock.uptimeMillis(); |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 4992 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4993 | } |
| 4994 | } |
Mike Lockwood | fcb3924 | 2009-10-21 23:01:07 -0400 | [diff] [blame] | 4995 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4996 | private int updateSystemUiVisibilityLw() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4997 | // If there is no window focused, there will be nobody to handle the events |
| 4998 | // anyway, so just hang on in whatever state we're in until things settle down. |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 4999 | WindowState win = mFocusedWindow != null ? mFocusedWindow : mTopFullscreenOpaqueWindowState; |
| 5000 | if (win == null) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5001 | return 0; |
| 5002 | } |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5003 | if (win.getAttrs().type == TYPE_KEYGUARD && mHideLockScreen == true) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 5004 | // We are updating at a point where the keyguard has gotten |
| 5005 | // focus, but we were last in a state where the top window is |
| 5006 | // hiding it. This is probably because the keyguard as been |
| 5007 | // shown while the top window was displayed, so we want to ignore |
| 5008 | // it here because this is just a very transient change and it |
| 5009 | // will quickly lose focus once it correctly gets hidden. |
| 5010 | return 0; |
| 5011 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 5012 | |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5013 | int tmpVisibility = win.getSystemUiVisibility() |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 5014 | & ~mResettingSystemUiFlags |
| 5015 | & ~mForceClearedSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5016 | if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) { |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 5017 | tmpVisibility &= ~View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 5018 | } |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5019 | final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5020 | final int diff = visibility ^ mLastSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5021 | final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState); |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 5022 | if (diff == 0 && mLastFocusNeedsMenu == needsMenu |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5023 | && mFocusedApp == win.getAppToken()) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5024 | return 0; |
| 5025 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 5026 | mLastSystemUiFlags = visibility; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 5027 | mLastFocusNeedsMenu = needsMenu; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5028 | mFocusedApp = win.getAppToken(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5029 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5030 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5031 | public void run() { |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 5032 | try { |
| 5033 | IStatusBarService statusbar = getStatusBarService(); |
| 5034 | if (statusbar != null) { |
| 5035 | statusbar.setSystemUiVisibility(visibility, 0xffffffff); |
| 5036 | statusbar.topAppWindowChanged(needsMenu); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5037 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 5038 | } catch (RemoteException e) { |
| 5039 | // re-acquire status bar service next time it is needed. |
| 5040 | mStatusBarService = null; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5041 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5042 | } |
| 5043 | }); |
| 5044 | return diff; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5045 | } |
| 5046 | |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5047 | private int updateSystemBarsLw(WindowState win, int oldVis, int vis) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5048 | // prevent status bar interaction from clearing certain flags |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5049 | boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5050 | if (statusBarHasFocus) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5051 | int flags = View.SYSTEM_UI_FLAG_FULLSCREEN |
| 5052 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | cfc359a | 2013-09-05 10:42:03 -0400 | [diff] [blame] | 5053 | | View.SYSTEM_UI_FLAG_IMMERSIVE |
| 5054 | | View.SYSTEM_UI_FLAG_TRANSPARENT_STATUS |
| 5055 | | View.SYSTEM_UI_FLAG_TRANSPARENT_NAVIGATION; |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 5056 | vis = (vis & ~flags) | (mLastSystemUiFlags & flags); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5057 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5058 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5059 | // update status bar |
| 5060 | boolean transientAllowed = |
John Spurlock | e47193d | 2013-08-27 14:23:33 -0400 | [diff] [blame] | 5061 | (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5062 | boolean hideStatusBarWM = |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5063 | (win.getAttrs().flags |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5064 | & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; |
| 5065 | boolean hideStatusBarSysui = |
| 5066 | (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5067 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5068 | boolean transientStatusBarAllowed = |
| 5069 | mStatusBar != null && ( |
| 5070 | hideStatusBarWM |
| 5071 | || (hideStatusBarSysui && transientAllowed) |
| 5072 | || statusBarHasFocus); |
| 5073 | |
| 5074 | if (mStatusBarController.isTransientShowing() |
| 5075 | && !transientStatusBarAllowed && hideStatusBarSysui) { |
| 5076 | // clear the clearable flags instead |
| 5077 | int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 5078 | if (newVal != mResettingSystemUiFlags) { |
| 5079 | mResettingSystemUiFlags = newVal; |
| 5080 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5081 | } |
| 5082 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5083 | |
| 5084 | vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis); |
| 5085 | |
| 5086 | // update navigation bar |
| 5087 | boolean oldTransientNav = isTransientNavigationAllowed(oldVis); |
| 5088 | boolean isTransientNav = isTransientNavigationAllowed(vis); |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5089 | if (win != null && oldTransientNav != isTransientNav) { |
| 5090 | final String pkg = win.getOwningPackage(); |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 5091 | mTransientNavigationConfirmation.transientNavigationChanged(pkg, isTransientNav); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 5092 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5093 | vis = mNavigationBarController.updateVisibilityLw(isTransientNav, oldVis, vis); |
| 5094 | |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 5095 | // don't send low profile updates if the system bars are hidden |
| 5096 | if (mStatusBarController.isHidden() && mNavigationBarController.isHidden()) { |
| 5097 | vis &= ~View.SYSTEM_UI_FLAG_LOW_PROFILE; |
| 5098 | } |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 5099 | return vis; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5100 | } |
| 5101 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5102 | private boolean isTransientNavigationAllowed(int vis) { |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 5103 | return mNavigationBar != null |
| 5104 | && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0 |
John Spurlock | e47193d | 2013-08-27 14:23:33 -0400 | [diff] [blame] | 5105 | && (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 5106 | } |
| 5107 | |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 5108 | // Use this instead of checking config_showNavigationBar so that it can be consistently |
| 5109 | // overridden by qemu.hw.mainkeys in the emulator. |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5110 | @Override |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 5111 | public boolean hasNavigationBar() { |
| 5112 | return mHasNavigationBar; |
| 5113 | } |
| 5114 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 5115 | @Override |
| 5116 | public void setLastInputMethodWindowLw(WindowState ime, WindowState target) { |
| 5117 | mLastInputMethodWindow = ime; |
| 5118 | mLastInputMethodTargetWindow = target; |
| 5119 | } |
| 5120 | |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5121 | @Override |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5122 | public void setCurrentUserLw(int newUserId) { |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 5123 | mCurrentUserId = newUserId; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5124 | if (mKeyguardDelegate != null) { |
| 5125 | mKeyguardDelegate.setCurrentUser(newUserId); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5126 | } |
John Spurlock | 13451a2 | 2012-09-28 14:40:41 -0400 | [diff] [blame] | 5127 | if (mStatusBarService != null) { |
| 5128 | try { |
| 5129 | mStatusBarService.setCurrentUser(newUserId); |
| 5130 | } catch (RemoteException e) { |
| 5131 | // oh well |
| 5132 | } |
| 5133 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 5134 | setLastInputMethodWindowLw(null, null); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5135 | } |
| 5136 | |
| 5137 | @Override |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 5138 | public void showAssistant() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5139 | mKeyguardDelegate.showAssistant(); |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 5140 | } |
| 5141 | |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 5142 | @Override |
| 5143 | public boolean canMagnifyWindow(int windowType) { |
| 5144 | switch (windowType) { |
| 5145 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD: |
| 5146 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG: |
| 5147 | case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR: |
| 5148 | case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: { |
| 5149 | return false; |
| 5150 | } |
| 5151 | } |
| 5152 | return true; |
| 5153 | } |
| 5154 | |
| 5155 | @Override |
| 5156 | public boolean isTopLevelWindow(int windowType) { |
| 5157 | if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW |
| 5158 | && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 5159 | return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG); |
| 5160 | } |
| 5161 | return true; |
| 5162 | } |
| 5163 | |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 5164 | @Override |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 5165 | public void dump(String prefix, PrintWriter pw, String[] args) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5166 | pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5167 | pw.print(" mSystemReady="); pw.print(mSystemReady); |
| 5168 | pw.print(" mSystemBooted="); pw.println(mSystemBooted); |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 5169 | pw.print(prefix); pw.print("mLidState="); pw.print(mLidState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5170 | pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation); |
| 5171 | pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 5172 | if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0 |
| 5173 | || mForceClearedSystemUiFlags != 0) { |
| 5174 | pw.print(prefix); pw.print("mLastSystemUiFlags=0x"); |
| 5175 | pw.print(Integer.toHexString(mLastSystemUiFlags)); |
| 5176 | pw.print(" mResettingSystemUiFlags=0x"); |
| 5177 | pw.print(Integer.toHexString(mResettingSystemUiFlags)); |
| 5178 | pw.print(" mForceClearedSystemUiFlags=0x"); |
| 5179 | pw.println(Integer.toHexString(mForceClearedSystemUiFlags)); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5180 | } |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 5181 | if (mLastFocusNeedsMenu) { |
| 5182 | pw.print(prefix); pw.print("mLastFocusNeedsMenu="); |
| 5183 | pw.println(mLastFocusNeedsMenu); |
| 5184 | } |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5185 | pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode); |
| 5186 | pw.print(" mDockMode="); pw.print(mDockMode); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5187 | pw.print(" mCarDockRotation="); pw.print(mCarDockRotation); |
| 5188 | pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation); |
| 5189 | pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode); |
| 5190 | pw.print(" mUserRotation="); pw.print(mUserRotation); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5191 | pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 5192 | pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5193 | pw.print(prefix); pw.print("mCarDockEnablesAccelerometer="); |
| 5194 | pw.print(mCarDockEnablesAccelerometer); |
| 5195 | pw.print(" mDeskDockEnablesAccelerometer="); |
| 5196 | pw.println(mDeskDockEnablesAccelerometer); |
| 5197 | pw.print(prefix); pw.print("mLidKeyboardAccessibility="); |
| 5198 | pw.print(mLidKeyboardAccessibility); |
| 5199 | pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 5200 | pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep); |
| 5201 | pw.print(prefix); pw.print("mLongPressOnPowerBehavior="); |
| 5202 | pw.print(mLongPressOnPowerBehavior); |
| 5203 | pw.print(" mHasSoftInput="); pw.println(mHasSoftInput); |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 5204 | pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly); |
| 5205 | pw.print(" mScreenOnFully="); pw.print(mScreenOnFully); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 5206 | pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 5207 | pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft); |
| 5208 | pw.print(","); pw.print(mOverscanScreenTop); |
| 5209 | pw.print(") "); pw.print(mOverscanScreenWidth); |
| 5210 | pw.print("x"); pw.println(mOverscanScreenHeight); |
| 5211 | if (mOverscanLeft != 0 || mOverscanTop != 0 |
| 5212 | || mOverscanRight != 0 || mOverscanBottom != 0) { |
| 5213 | pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft); |
| 5214 | pw.print(" top="); pw.print(mOverscanTop); |
| 5215 | pw.print(" right="); pw.print(mOverscanRight); |
| 5216 | pw.print(" bottom="); pw.println(mOverscanBottom); |
| 5217 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 5218 | pw.print(prefix); pw.print("mRestrictedOverscanScreen=("); |
| 5219 | pw.print(mRestrictedOverscanScreenLeft); |
| 5220 | pw.print(","); pw.print(mRestrictedOverscanScreenTop); |
| 5221 | pw.print(") "); pw.print(mRestrictedOverscanScreenWidth); |
| 5222 | pw.print("x"); pw.println(mRestrictedOverscanScreenHeight); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5223 | pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft); |
| 5224 | pw.print(","); pw.print(mUnrestrictedScreenTop); |
| 5225 | pw.print(") "); pw.print(mUnrestrictedScreenWidth); |
| 5226 | pw.print("x"); pw.println(mUnrestrictedScreenHeight); |
| 5227 | pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft); |
| 5228 | pw.print(","); pw.print(mRestrictedScreenTop); |
| 5229 | pw.print(") "); pw.print(mRestrictedScreenWidth); |
| 5230 | pw.print("x"); pw.println(mRestrictedScreenHeight); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 5231 | pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft); |
| 5232 | pw.print(","); pw.print(mStableFullscreenTop); |
| 5233 | pw.print(")-("); pw.print(mStableFullscreenRight); |
| 5234 | pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")"); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5235 | pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft); |
| 5236 | pw.print(","); pw.print(mStableTop); |
| 5237 | pw.print(")-("); pw.print(mStableRight); |
| 5238 | pw.print(","); pw.print(mStableBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 5239 | pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft); |
| 5240 | pw.print(","); pw.print(mSystemTop); |
| 5241 | pw.print(")-("); pw.print(mSystemRight); |
| 5242 | pw.print(","); pw.print(mSystemBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5243 | pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft); |
| 5244 | pw.print(","); pw.print(mCurTop); |
| 5245 | pw.print(")-("); pw.print(mCurRight); |
| 5246 | pw.print(","); pw.print(mCurBottom); pw.println(")"); |
| 5247 | pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft); |
| 5248 | pw.print(","); pw.print(mContentTop); |
| 5249 | pw.print(")-("); pw.print(mContentRight); |
| 5250 | pw.print(","); pw.print(mContentBottom); pw.println(")"); |
| 5251 | pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft); |
| 5252 | pw.print(","); pw.print(mDockTop); |
| 5253 | pw.print(")-("); pw.print(mDockRight); |
| 5254 | pw.print(","); pw.print(mDockBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 5255 | pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer); |
| 5256 | pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer); |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5257 | pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen); |
| 5258 | pw.print(" mShowingDream="); pw.print(mShowingDream); |
| 5259 | pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 5260 | if (mLastInputMethodWindow != null) { |
| 5261 | pw.print(prefix); pw.print("mLastInputMethodWindow="); |
| 5262 | pw.println(mLastInputMethodWindow); |
| 5263 | } |
| 5264 | if (mLastInputMethodTargetWindow != null) { |
| 5265 | pw.print(prefix); pw.print("mLastInputMethodTargetWindow="); |
| 5266 | pw.println(mLastInputMethodTargetWindow); |
| 5267 | } |
| 5268 | if (mStatusBar != null) { |
| 5269 | pw.print(prefix); pw.print("mStatusBar="); |
| 5270 | pw.println(mStatusBar); |
| 5271 | } |
| 5272 | if (mNavigationBar != null) { |
| 5273 | pw.print(prefix); pw.print("mNavigationBar="); |
| 5274 | pw.println(mNavigationBar); |
| 5275 | } |
| 5276 | if (mKeyguard != null) { |
| 5277 | pw.print(prefix); pw.print("mKeyguard="); |
| 5278 | pw.println(mKeyguard); |
| 5279 | } |
| 5280 | if (mFocusedWindow != null) { |
| 5281 | pw.print(prefix); pw.print("mFocusedWindow="); |
| 5282 | pw.println(mFocusedWindow); |
| 5283 | } |
| 5284 | if (mFocusedApp != null) { |
| 5285 | pw.print(prefix); pw.print("mFocusedApp="); |
| 5286 | pw.println(mFocusedApp); |
| 5287 | } |
| 5288 | if (mWinDismissingKeyguard != null) { |
| 5289 | pw.print(prefix); pw.print("mWinDismissingKeyguard="); |
| 5290 | pw.println(mWinDismissingKeyguard); |
| 5291 | } |
| 5292 | if (mTopFullscreenOpaqueWindowState != null) { |
| 5293 | pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState="); |
| 5294 | pw.println(mTopFullscreenOpaqueWindowState); |
| 5295 | } |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 5296 | if (mForcingShowNavBar) { |
| 5297 | pw.print(prefix); pw.print("mForcingShowNavBar="); |
| 5298 | pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer="); |
| 5299 | pw.println(mForcingShowNavBarLayer); |
| 5300 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5301 | pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5302 | pw.print(" mHideLockScreen="); pw.println(mHideLockScreen); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 5303 | pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar); |
| 5304 | pw.print(" mForceStatusBarFromKeyguard="); |
| 5305 | pw.println(mForceStatusBarFromKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5306 | pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 5307 | pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5308 | pw.print(" mHomePressed="); pw.println(mHomePressed); |
| 5309 | pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn); |
| 5310 | pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout); |
| 5311 | pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive); |
| 5312 | pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior); |
| 5313 | pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior); |
| 5314 | pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior); |
| 5315 | pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation); |
| 5316 | pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation); |
| 5317 | pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation); |
| 5318 | pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 5319 | pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation); |
| 5320 | pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock); |
| 5321 | pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5322 | mStatusBarController.dump(pw, prefix); |
| 5323 | mNavigationBarController.dump(pw, prefix); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5324 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5325 | } |