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; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 21 | import android.app.ProgressDialog; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 22 | import android.app.SearchManager; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 23 | import android.app.UiModeManager; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 24 | import android.content.ActivityNotFoundException; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 25 | import android.content.BroadcastReceiver; |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 26 | import android.content.ComponentName; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 27 | import android.content.ContentResolver; |
| 28 | import android.content.Context; |
| 29 | import android.content.Intent; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 30 | import android.content.IntentFilter; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 31 | import android.content.ServiceConnection; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 32 | import android.content.pm.ActivityInfo; |
| 33 | import android.content.pm.PackageManager; |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 34 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 35 | import android.content.res.Configuration; |
| 36 | import android.content.res.Resources; |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 37 | import android.content.res.TypedArray; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 38 | import android.database.ContentObserver; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 39 | import android.graphics.PixelFormat; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 40 | import android.graphics.Rect; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 41 | import android.media.AudioManager; |
| 42 | import android.media.IAudioService; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 43 | import android.media.Ringtone; |
| 44 | import android.media.RingtoneManager; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 45 | import android.os.Bundle; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 46 | import android.os.FactoryTest; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 47 | import android.os.Handler; |
| 48 | import android.os.IBinder; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 49 | import android.os.IRemoteCallback; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 50 | import android.os.Looper; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 51 | import android.os.Message; |
| 52 | import android.os.Messenger; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 53 | import android.os.PowerManager; |
| 54 | import android.os.RemoteException; |
| 55 | import android.os.ServiceManager; |
| 56 | import android.os.SystemClock; |
| 57 | import android.os.SystemProperties; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 58 | import android.os.UEventObserver; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 59 | import android.os.UserHandle; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 60 | import android.os.Vibrator; |
| 61 | import android.provider.Settings; |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 62 | import android.service.dreams.DreamService; |
| 63 | import android.service.dreams.IDreamManager; |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 64 | import android.util.DisplayMetrics; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 65 | import android.util.EventLog; |
| 66 | import android.util.Log; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 67 | import android.util.Slog; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 68 | import android.util.SparseArray; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 69 | import android.view.Display; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 70 | import android.view.Gravity; |
| 71 | import android.view.HapticFeedbackConstants; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 72 | import android.view.IApplicationToken; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 73 | import android.view.IWindowManager; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 74 | import android.view.InputChannel; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 75 | import android.view.InputDevice; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 76 | import android.view.InputEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 77 | import android.view.InputEventReceiver; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 78 | import android.view.KeyCharacterMap; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 79 | import android.view.KeyCharacterMap.FallbackAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 80 | import android.view.KeyEvent; |
| 81 | import android.view.MotionEvent; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 82 | import android.view.Surface; |
| 83 | import android.view.View; |
| 84 | import android.view.ViewConfiguration; |
| 85 | import android.view.Window; |
| 86 | import android.view.WindowManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 87 | import android.view.WindowManagerGlobal; |
| 88 | import android.view.WindowManagerPolicy; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 89 | import android.view.accessibility.AccessibilityEvent; |
| 90 | import android.view.animation.Animation; |
| 91 | import android.view.animation.AnimationUtils; |
| 92 | |
| 93 | import com.android.internal.R; |
| 94 | import com.android.internal.policy.PolicyManager; |
| 95 | import com.android.internal.policy.impl.keyguard.KeyguardViewManager; |
| 96 | import com.android.internal.policy.impl.keyguard.KeyguardViewMediator; |
| 97 | import com.android.internal.statusbar.IStatusBarService; |
| 98 | import com.android.internal.telephony.ITelephony; |
| 99 | import com.android.internal.widget.PointerLocationView; |
| 100 | |
| 101 | import java.io.File; |
| 102 | import java.io.FileReader; |
| 103 | import java.io.IOException; |
| 104 | import java.io.PrintWriter; |
| 105 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 106 | import static android.view.WindowManager.LayoutParams.*; |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 107 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT; |
| 108 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN; |
| 109 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 110 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 111 | /** |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 112 | * WindowManagerPolicy implementation for the Android phone UI. This |
| 113 | * introduces a new method suffix, Lp, for an internal lock of the |
| 114 | * PhoneWindowManager. This is used to protect some internal state, and |
| 115 | * can be acquired with either thw Lw and Li lock held, so has the restrictions |
| 116 | * of both of those when held. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 117 | */ |
| 118 | public class PhoneWindowManager implements WindowManagerPolicy { |
| 119 | static final String TAG = "WindowManager"; |
| 120 | static final boolean DEBUG = false; |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 121 | static final boolean localLOGV = false; |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 122 | static final boolean DEBUG_LAYOUT = false; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 123 | static final boolean DEBUG_INPUT = false; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 124 | static final boolean DEBUG_STARTING_WINDOW = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 125 | static final boolean SHOW_STARTING_ANIMATIONS = true; |
| 126 | static final boolean SHOW_PROCESSES_ON_ALT_MENU = false; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 127 | |
| 128 | static final int LONG_PRESS_POWER_NOTHING = 0; |
| 129 | static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; |
| 130 | static final int LONG_PRESS_POWER_SHUT_OFF = 2; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 131 | static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3; |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 132 | |
| 133 | // These need to match the documentation/constant in |
| 134 | // core/res/res/values/config.xml |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 135 | static final int LONG_PRESS_HOME_NOTHING = 0; |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 136 | static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 137 | |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 138 | static final int APPLICATION_MEDIA_SUBLAYER = -2; |
| 139 | static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 140 | static final int APPLICATION_PANEL_SUBLAYER = 1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 141 | static final int APPLICATION_SUB_PANEL_SUBLAYER = 2; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 142 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 143 | static public final String SYSTEM_DIALOG_REASON_KEY = "reason"; |
| 144 | static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; |
| 145 | static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 146 | static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 147 | static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 148 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 149 | /** |
| 150 | * These are the system UI flags that, when changing, can cause the layout |
| 151 | * of the screen to change. |
| 152 | */ |
| 153 | static final int SYSTEM_UI_CHANGING_LAYOUT = |
| 154 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN; |
| 155 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 156 | /* Table of Application Launch keys. Maps from key codes to intent categories. |
| 157 | * |
| 158 | * These are special keys that are used to launch particular kinds of applications, |
| 159 | * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C) |
| 160 | * usage page. We don't support quite that many yet... |
| 161 | */ |
| 162 | static SparseArray<String> sApplicationLaunchKeyCategories; |
| 163 | static { |
| 164 | sApplicationLaunchKeyCategories = new SparseArray<String>(); |
| 165 | sApplicationLaunchKeyCategories.append( |
| 166 | KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER); |
| 167 | sApplicationLaunchKeyCategories.append( |
| 168 | KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL); |
| 169 | sApplicationLaunchKeyCategories.append( |
| 170 | KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS); |
| 171 | sApplicationLaunchKeyCategories.append( |
| 172 | KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR); |
| 173 | sApplicationLaunchKeyCategories.append( |
| 174 | KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC); |
| 175 | sApplicationLaunchKeyCategories.append( |
| 176 | KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR); |
| 177 | } |
| 178 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 179 | /** |
| 180 | * Lock protecting internal state. Must not call out into window |
| 181 | * manager with lock held. (This lock will be acquired in places |
| 182 | * where the window manager is calling in with its own lock held.) |
| 183 | */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 184 | private final Object mLock = new Object(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 185 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 186 | Context mContext; |
| 187 | IWindowManager mWindowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 188 | WindowManagerFuncs mWindowManagerFuncs; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 189 | PowerManager mPowerManager; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 190 | IStatusBarService mStatusBarService; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 191 | final Object mServiceAquireLock = new Object(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 192 | Vibrator mVibrator; // Vibrator for giving feedback of orientation changes |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 193 | SearchManager mSearchManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 194 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 195 | // Vibrator pattern for haptic feedback of a long press. |
| 196 | long[] mLongPressVibePattern; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 197 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 198 | // Vibrator pattern for haptic feedback of virtual key press. |
| 199 | long[] mVirtualKeyVibePattern; |
| 200 | |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 201 | // Vibrator pattern for a short vibration. |
| 202 | long[] mKeyboardTapVibePattern; |
| 203 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 204 | // Vibrator pattern for haptic feedback during boot when safe mode is disabled. |
| 205 | long[] mSafeModeDisabledVibePattern; |
| 206 | |
| 207 | // Vibrator pattern for haptic feedback during boot when safe mode is enabled. |
| 208 | long[] mSafeModeEnabledVibePattern; |
Romain Guy | 8154cd3 | 2010-03-29 14:41:15 -0700 | [diff] [blame] | 209 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 210 | /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */ |
| 211 | boolean mEnableShiftMenuBugReports = false; |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 212 | |
| 213 | boolean mHeadless; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 214 | boolean mSafeMode; |
| 215 | WindowState mStatusBar = null; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 216 | boolean mHasSystemNavBar; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 217 | int mStatusBarHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 218 | WindowState mNavigationBar = null; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 219 | boolean mHasNavigationBar = false; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 220 | boolean mCanHideNavigationBar = false; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 221 | boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side? |
| 222 | boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*? |
| 223 | int[] mNavigationBarHeightForRotation = new int[4]; |
| 224 | int[] mNavigationBarWidthForRotation = new int[4]; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 225 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 226 | WindowState mKeyguard = null; |
| 227 | KeyguardViewMediator mKeyguardMediator; |
| 228 | GlobalActions mGlobalActions; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 229 | volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread |
| 230 | boolean mPendingPowerKeyUpCanceled; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 231 | Handler mHandler; |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 232 | WindowState mLastInputMethodWindow = null; |
| 233 | WindowState mLastInputMethodTargetWindow = null; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 234 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 235 | static final int RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS = 0; |
| 236 | static final int RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW = 1; |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 237 | static final int RECENT_APPS_BEHAVIOR_DISMISS = 2; |
| 238 | static final int RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH = 3; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 239 | |
| 240 | RecentApplicationsDialog mRecentAppsDialog; |
| 241 | int mRecentAppsDialogHeldModifiers; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 242 | boolean mLanguageSwitchKeyPressed; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 243 | |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 244 | int mLidState = LID_ABSENT; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 245 | boolean mHaveBuiltInKeyboard; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 246 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 247 | boolean mSystemReady; |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 248 | boolean mSystemBooted; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 249 | boolean mHdmiPlugged; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 250 | int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 251 | int mLidOpenRotation; |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 252 | int mCarDockRotation; |
| 253 | int mDeskDockRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 254 | int mHdmiRotation; |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 255 | boolean mHdmiRotationLock; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 256 | |
| 257 | int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE; |
| 258 | int mUserRotation = Surface.ROTATION_0; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 259 | boolean mAccelerometerDefault; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 260 | |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 261 | int mAllowAllRotations = -1; |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 262 | boolean mCarDockEnablesAccelerometer; |
| 263 | boolean mDeskDockEnablesAccelerometer; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 264 | int mLidKeyboardAccessibility; |
| 265 | int mLidNavigationAccessibility; |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 266 | boolean mLidControlsSleep; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 267 | int mLongPressOnPowerBehavior = -1; |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 268 | boolean mScreenOnEarly = false; |
| 269 | boolean mScreenOnFully = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 270 | boolean mOrientationSensorEnabled = false; |
| 271 | int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 272 | boolean mHasSoftInput = false; |
| 273 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 274 | int mPointerLocationMode = 0; // guarded by mLock |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 275 | |
| 276 | // The last window we were told about in focusChanged. |
| 277 | WindowState mFocusedWindow; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 278 | IApplicationToken mFocusedApp; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 279 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 280 | private static final class PointerLocationInputEventReceiver extends InputEventReceiver { |
| 281 | private final PointerLocationView mView; |
| 282 | |
| 283 | public PointerLocationInputEventReceiver(InputChannel inputChannel, Looper looper, |
| 284 | PointerLocationView view) { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 285 | super(inputChannel, looper); |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 286 | mView = view; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 287 | } |
| 288 | |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 289 | @Override |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 290 | public void onInputEvent(InputEvent event) { |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 291 | boolean handled = false; |
| 292 | try { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 293 | if (event instanceof MotionEvent |
| 294 | && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 295 | final MotionEvent motionEvent = (MotionEvent)event; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 296 | mView.addPointerEvent(motionEvent); |
| 297 | handled = true; |
Jeff Brown | 93ed4e3 | 2010-09-23 13:51:48 -0700 | [diff] [blame] | 298 | } |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 299 | } finally { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 300 | finishInputEvent(event, handled); |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 301 | } |
| 302 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 303 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 304 | |
| 305 | // Pointer location view state, only modified on the mHandler Looper. |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 306 | PointerLocationInputEventReceiver mPointerLocationInputEventReceiver; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 307 | PointerLocationView mPointerLocationView; |
| 308 | InputChannel mPointerLocationInputChannel; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 309 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 310 | // The current size of the screen; really; extends into the overscan area of |
| 311 | // the screen and doesn't account for any system elements like the status bar. |
| 312 | int mOverscanScreenLeft, mOverscanScreenTop; |
| 313 | int mOverscanScreenWidth, mOverscanScreenHeight; |
| 314 | // The current visible size of the screen; really; (ir)regardless of whether the status |
| 315 | // bar can be hidden but not extending into the overscan area. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 316 | int mUnrestrictedScreenLeft, mUnrestrictedScreenTop; |
| 317 | int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 318 | // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate. |
| 319 | int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop; |
| 320 | int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight; |
Dianne Hackborn | 82de1ae | 2010-10-28 11:28:39 -0700 | [diff] [blame] | 321 | // The current size of the screen; these may be different than (0,0)-(dw,dh) |
| 322 | // if the status bar can't be hidden; in that case it effectively carves out |
| 323 | // that area of the display from all other windows. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 324 | int mRestrictedScreenLeft, mRestrictedScreenTop; |
| 325 | int mRestrictedScreenWidth, mRestrictedScreenHeight; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 326 | // During layout, the current screen borders accounting for any currently |
| 327 | // visible system UI elements. |
| 328 | int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 329 | // For applications requesting stable content insets, these are them. |
| 330 | int mStableLeft, mStableTop, mStableRight, mStableBottom; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 331 | // For applications requesting stable content insets but have also set the |
| 332 | // fullscreen window flag, these are the stable dimensions without the status bar. |
| 333 | int mStableFullscreenLeft, mStableFullscreenTop; |
| 334 | int mStableFullscreenRight, mStableFullscreenBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 335 | // During layout, the current screen borders with all outer decoration |
| 336 | // (status bar, input method dock) accounted for. |
| 337 | int mCurLeft, mCurTop, mCurRight, mCurBottom; |
| 338 | // During layout, the frame in which content should be displayed |
| 339 | // to the user, accounting for all screen decoration except for any |
| 340 | // space they deem as available for other content. This is usually |
| 341 | // the same as mCur*, but may be larger if the screen decor has supplied |
| 342 | // content insets. |
| 343 | int mContentLeft, mContentTop, mContentRight, mContentBottom; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 344 | // 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] | 345 | // windows are placed. |
| 346 | int mDockLeft, mDockTop, mDockRight, mDockBottom; |
| 347 | // During layout, the layer at which the doc window is placed. |
| 348 | int mDockLayer; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 349 | // During layout, this is the layer of the status bar. |
| 350 | int mStatusBarLayer; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 351 | int mLastSystemUiFlags; |
| 352 | // Bits that we are in the process of clearing, so we want to prevent |
| 353 | // them from being set by applications until everything has been updated |
| 354 | // to have them clear. |
| 355 | int mResettingSystemUiFlags = 0; |
| 356 | // Bits that we are currently always keeping cleared. |
| 357 | int mForceClearedSystemUiFlags = 0; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 358 | // What we last reported to system UI about whether the compatibility |
| 359 | // menu needs to be displayed. |
| 360 | boolean mLastFocusNeedsMenu = false; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 361 | |
| 362 | FakeWindow mHideNavFakeWindow = null; |
| 363 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 364 | static final Rect mTmpParentFrame = new Rect(); |
| 365 | static final Rect mTmpDisplayFrame = new Rect(); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 366 | static final Rect mTmpOverscanFrame = new Rect(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 367 | static final Rect mTmpContentFrame = new Rect(); |
| 368 | static final Rect mTmpVisibleFrame = new Rect(); |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 369 | static final Rect mTmpNavigationFrame = new Rect(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 370 | |
| 371 | WindowState mTopFullscreenOpaqueWindowState; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 372 | boolean mTopIsFullscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 373 | boolean mForceStatusBar; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 374 | boolean mForceStatusBarFromKeyguard; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 375 | boolean mHideLockScreen; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 376 | boolean mForcingShowNavBar; |
| 377 | int mForcingShowNavBarLayer; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 378 | |
| 379 | // States of keyguard dismiss. |
| 380 | private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed. |
| 381 | private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed. |
| 382 | private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed. |
| 383 | int mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
| 384 | |
| 385 | /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only |
| 386 | * be done once per window. */ |
| 387 | private WindowState mWinDismissingKeyguard; |
| 388 | |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 389 | boolean mShowingLockscreen; |
| 390 | boolean mShowingDream; |
| 391 | boolean mDreamingLockscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 392 | boolean mHomePressed; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 393 | boolean mHomeLongPressed; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 394 | Intent mHomeIntent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 395 | Intent mCarDockIntent; |
| 396 | Intent mDeskDockIntent; |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 397 | boolean mSearchKeyShortcutPending; |
| 398 | boolean mConsumeSearchKeyUp; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 399 | boolean mAssistKeyLongPressed; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 400 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 401 | // support for activating the lock screen while the screen is on |
| 402 | boolean mAllowLockscreenWhenOn; |
| 403 | int mLockScreenTimeout; |
| 404 | boolean mLockScreenTimerActive; |
| 405 | |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 406 | // 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] | 407 | int mEndcallBehavior; |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 408 | |
| 409 | // Behavior of POWER button while in-call and screen on. |
| 410 | // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.) |
| 411 | int mIncallPowerBehavior; |
| 412 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 413 | Display mDisplay; |
| 414 | |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 415 | int mLandscapeRotation = 0; // default landscape rotation |
| 416 | int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation |
| 417 | int mPortraitRotation = 0; // default portrait rotation |
| 418 | int mUpsideDownRotation = 0; // "other" portrait rotation |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 419 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 420 | int mOverscanLeft = 0; |
| 421 | int mOverscanTop = 0; |
| 422 | int mOverscanRight = 0; |
| 423 | int mOverscanBottom = 0; |
| 424 | |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 425 | // What we do when the user long presses on home |
| 426 | private int mLongPressOnHomeBehavior = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 427 | |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 428 | // Screenshot trigger states |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 429 | // Time to volume and power must be pressed within this interval of each other. |
| 430 | private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150; |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 431 | // Increase the chord delay when taking a screenshot from the keyguard |
| 432 | private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f; |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 433 | private boolean mScreenshotChordEnabled; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 434 | private boolean mVolumeDownKeyTriggered; |
| 435 | private long mVolumeDownKeyTime; |
| 436 | private boolean mVolumeDownKeyConsumedByScreenshotChord; |
| 437 | private boolean mVolumeUpKeyTriggered; |
| 438 | private boolean mPowerKeyTriggered; |
| 439 | private long mPowerKeyTime; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 440 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 441 | SettingsObserver mSettingsObserver; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 442 | ShortcutManager mShortcutManager; |
| 443 | PowerManager.WakeLock mBroadcastWakeLock; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 444 | boolean mHavePendingMediaKeyRepeatWithWakeLock; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 445 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 446 | // Maps global key codes to the components that will handle them. |
| 447 | private GlobalKeyManager mGlobalKeyManager; |
| 448 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 449 | // Fallback actions by key code. |
| 450 | private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions = |
| 451 | new SparseArray<KeyCharacterMap.FallbackAction>(); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 452 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 453 | private static final int MSG_ENABLE_POINTER_LOCATION = 1; |
| 454 | private static final int MSG_DISABLE_POINTER_LOCATION = 2; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 455 | private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3; |
| 456 | 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] | 457 | |
| 458 | private class PolicyHandler extends Handler { |
| 459 | @Override |
| 460 | public void handleMessage(Message msg) { |
| 461 | switch (msg.what) { |
| 462 | case MSG_ENABLE_POINTER_LOCATION: |
| 463 | enablePointerLocation(); |
| 464 | break; |
| 465 | case MSG_DISABLE_POINTER_LOCATION: |
| 466 | disablePointerLocation(); |
| 467 | break; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 468 | case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK: |
| 469 | dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj); |
| 470 | break; |
| 471 | case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK: |
| 472 | dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj); |
| 473 | break; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 474 | } |
| 475 | } |
| 476 | } |
| 477 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 478 | private UEventObserver mHDMIObserver = new UEventObserver() { |
| 479 | @Override |
| 480 | public void onUEvent(UEventObserver.UEvent event) { |
| 481 | setHdmiPlugged("1".equals(event.get("SWITCH_STATE"))); |
| 482 | } |
| 483 | }; |
| 484 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 485 | class SettingsObserver extends ContentObserver { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 486 | SettingsObserver(Handler handler) { |
| 487 | super(handler); |
| 488 | } |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 489 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 490 | void observe() { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 491 | // Observe all users' changes |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 492 | ContentResolver resolver = mContext.getContentResolver(); |
| 493 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 494 | Settings.System.END_BUTTON_BEHAVIOR), false, this, |
| 495 | UserHandle.USER_ALL); |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 496 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 497 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this, |
| 498 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 499 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 500 | Settings.System.ACCELEROMETER_ROTATION), false, this, |
| 501 | UserHandle.USER_ALL); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 502 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 503 | Settings.System.USER_ROTATION), false, this, |
| 504 | UserHandle.USER_ALL); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 505 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 506 | Settings.System.SCREEN_OFF_TIMEOUT), false, this, |
| 507 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 508 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 509 | Settings.System.POINTER_LOCATION), false, this, |
| 510 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 511 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 512 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this, |
| 513 | UserHandle.USER_ALL); |
Dianne Hackborn | 03759ed | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 514 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 515 | "fancy_rotation_anim"), false, this, |
| 516 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 517 | updateSettings(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | @Override public void onChange(boolean selfChange) { |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 521 | updateSettings(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 522 | updateRotation(false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 523 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | class MyOrientationListener extends WindowOrientationListener { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 527 | MyOrientationListener(Context context, Handler handler) { |
| 528 | super(context, handler); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | @Override |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 532 | public void onProposedRotationChanged(int rotation) { |
| 533 | if (localLOGV) Log.v(TAG, "onProposedRotationChanged, rotation=" + rotation); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 534 | updateRotation(false); |
| 535 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 536 | } |
| 537 | MyOrientationListener mOrientationListener; |
| 538 | |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 539 | IStatusBarService getStatusBarService() { |
| 540 | synchronized (mServiceAquireLock) { |
| 541 | if (mStatusBarService == null) { |
| 542 | mStatusBarService = IStatusBarService.Stub.asInterface( |
| 543 | ServiceManager.getService("statusbar")); |
| 544 | } |
| 545 | return mStatusBarService; |
| 546 | } |
| 547 | } |
| 548 | |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 549 | /* |
| 550 | * We always let the sensor be switched on by default except when |
| 551 | * the user has explicitly disabled sensor based rotation or when the |
| 552 | * screen is switched off. |
| 553 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 554 | boolean needSensorRunningLp() { |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 555 | if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 556 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 557 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT |
| 558 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 559 | // If the application has explicitly requested to follow the |
| 560 | // orientation, then we need to turn the sensor or. |
| 561 | return true; |
| 562 | } |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 563 | if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) || |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 564 | (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 565 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 566 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) { |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 567 | // enable accelerometer if we are docked in a dock that enables accelerometer |
| 568 | // orientation management, |
| 569 | return true; |
| 570 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 571 | if (mUserRotationMode == USER_ROTATION_LOCKED) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 572 | // If the setting for using the sensor by default is enabled, then |
| 573 | // we will always leave it on. Note that the user could go to |
| 574 | // a window that forces an orientation that does not use the |
| 575 | // sensor and in theory we could turn it off... however, when next |
| 576 | // turning it on we won't have a good value for the current |
| 577 | // orientation for a little bit, which can cause orientation |
| 578 | // changes to lag, so we'd like to keep it always on. (It will |
| 579 | // still be turned off when the screen is off.) |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 580 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 581 | } |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 582 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | /* |
| 586 | * Various use cases for invoking this function |
| 587 | * screen turning off, should always disable listeners if already enabled |
| 588 | * screen turned on and current app has sensor based orientation, enable listeners |
| 589 | * if not already enabled |
| 590 | * screen turned on and current app does not have sensor orientation, disable listeners if |
| 591 | * already enabled |
| 592 | * screen turning on and current app has sensor based orientation, enable listeners if needed |
| 593 | * screen turning on and current app has nosensor based orientation, do nothing |
| 594 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 595 | void updateOrientationListenerLp() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 596 | if (!mOrientationListener.canDetectOrientation()) { |
| 597 | // If sensor is turned off or nonexistent for some reason |
| 598 | return; |
| 599 | } |
| 600 | //Could have been invoked due to screen turning on or off or |
| 601 | //change of the currently visible window's orientation |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 602 | if (localLOGV) Log.v(TAG, "Screen status="+mScreenOnEarly+ |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 603 | ", current orientation="+mCurrentAppOrientation+ |
| 604 | ", SensorEnabled="+mOrientationSensorEnabled); |
| 605 | boolean disable = true; |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 606 | if (mScreenOnEarly) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 607 | if (needSensorRunningLp()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 608 | disable = false; |
| 609 | //enable listener if not already enabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 610 | if (!mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 611 | mOrientationListener.enable(); |
Dianne Hackborn | 0572658 | 2009-09-22 17:28:24 -0700 | [diff] [blame] | 612 | if(localLOGV) Log.v(TAG, "Enabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 613 | mOrientationSensorEnabled = true; |
| 614 | } |
| 615 | } |
| 616 | } |
| 617 | //check if sensors need to be disabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 618 | if (disable && mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 619 | mOrientationListener.disable(); |
Dianne Hackborn | 0572658 | 2009-09-22 17:28:24 -0700 | [diff] [blame] | 620 | if(localLOGV) Log.v(TAG, "Disabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 621 | mOrientationSensorEnabled = false; |
| 622 | } |
| 623 | } |
| 624 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 625 | private void interceptPowerKeyDown(boolean handled) { |
| 626 | mPowerKeyHandled = handled; |
| 627 | if (!handled) { |
| 628 | mHandler.postDelayed(mPowerLongPress, ViewConfiguration.getGlobalActionKeyTimeout()); |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | private boolean interceptPowerKeyUp(boolean canceled) { |
| 633 | if (!mPowerKeyHandled) { |
| 634 | mHandler.removeCallbacks(mPowerLongPress); |
| 635 | return !canceled; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 636 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 637 | return false; |
| 638 | } |
| 639 | |
| 640 | private void cancelPendingPowerKeyAction() { |
| 641 | if (!mPowerKeyHandled) { |
| 642 | mHandler.removeCallbacks(mPowerLongPress); |
| 643 | } |
Jeff Brown | ff20471 | 2011-10-25 21:27:54 -0700 | [diff] [blame] | 644 | if (mPowerKeyTriggered) { |
| 645 | mPendingPowerKeyUpCanceled = true; |
| 646 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | private void interceptScreenshotChord() { |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 650 | if (mScreenshotChordEnabled |
| 651 | && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 652 | final long now = SystemClock.uptimeMillis(); |
| 653 | if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS |
| 654 | && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { |
| 655 | mVolumeDownKeyConsumedByScreenshotChord = true; |
| 656 | cancelPendingPowerKeyAction(); |
| 657 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 658 | mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay()); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 659 | } |
| 660 | } |
| 661 | } |
| 662 | |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 663 | private long getScreenshotChordLongPressDelay() { |
| 664 | if (mKeyguardMediator.isShowing()) { |
| 665 | // Double the time it takes to take a screenshot from the keyguard |
| 666 | return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER * |
| 667 | ViewConfiguration.getGlobalActionKeyTimeout()); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 668 | } |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 669 | return ViewConfiguration.getGlobalActionKeyTimeout(); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 670 | } |
| 671 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 672 | private void cancelPendingScreenshotChordAction() { |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 673 | mHandler.removeCallbacks(mScreenshotRunnable); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | private final Runnable mPowerLongPress = new Runnable() { |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 677 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 678 | public void run() { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 679 | // The context isn't read |
| 680 | if (mLongPressOnPowerBehavior < 0) { |
Jeff Brown | 850c5b7 | 2012-10-01 15:17:22 -0700 | [diff] [blame] | 681 | mLongPressOnPowerBehavior = mContext.getResources().getInteger( |
| 682 | com.android.internal.R.integer.config_longPressOnPowerBehavior); |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 683 | } |
Jeff Brown | 850c5b7 | 2012-10-01 15:17:22 -0700 | [diff] [blame] | 684 | int resolvedBehavior = mLongPressOnPowerBehavior; |
| 685 | if (FactoryTest.isLongPressOnPowerOffEnabled()) { |
| 686 | resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM; |
| 687 | } |
| 688 | |
| 689 | switch (resolvedBehavior) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 690 | case LONG_PRESS_POWER_NOTHING: |
| 691 | break; |
| 692 | case LONG_PRESS_POWER_GLOBAL_ACTIONS: |
| 693 | mPowerKeyHandled = true; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 694 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 695 | performAuditoryFeedbackForAccessibilityIfNeed(); |
| 696 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 697 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
| 698 | showGlobalActionsDialog(); |
| 699 | break; |
| 700 | case LONG_PRESS_POWER_SHUT_OFF: |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 701 | case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM: |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 702 | mPowerKeyHandled = true; |
| 703 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 704 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
Jeff Brown | 850c5b7 | 2012-10-01 15:17:22 -0700 | [diff] [blame] | 705 | mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 706 | break; |
| 707 | } |
| 708 | } |
| 709 | }; |
| 710 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 711 | private final Runnable mScreenshotRunnable = new Runnable() { |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 712 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 713 | public void run() { |
| 714 | takeScreenshot(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 715 | } |
| 716 | }; |
| 717 | |
| 718 | void showGlobalActionsDialog() { |
| 719 | if (mGlobalActions == null) { |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 720 | mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 721 | } |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 722 | final boolean keyguardShowing = keyguardIsShowingTq(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 723 | mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned()); |
| 724 | if (keyguardShowing) { |
| 725 | // since it took two seconds of long press to bring this up, |
| 726 | // poke the wake lock so they have some time to see the dialog. |
Jeff Brown | 3dc524b | 2012-09-30 19:49:11 -0700 | [diff] [blame] | 727 | mKeyguardMediator.userActivity(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 728 | } |
| 729 | } |
| 730 | |
| 731 | boolean isDeviceProvisioned() { |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 732 | return Settings.Global.getInt( |
| 733 | mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 734 | } |
| 735 | |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 736 | private void handleLongPressOnHome() { |
Jim Miller | ee969aa | 2010-08-26 20:17:43 -0700 | [diff] [blame] | 737 | // We can't initialize this in init() since the configuration hasn't been loaded yet. |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 738 | if (mLongPressOnHomeBehavior < 0) { |
| 739 | mLongPressOnHomeBehavior |
Joe Onorato | 50262e5 | 2010-11-26 14:04:54 -0800 | [diff] [blame] | 740 | = mContext.getResources().getInteger(R.integer.config_longPressOnHomeBehavior); |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 741 | if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING || |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 742 | mLongPressOnHomeBehavior > LONG_PRESS_HOME_RECENT_SYSTEM_UI) { |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 743 | mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) { |
| 748 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 749 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS); |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 750 | |
| 751 | // Eat the longpress so it won't dismiss the recent apps dialog when |
| 752 | // the user lets go of the home key |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 753 | mHomeLongPressed = true; |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 754 | try { |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 755 | IStatusBarService statusbar = getStatusBarService(); |
| 756 | if (statusbar != null) { |
| 757 | statusbar.toggleRecentApps(); |
| 758 | } |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 759 | } catch (RemoteException e) { |
| 760 | Slog.e(TAG, "RemoteException when showing recent apps", e); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 761 | // re-acquire status bar service next time it is needed. |
| 762 | mStatusBarService = null; |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 763 | } |
| 764 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 765 | } |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 766 | |
| 767 | /** |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 768 | * Create (if necessary) and show or dismiss the recent apps dialog according |
| 769 | * according to the requested behavior. |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 770 | */ |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 771 | void showOrHideRecentAppsDialog(final int behavior) { |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 772 | mHandler.post(new Runnable() { |
| 773 | @Override |
| 774 | public void run() { |
| 775 | if (mRecentAppsDialog == null) { |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 776 | mRecentAppsDialog = new RecentApplicationsDialog(mContext); |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 777 | } |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 778 | if (mRecentAppsDialog.isShowing()) { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 779 | switch (behavior) { |
| 780 | case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS: |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 781 | case RECENT_APPS_BEHAVIOR_DISMISS: |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 782 | mRecentAppsDialog.dismiss(); |
| 783 | break; |
| 784 | case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH: |
| 785 | mRecentAppsDialog.dismissAndSwitch(); |
| 786 | break; |
| 787 | case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW: |
| 788 | default: |
| 789 | break; |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 790 | } |
| 791 | } else { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 792 | switch (behavior) { |
| 793 | case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS: |
| 794 | mRecentAppsDialog.show(); |
| 795 | break; |
| 796 | case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW: |
| 797 | try { |
| 798 | mWindowManager.setInTouchMode(false); |
| 799 | } catch (RemoteException e) { |
| 800 | } |
| 801 | mRecentAppsDialog.show(); |
| 802 | break; |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 803 | case RECENT_APPS_BEHAVIOR_DISMISS: |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 804 | case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH: |
| 805 | default: |
| 806 | break; |
| 807 | } |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 808 | } |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 809 | } |
| 810 | }); |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 811 | } |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 812 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 813 | /** {@inheritDoc} */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 814 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 815 | public void init(Context context, IWindowManager windowManager, |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 816 | WindowManagerFuncs windowManagerFuncs) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 817 | mContext = context; |
| 818 | mWindowManager = windowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 819 | mWindowManagerFuncs = windowManagerFuncs; |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 820 | mHeadless = "1".equals(SystemProperties.get("ro.config.headless", "0")); |
| 821 | if (!mHeadless) { |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 822 | // don't create KeyguardViewMediator if headless |
Jim Miller | 9c7e630 | 2012-08-29 13:48:34 -0700 | [diff] [blame] | 823 | mKeyguardMediator = new KeyguardViewMediator(context, null); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 824 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 825 | mHandler = new PolicyHandler(); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 826 | mOrientationListener = new MyOrientationListener(mContext, mHandler); |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 827 | try { |
| 828 | mOrientationListener.setCurrentRotation(windowManager.getRotation()); |
| 829 | } catch (RemoteException ex) { } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 830 | mSettingsObserver = new SettingsObserver(mHandler); |
| 831 | mSettingsObserver.observe(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 832 | mShortcutManager = new ShortcutManager(context, mHandler); |
| 833 | mShortcutManager.observe(); |
| 834 | mHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 835 | mHomeIntent.addCategory(Intent.CATEGORY_HOME); |
| 836 | mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 837 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 838 | mCarDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 839 | mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK); |
| 840 | mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 841 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 842 | mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 843 | mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK); |
| 844 | mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 845 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 846 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 847 | mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 848 | mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 849 | "PhoneWindowManager.mBroadcastWakeLock"); |
| 850 | mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable")); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 851 | mLidOpenRotation = readRotation( |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 852 | com.android.internal.R.integer.config_lidOpenRotation); |
| 853 | mCarDockRotation = readRotation( |
| 854 | com.android.internal.R.integer.config_carDockRotation); |
| 855 | mDeskDockRotation = readRotation( |
| 856 | com.android.internal.R.integer.config_deskDockRotation); |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 857 | mCarDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 858 | com.android.internal.R.bool.config_carDockEnablesAccelerometer); |
| 859 | mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 860 | com.android.internal.R.bool.config_deskDockEnablesAccelerometer); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 861 | mLidKeyboardAccessibility = mContext.getResources().getInteger( |
| 862 | com.android.internal.R.integer.config_lidKeyboardAccessibility); |
| 863 | mLidNavigationAccessibility = mContext.getResources().getInteger( |
| 864 | com.android.internal.R.integer.config_lidNavigationAccessibility); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 865 | mLidControlsSleep = mContext.getResources().getBoolean( |
| 866 | com.android.internal.R.bool.config_lidControlsSleep); |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 867 | // register for dock events |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 868 | IntentFilter filter = new IntentFilter(); |
| 869 | filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE); |
| 870 | filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE); |
| 871 | filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE); |
| 872 | filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 873 | filter.addAction(Intent.ACTION_DOCK_EVENT); |
| 874 | Intent intent = context.registerReceiver(mDockReceiver, filter); |
| 875 | if (intent != null) { |
| 876 | // Retrieve current sticky dock event broadcast. |
| 877 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 878 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
| 879 | } |
Daniel Sandler | 7e37df5 | 2011-11-16 22:08:23 -0800 | [diff] [blame] | 880 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 881 | // register for dream-related broadcasts |
| 882 | filter = new IntentFilter(); |
| 883 | filter.addAction(Intent.ACTION_DREAMING_STARTED); |
| 884 | filter.addAction(Intent.ACTION_DREAMING_STOPPED); |
| 885 | context.registerReceiver(mDreamReceiver, filter); |
| 886 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 887 | // register for multiuser-relevant broadcasts |
| 888 | filter = new IntentFilter(Intent.ACTION_USER_SWITCHED); |
| 889 | context.registerReceiver(mMultiuserReceiver, filter); |
| 890 | |
Jeff Brown | c234613 | 2012-04-13 01:55:38 -0700 | [diff] [blame] | 891 | mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 892 | mLongPressVibePattern = getLongIntArray(mContext.getResources(), |
| 893 | com.android.internal.R.array.config_longPressVibePattern); |
| 894 | mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(), |
| 895 | com.android.internal.R.array.config_virtualKeyVibePattern); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 896 | mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(), |
| 897 | com.android.internal.R.array.config_keyboardTapVibePattern); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 898 | mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(), |
| 899 | com.android.internal.R.array.config_safeModeDisabledVibePattern); |
| 900 | mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), |
| 901 | com.android.internal.R.array.config_safeModeEnabledVibePattern); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 902 | |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 903 | mScreenshotChordEnabled = mContext.getResources().getBoolean( |
| 904 | com.android.internal.R.bool.config_enableScreenshotChord); |
| 905 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 906 | mGlobalKeyManager = new GlobalKeyManager(mContext); |
| 907 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 908 | // Controls rotation and the like. |
| 909 | initializeHdmiState(); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 910 | |
| 911 | // Match current screen state. |
| 912 | if (mPowerManager.isScreenOn()) { |
| 913 | screenTurningOn(null); |
| 914 | } else { |
| 915 | screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 916 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 917 | } |
| 918 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 919 | @Override |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 920 | public void setInitialDisplaySize(Display display, int width, int height, int density) { |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 921 | if (display.getDisplayId() != Display.DEFAULT_DISPLAY) { |
| 922 | throw new IllegalArgumentException("Can only set the default display"); |
| 923 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 924 | mDisplay = display; |
| 925 | |
| 926 | int shortSize, longSize; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 927 | if (width > height) { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 928 | shortSize = height; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 929 | longSize = width; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 930 | mLandscapeRotation = Surface.ROTATION_0; |
| 931 | mSeascapeRotation = Surface.ROTATION_180; |
| 932 | if (mContext.getResources().getBoolean( |
| 933 | com.android.internal.R.bool.config_reverseDefaultRotation)) { |
| 934 | mPortraitRotation = Surface.ROTATION_90; |
| 935 | mUpsideDownRotation = Surface.ROTATION_270; |
| 936 | } else { |
| 937 | mPortraitRotation = Surface.ROTATION_270; |
| 938 | mUpsideDownRotation = Surface.ROTATION_90; |
| 939 | } |
| 940 | } else { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 941 | shortSize = width; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 942 | longSize = height; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 943 | mPortraitRotation = Surface.ROTATION_0; |
| 944 | mUpsideDownRotation = Surface.ROTATION_180; |
| 945 | if (mContext.getResources().getBoolean( |
| 946 | com.android.internal.R.bool.config_reverseDefaultRotation)) { |
| 947 | mLandscapeRotation = Surface.ROTATION_270; |
| 948 | mSeascapeRotation = Surface.ROTATION_90; |
| 949 | } else { |
| 950 | mLandscapeRotation = Surface.ROTATION_90; |
| 951 | mSeascapeRotation = Surface.ROTATION_270; |
| 952 | } |
| 953 | } |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 954 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 955 | mStatusBarHeight = mContext.getResources().getDimensionPixelSize( |
| 956 | com.android.internal.R.dimen.status_bar_height); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 957 | |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 958 | // Height of the navigation bar when presented horizontally at bottom |
| 959 | mNavigationBarHeightForRotation[mPortraitRotation] = |
| 960 | mNavigationBarHeightForRotation[mUpsideDownRotation] = |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 961 | mContext.getResources().getDimensionPixelSize( |
| 962 | com.android.internal.R.dimen.navigation_bar_height); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 963 | mNavigationBarHeightForRotation[mLandscapeRotation] = |
| 964 | mNavigationBarHeightForRotation[mSeascapeRotation] = |
| 965 | mContext.getResources().getDimensionPixelSize( |
| 966 | com.android.internal.R.dimen.navigation_bar_height_landscape); |
| 967 | |
| 968 | // Width of the navigation bar when presented vertically along one side |
| 969 | mNavigationBarWidthForRotation[mPortraitRotation] = |
| 970 | mNavigationBarWidthForRotation[mUpsideDownRotation] = |
| 971 | mNavigationBarWidthForRotation[mLandscapeRotation] = |
| 972 | mNavigationBarWidthForRotation[mSeascapeRotation] = |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 973 | mContext.getResources().getDimensionPixelSize( |
| 974 | com.android.internal.R.dimen.navigation_bar_width); |
| 975 | |
| 976 | // SystemUI (status bar) layout policy |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 977 | int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 978 | |
| 979 | if (shortSizeDp < 600) { |
| 980 | // 0-599dp: "phone" UI with a separate status & navigation bar |
| 981 | mHasSystemNavBar = false; |
| 982 | mNavigationBarCanMove = true; |
| 983 | } else if (shortSizeDp < 720) { |
Daniel Sandler | ef86370 | 2012-07-11 10:03:34 -0400 | [diff] [blame] | 984 | // 600+dp: "phone" UI with modifications for larger screens |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 985 | mHasSystemNavBar = false; |
| 986 | mNavigationBarCanMove = false; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 987 | } |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 988 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 989 | if (!mHasSystemNavBar) { |
| 990 | mHasNavigationBar = mContext.getResources().getBoolean( |
| 991 | com.android.internal.R.bool.config_showNavigationBar); |
| 992 | // Allow a system property to override this. Used by the emulator. |
| 993 | // See also hasNavigationBar(). |
| 994 | String navBarOverride = SystemProperties.get("qemu.hw.mainkeys"); |
| 995 | if (! "".equals(navBarOverride)) { |
| 996 | if (navBarOverride.equals("1")) mHasNavigationBar = false; |
| 997 | else if (navBarOverride.equals("0")) mHasNavigationBar = true; |
| 998 | } |
| 999 | } else { |
| 1000 | mHasNavigationBar = false; |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 1001 | } |
| 1002 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1003 | if (mHasSystemNavBar) { |
| 1004 | // The system bar is always at the bottom. If you are watching |
| 1005 | // a video in landscape, we don't need to hide it if we can still |
| 1006 | // show a 16:9 aspect ratio with it. |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1007 | int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1008 | int barHeightDp = mNavigationBarHeightForRotation[mLandscapeRotation] |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1009 | * DisplayMetrics.DENSITY_DEFAULT / density; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1010 | int aspect = ((shortSizeDp-barHeightDp) * 16) / longSizeDp; |
| 1011 | // We have computed the aspect ratio with the bar height taken |
| 1012 | // out to be 16:aspect. If this is less than 9, then hiding |
| 1013 | // the navigation bar will provide more useful space for wide |
| 1014 | // screen movies. |
| 1015 | mCanHideNavigationBar = aspect < 9; |
| 1016 | } else if (mHasNavigationBar) { |
| 1017 | // The navigation bar is at the right in landscape; it seems always |
| 1018 | // useful to hide it for showing a video. |
| 1019 | mCanHideNavigationBar = true; |
| 1020 | } else { |
| 1021 | mCanHideNavigationBar = false; |
| 1022 | } |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1023 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 1024 | // For demo purposes, allow the rotation of the HDMI display to be controlled. |
| 1025 | // By default, HDMI locks rotation to landscape. |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1026 | if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) { |
| 1027 | mHdmiRotation = mPortraitRotation; |
| 1028 | } else { |
| 1029 | mHdmiRotation = mLandscapeRotation; |
| 1030 | } |
Jeff Brown | 74bea06 | 2012-10-25 12:16:10 -0700 | [diff] [blame] | 1031 | mHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false); |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1032 | } |
| 1033 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1034 | @Override |
| 1035 | public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) { |
| 1036 | if (display.getDisplayId() == Display.DEFAULT_DISPLAY) { |
| 1037 | mOverscanLeft = left; |
| 1038 | mOverscanTop = top; |
| 1039 | mOverscanRight = right; |
| 1040 | mOverscanBottom = bottom; |
| 1041 | } |
| 1042 | } |
| 1043 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1044 | public void updateSettings() { |
| 1045 | ContentResolver resolver = mContext.getContentResolver(); |
| 1046 | boolean updateRotation = false; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1047 | synchronized (mLock) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1048 | mEndcallBehavior = Settings.System.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1049 | Settings.System.END_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1050 | Settings.System.END_BUTTON_BEHAVIOR_DEFAULT, |
| 1051 | UserHandle.USER_CURRENT); |
| 1052 | mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1053 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1054 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT, |
| 1055 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1056 | |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1057 | // Configure rotation lock. |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1058 | int userRotation = Settings.System.getIntForUser(resolver, |
| 1059 | Settings.System.USER_ROTATION, Surface.ROTATION_0, |
| 1060 | UserHandle.USER_CURRENT); |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1061 | if (mUserRotation != userRotation) { |
| 1062 | mUserRotation = userRotation; |
| 1063 | updateRotation = true; |
| 1064 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1065 | int userRotationMode = Settings.System.getIntForUser(resolver, |
| 1066 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1067 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 1068 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
| 1069 | if (mUserRotationMode != userRotationMode) { |
| 1070 | mUserRotationMode = userRotationMode; |
| 1071 | updateRotation = true; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1072 | updateOrientationListenerLp(); |
| 1073 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1074 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1075 | if (mSystemReady) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1076 | int pointerLocation = Settings.System.getIntForUser(resolver, |
| 1077 | Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1078 | if (mPointerLocationMode != pointerLocation) { |
| 1079 | mPointerLocationMode = pointerLocation; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1080 | mHandler.sendEmptyMessage(pointerLocation != 0 ? |
| 1081 | MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1082 | } |
| 1083 | } |
| 1084 | // use screen off timeout setting as the timeout for the lockscreen |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1085 | mLockScreenTimeout = Settings.System.getIntForUser(resolver, |
| 1086 | Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT); |
| 1087 | String imId = Settings.Secure.getStringForUser(resolver, |
| 1088 | Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1089 | boolean hasSoftInput = imId != null && imId.length() > 0; |
| 1090 | if (mHasSoftInput != hasSoftInput) { |
| 1091 | mHasSoftInput = hasSoftInput; |
| 1092 | updateRotation = true; |
| 1093 | } |
| 1094 | } |
| 1095 | if (updateRotation) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 1096 | updateRotation(true); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1097 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | private void enablePointerLocation() { |
| 1101 | if (mPointerLocationView == null) { |
| 1102 | mPointerLocationView = new PointerLocationView(mContext); |
| 1103 | mPointerLocationView.setPrintCoords(false); |
| 1104 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1105 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 1106 | WindowManager.LayoutParams.MATCH_PARENT, |
| 1107 | WindowManager.LayoutParams.MATCH_PARENT); |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1108 | lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1109 | lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 1110 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
| 1111 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1112 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
Jeff Brown | 90fc905 | 2012-10-01 14:44:24 -0700 | [diff] [blame] | 1113 | if (ActivityManager.isHighEndGfx()) { |
| 1114 | lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 1115 | lp.privateFlags |= |
| 1116 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED; |
| 1117 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1118 | lp.format = PixelFormat.TRANSLUCENT; |
| 1119 | lp.setTitle("PointerLocation"); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1120 | WindowManager wm = (WindowManager) |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1121 | mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1122 | lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1123 | wm.addView(mPointerLocationView, lp); |
| 1124 | |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 1125 | mPointerLocationInputChannel = |
| 1126 | mWindowManagerFuncs.monitorInput("PointerLocationView"); |
| 1127 | mPointerLocationInputEventReceiver = |
| 1128 | new PointerLocationInputEventReceiver(mPointerLocationInputChannel, |
| 1129 | Looper.myLooper(), mPointerLocationView); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1130 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1131 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1132 | |
| 1133 | private void disablePointerLocation() { |
| 1134 | if (mPointerLocationInputEventReceiver != null) { |
| 1135 | mPointerLocationInputEventReceiver.dispose(); |
| 1136 | mPointerLocationInputEventReceiver = null; |
| 1137 | } |
| 1138 | |
| 1139 | if (mPointerLocationInputChannel != null) { |
| 1140 | mPointerLocationInputChannel.dispose(); |
| 1141 | mPointerLocationInputChannel = null; |
| 1142 | } |
| 1143 | |
| 1144 | if (mPointerLocationView != null) { |
| 1145 | WindowManager wm = (WindowManager) |
| 1146 | mContext.getSystemService(Context.WINDOW_SERVICE); |
| 1147 | wm.removeView(mPointerLocationView); |
| 1148 | mPointerLocationView = null; |
| 1149 | } |
| 1150 | } |
| 1151 | |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1152 | private int readRotation(int resID) { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1153 | try { |
| 1154 | int rotation = mContext.getResources().getInteger(resID); |
| 1155 | switch (rotation) { |
| 1156 | case 0: |
| 1157 | return Surface.ROTATION_0; |
| 1158 | case 90: |
| 1159 | return Surface.ROTATION_90; |
| 1160 | case 180: |
| 1161 | return Surface.ROTATION_180; |
| 1162 | case 270: |
| 1163 | return Surface.ROTATION_270; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1164 | } |
| 1165 | } catch (Resources.NotFoundException e) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1166 | // fall through |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1167 | } |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1168 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | /** {@inheritDoc} */ |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1172 | @Override |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1173 | public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1174 | int type = attrs.type; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1175 | |
| 1176 | outAppOp[0] = AppOpsManager.OP_NONE; |
| 1177 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1178 | if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW |
| 1179 | || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1180 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1181 | } |
| 1182 | String permission = null; |
| 1183 | switch (type) { |
| 1184 | case TYPE_TOAST: |
| 1185 | // XXX right now the app process has complete control over |
| 1186 | // this... should introduce a token to let the system |
| 1187 | // monitor/control what they are doing. |
| 1188 | break; |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 1189 | case TYPE_DREAM: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1190 | case TYPE_INPUT_METHOD: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1191 | case TYPE_WALLPAPER: |
| 1192 | // The window manager will check these. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1193 | break; |
| 1194 | case TYPE_PHONE: |
| 1195 | case TYPE_PRIORITY_PHONE: |
| 1196 | case TYPE_SYSTEM_ALERT: |
| 1197 | case TYPE_SYSTEM_ERROR: |
| 1198 | case TYPE_SYSTEM_OVERLAY: |
| 1199 | permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1200 | outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1201 | break; |
| 1202 | default: |
| 1203 | permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
| 1204 | } |
| 1205 | if (permission != null) { |
| 1206 | if (mContext.checkCallingOrSelfPermission(permission) |
| 1207 | != PackageManager.PERMISSION_GRANTED) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1208 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1209 | } |
| 1210 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1211 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1212 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1213 | |
| 1214 | @Override |
| 1215 | public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) { |
| 1216 | |
| 1217 | // If this switch statement is modified, modify the comment in the declarations of |
| 1218 | // the type in {@link WindowManager.LayoutParams} as well. |
| 1219 | switch (attrs.type) { |
| 1220 | default: |
| 1221 | // These are the windows that by default are shown only to the user that created |
| 1222 | // them. If this needs to be overridden, set |
| 1223 | // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in |
| 1224 | // {@link WindowManager.LayoutParams}. Note that permission |
| 1225 | // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well. |
| 1226 | if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) { |
| 1227 | return true; |
| 1228 | } |
| 1229 | break; |
| 1230 | |
| 1231 | // These are the windows that by default are shown to all users. However, to |
| 1232 | // protect against spoofing, check permissions below. |
| 1233 | case TYPE_APPLICATION_STARTING: |
| 1234 | case TYPE_BOOT_PROGRESS: |
| 1235 | case TYPE_DISPLAY_OVERLAY: |
| 1236 | case TYPE_HIDDEN_NAV_CONSUMER: |
| 1237 | case TYPE_KEYGUARD: |
| 1238 | case TYPE_KEYGUARD_DIALOG: |
| 1239 | case TYPE_MAGNIFICATION_OVERLAY: |
| 1240 | case TYPE_NAVIGATION_BAR: |
| 1241 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1242 | case TYPE_PHONE: |
| 1243 | case TYPE_POINTER: |
| 1244 | case TYPE_PRIORITY_PHONE: |
| 1245 | case TYPE_RECENTS_OVERLAY: |
| 1246 | case TYPE_SEARCH_BAR: |
| 1247 | case TYPE_STATUS_BAR: |
| 1248 | case TYPE_STATUS_BAR_PANEL: |
| 1249 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 1250 | case TYPE_SYSTEM_DIALOG: |
| 1251 | case TYPE_UNIVERSE_BACKGROUND: |
| 1252 | case TYPE_VOLUME_OVERLAY: |
| 1253 | break; |
| 1254 | } |
| 1255 | |
| 1256 | // Check if third party app has set window to system window type. |
| 1257 | return mContext.checkCallingOrSelfPermission( |
| 1258 | android.Manifest.permission.INTERNAL_SYSTEM_WINDOW) |
| 1259 | != PackageManager.PERMISSION_GRANTED; |
| 1260 | } |
| 1261 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1262 | public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) { |
| 1263 | switch (attrs.type) { |
| 1264 | case TYPE_SYSTEM_OVERLAY: |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1265 | case TYPE_SECURE_SYSTEM_OVERLAY: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1266 | case TYPE_TOAST: |
| 1267 | // These types of windows can't receive input events. |
| 1268 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1269 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1270 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1271 | break; |
| 1272 | } |
| 1273 | } |
| 1274 | |
| 1275 | void readLidState() { |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 1276 | mLidState = mWindowManagerFuncs.getLidState(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1277 | } |
| 1278 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1279 | private boolean isHidden(int accessibilityMode) { |
| 1280 | switch (accessibilityMode) { |
| 1281 | case 1: |
| 1282 | return mLidState == LID_CLOSED; |
| 1283 | case 2: |
| 1284 | return mLidState == LID_OPEN; |
| 1285 | default: |
| 1286 | return false; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1287 | } |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1288 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1289 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1290 | private boolean isBuiltInKeyboardVisible() { |
| 1291 | return mHaveBuiltInKeyboard && !isHidden(mLidKeyboardAccessibility); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1292 | } |
| 1293 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1294 | /** {@inheritDoc} */ |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1295 | public void adjustConfigurationLw(Configuration config, int keyboardPresence, |
| 1296 | int navigationPresence) { |
| 1297 | mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0; |
| 1298 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1299 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1300 | applyLidSwitchState(); |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1301 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1302 | if (config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 1303 | || (keyboardPresence == PRESENCE_INTERNAL |
| 1304 | && isHidden(mLidKeyboardAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1305 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1306 | if (!mHasSoftInput) { |
| 1307 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES; |
| 1308 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1309 | } |
| 1310 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1311 | if (config.navigation == Configuration.NAVIGATION_NONAV |
| 1312 | || (navigationPresence == PRESENCE_INTERNAL |
| 1313 | && isHidden(mLidNavigationAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1314 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES; |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1315 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1316 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1317 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1318 | /** {@inheritDoc} */ |
| 1319 | public int windowTypeToLayerLw(int type) { |
| 1320 | if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1321 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1322 | } |
| 1323 | switch (type) { |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1324 | case TYPE_UNIVERSE_BACKGROUND: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1325 | return 1; |
| 1326 | case TYPE_WALLPAPER: |
| 1327 | // wallpaper is at the bottom, though the window manager may move it. |
| 1328 | return 2; |
| 1329 | case TYPE_PHONE: |
| 1330 | return 3; |
| 1331 | case TYPE_SEARCH_BAR: |
| 1332 | return 4; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1333 | case TYPE_RECENTS_OVERLAY: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1334 | case TYPE_SYSTEM_DIALOG: |
| 1335 | return 5; |
| 1336 | case TYPE_TOAST: |
| 1337 | // toasts and the plugged-in battery thing |
| 1338 | return 6; |
| 1339 | case TYPE_PRIORITY_PHONE: |
| 1340 | // SIM errors and unlock. Not sure if this really should be in a high layer. |
| 1341 | return 7; |
| 1342 | case TYPE_DREAM: |
| 1343 | // used for Dreams (screensavers with TYPE_DREAM windows) |
| 1344 | return 8; |
| 1345 | case TYPE_SYSTEM_ALERT: |
| 1346 | // like the ANR / app crashed dialogs |
| 1347 | return 9; |
| 1348 | case TYPE_INPUT_METHOD: |
| 1349 | // on-screen keyboards and other such input method user interfaces go here. |
| 1350 | return 10; |
| 1351 | case TYPE_INPUT_METHOD_DIALOG: |
| 1352 | // on-screen keyboards and other such input method user interfaces go here. |
| 1353 | return 11; |
| 1354 | case TYPE_KEYGUARD: |
| 1355 | // the keyguard; nothing on top of these can take focus, since they are |
| 1356 | // responsible for power management when displayed. |
| 1357 | return 12; |
| 1358 | case TYPE_KEYGUARD_DIALOG: |
| 1359 | return 13; |
| 1360 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 1361 | return 14; |
| 1362 | case TYPE_STATUS_BAR: |
| 1363 | return 15; |
| 1364 | case TYPE_STATUS_BAR_PANEL: |
| 1365 | return 16; |
| 1366 | case TYPE_VOLUME_OVERLAY: |
| 1367 | // the on-screen volume indicator and controller shown when the user |
| 1368 | // changes the device volume |
| 1369 | return 17; |
| 1370 | case TYPE_SYSTEM_OVERLAY: |
| 1371 | // the on-screen volume indicator and controller shown when the user |
| 1372 | // changes the device volume |
| 1373 | return 18; |
| 1374 | case TYPE_NAVIGATION_BAR: |
| 1375 | // the navigation bar, if available, shows atop most things |
| 1376 | return 19; |
| 1377 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1378 | // some panels (e.g. search) need to show on top of the navigation bar |
| 1379 | return 20; |
| 1380 | case TYPE_SYSTEM_ERROR: |
| 1381 | // system-level error dialogs |
| 1382 | return 21; |
| 1383 | case TYPE_MAGNIFICATION_OVERLAY: |
| 1384 | // used to highlight the magnified portion of a display |
| 1385 | return 22; |
| 1386 | case TYPE_DISPLAY_OVERLAY: |
| 1387 | // used to simulate secondary display devices |
| 1388 | return 23; |
| 1389 | case TYPE_DRAG: |
| 1390 | // the drag layer: input for drag-and-drop is associated with this window, |
| 1391 | // which sits above all other focusable windows |
| 1392 | return 24; |
| 1393 | case TYPE_SECURE_SYSTEM_OVERLAY: |
| 1394 | return 25; |
| 1395 | case TYPE_BOOT_PROGRESS: |
| 1396 | return 26; |
| 1397 | case TYPE_POINTER: |
| 1398 | // the (mouse) pointer layer |
| 1399 | return 27; |
| 1400 | case TYPE_HIDDEN_NAV_CONSUMER: |
| 1401 | return 28; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1402 | } |
| 1403 | Log.e(TAG, "Unknown window type: " + type); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1404 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | /** {@inheritDoc} */ |
| 1408 | public int subWindowTypeToLayerLw(int type) { |
| 1409 | switch (type) { |
| 1410 | case TYPE_APPLICATION_PANEL: |
| 1411 | case TYPE_APPLICATION_ATTACHED_DIALOG: |
| 1412 | return APPLICATION_PANEL_SUBLAYER; |
| 1413 | case TYPE_APPLICATION_MEDIA: |
| 1414 | return APPLICATION_MEDIA_SUBLAYER; |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 1415 | case TYPE_APPLICATION_MEDIA_OVERLAY: |
| 1416 | return APPLICATION_MEDIA_OVERLAY_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1417 | case TYPE_APPLICATION_SUB_PANEL: |
| 1418 | return APPLICATION_SUB_PANEL_SUBLAYER; |
| 1419 | } |
| 1420 | Log.e(TAG, "Unknown sub-window type: " + type); |
| 1421 | return 0; |
| 1422 | } |
| 1423 | |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 1424 | public int getMaxWallpaperLayer() { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1425 | return windowTypeToLayerLw(TYPE_STATUS_BAR); |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 1426 | } |
| 1427 | |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1428 | public int getAboveUniverseLayer() { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1429 | return windowTypeToLayerLw(TYPE_SYSTEM_ERROR); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1430 | } |
| 1431 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1432 | public boolean hasSystemNavBar() { |
| 1433 | return mHasSystemNavBar; |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1434 | } |
| 1435 | |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1436 | public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1437 | if (mHasNavigationBar) { |
| 1438 | // For a basic navigation bar, when we are in landscape mode we place |
| 1439 | // the navigation bar to the side. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1440 | if (mNavigationBarCanMove && fullWidth > fullHeight) { |
| 1441 | return fullWidth - mNavigationBarWidthForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1442 | } |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1443 | } |
| 1444 | return fullWidth; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1445 | } |
| 1446 | |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1447 | public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1448 | if (mHasSystemNavBar) { |
| 1449 | // For the system navigation bar, we always place it at the bottom. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1450 | return fullHeight - mNavigationBarHeightForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1451 | } |
| 1452 | if (mHasNavigationBar) { |
| 1453 | // For a basic navigation bar, when we are in portrait mode we place |
| 1454 | // the navigation bar to the bottom. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1455 | if (!mNavigationBarCanMove || fullWidth < fullHeight) { |
| 1456 | return fullHeight - mNavigationBarHeightForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1457 | } |
| 1458 | } |
| 1459 | return fullHeight; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 1460 | } |
| 1461 | |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1462 | public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
| 1463 | return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 1464 | } |
| 1465 | |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1466 | public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1467 | // If we don't have a system nav bar, then there is a separate status |
| 1468 | // bar at the top of the display. We don't count that as part of the |
| 1469 | // fixed decor, since it can hide; however, for purposes of configurations, |
| 1470 | // we do want to exclude it since applications can't generally use that part |
| 1471 | // of the screen. |
| 1472 | if (!mHasSystemNavBar) { |
| 1473 | return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight; |
| 1474 | } |
| 1475 | return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1476 | } |
| 1477 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1478 | @Override |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1479 | public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs) { |
| 1480 | return attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD; |
| 1481 | } |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1482 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1483 | @Override |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1484 | public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) { |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1485 | switch (attrs.type) { |
| 1486 | case TYPE_STATUS_BAR: |
| 1487 | case TYPE_NAVIGATION_BAR: |
| 1488 | case TYPE_WALLPAPER: |
| 1489 | case TYPE_DREAM: |
| 1490 | case TYPE_UNIVERSE_BACKGROUND: |
| 1491 | case TYPE_KEYGUARD: |
| 1492 | return false; |
| 1493 | default: |
| 1494 | return true; |
| 1495 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1496 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1497 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1498 | /** {@inheritDoc} */ |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1499 | @Override |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 1500 | public View addStartingWindow(IBinder appToken, String packageName, int theme, |
| 1501 | CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, |
| 1502 | int icon, int windowFlags) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1503 | if (!SHOW_STARTING_ANIMATIONS) { |
| 1504 | return null; |
| 1505 | } |
| 1506 | if (packageName == null) { |
| 1507 | return null; |
| 1508 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1509 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 1510 | WindowManager wm = null; |
| 1511 | View view = null; |
| 1512 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1513 | try { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1514 | Context context = mContext; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1515 | if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName |
| 1516 | + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme=" |
| 1517 | + Integer.toHexString(theme)); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 1518 | if (theme != context.getThemeResId() || labelRes != 0) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1519 | try { |
| 1520 | context = context.createPackageContext(packageName, 0); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 1521 | context.setTheme(theme); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1522 | } catch (PackageManager.NameNotFoundException e) { |
| 1523 | // Ignore |
| 1524 | } |
| 1525 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1526 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1527 | Window win = PolicyManager.makeNewWindow(context); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1528 | final TypedArray ta = win.getWindowStyle(); |
| 1529 | if (ta.getBoolean( |
| 1530 | com.android.internal.R.styleable.Window_windowDisablePreview, false) |
| 1531 | || ta.getBoolean( |
| 1532 | com.android.internal.R.styleable.Window_windowShowWallpaper,false)) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1533 | return null; |
| 1534 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1535 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1536 | Resources r = context.getResources(); |
| 1537 | win.setTitle(r.getText(labelRes, nonLocalizedLabel)); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1538 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1539 | win.setType( |
| 1540 | WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); |
| 1541 | // Force the window flags: this is a fake window, so it is not really |
| 1542 | // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM |
| 1543 | // flag because we do know that the next window will take input |
| 1544 | // focus, so we want to get the IME window up on top of us right away. |
| 1545 | win.setFlags( |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1546 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1547 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 1548 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 1549 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1550 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1551 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 1552 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 1553 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1554 | |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 1555 | if (!compatInfo.supportsScreen()) { |
| 1556 | win.addFlags(WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW); |
| 1557 | } |
| 1558 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1559 | win.setLayout(WindowManager.LayoutParams.MATCH_PARENT, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 1560 | WindowManager.LayoutParams.MATCH_PARENT); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1561 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1562 | final WindowManager.LayoutParams params = win.getAttributes(); |
| 1563 | params.token = appToken; |
| 1564 | params.packageName = packageName; |
| 1565 | params.windowAnimations = win.getWindowStyle().getResourceId( |
| 1566 | com.android.internal.R.styleable.Window_windowAnimationStyle, 0); |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 1567 | params.privateFlags |= |
| 1568 | WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1569 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1570 | params.setTitle("Starting " + packageName); |
| 1571 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 1572 | wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); |
| 1573 | view = win.getDecorView(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1574 | |
| 1575 | if (win.isFloating()) { |
| 1576 | // Whoops, there is no way to display an animation/preview |
| 1577 | // of such a thing! After all that work... let's skip it. |
| 1578 | // (Note that we must do this here because it is in |
| 1579 | // getDecorView() where the theme is evaluated... maybe |
| 1580 | // we should peek the floating attribute from the theme |
| 1581 | // earlier.) |
| 1582 | return null; |
| 1583 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1584 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1585 | if (DEBUG_STARTING_WINDOW) Slog.d( |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1586 | TAG, "Adding starting window for " + packageName |
| 1587 | + " / " + appToken + ": " |
| 1588 | + (view.getParent() != null ? view : null)); |
| 1589 | |
| 1590 | wm.addView(view, params); |
| 1591 | |
| 1592 | // Only return the view if it was successfully added to the |
| 1593 | // window manager... which we can tell by it having a parent. |
| 1594 | return view.getParent() != null ? view : null; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1595 | } catch (WindowManager.BadTokenException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1596 | // ignore |
| 1597 | Log.w(TAG, appToken + " already running, starting window not displayed"); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1598 | } catch (RuntimeException e) { |
| 1599 | // don't crash if something else bad happens, for example a |
| 1600 | // failure loading resources because we are loading from an app |
| 1601 | // on external storage that has been unmounted. |
| 1602 | Log.w(TAG, appToken + " failed creating starting window", e); |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 1603 | } finally { |
| 1604 | if (view != null && view.getParent() == null) { |
| 1605 | Log.w(TAG, "view not successfully added to wm, removing view"); |
| 1606 | wm.removeViewImmediate(view); |
| 1607 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1608 | } |
| 1609 | |
| 1610 | return null; |
| 1611 | } |
| 1612 | |
| 1613 | /** {@inheritDoc} */ |
| 1614 | public void removeStartingWindow(IBinder appToken, View window) { |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1615 | if (DEBUG_STARTING_WINDOW) { |
| 1616 | RuntimeException e = new RuntimeException("here"); |
| 1617 | e.fillInStackTrace(); |
| 1618 | Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e); |
| 1619 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1620 | |
| 1621 | if (window != null) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1622 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1623 | wm.removeView(window); |
| 1624 | } |
| 1625 | } |
| 1626 | |
| 1627 | /** |
| 1628 | * Preflight adding a window to the system. |
| 1629 | * |
| 1630 | * Currently enforces that three window types are singletons: |
| 1631 | * <ul> |
| 1632 | * <li>STATUS_BAR_TYPE</li> |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1633 | * <li>KEYGUARD_TYPE</li> |
| 1634 | * </ul> |
| 1635 | * |
| 1636 | * @param win The window to be added |
| 1637 | * @param attrs Information about the window to be added |
| 1638 | * |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1639 | * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, |
| 1640 | * WindowManagerImpl.ADD_MULTIPLE_SINGLETON |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1641 | */ |
| 1642 | public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) { |
| 1643 | switch (attrs.type) { |
| 1644 | case TYPE_STATUS_BAR: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 1645 | mContext.enforceCallingOrSelfPermission( |
| 1646 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1647 | "PhoneWindowManager"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1648 | if (mStatusBar != null) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1649 | if (mStatusBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1650 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1651 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1652 | } |
| 1653 | mStatusBar = win; |
| 1654 | break; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1655 | case TYPE_NAVIGATION_BAR: |
| 1656 | mContext.enforceCallingOrSelfPermission( |
| 1657 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1658 | "PhoneWindowManager"); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1659 | if (mNavigationBar != null) { |
| 1660 | if (mNavigationBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1661 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1662 | } |
| 1663 | } |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1664 | mNavigationBar = win; |
| 1665 | if (DEBUG_LAYOUT) Log.i(TAG, "NAVIGATION BAR: " + mNavigationBar); |
| 1666 | break; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 1667 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1668 | mContext.enforceCallingOrSelfPermission( |
| 1669 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1670 | "PhoneWindowManager"); |
| 1671 | break; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 1672 | case TYPE_STATUS_BAR_PANEL: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 1673 | mContext.enforceCallingOrSelfPermission( |
| 1674 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1675 | "PhoneWindowManager"); |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 1676 | break; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 1677 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 1678 | mContext.enforceCallingOrSelfPermission( |
| 1679 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1680 | "PhoneWindowManager"); |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 1681 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1682 | case TYPE_KEYGUARD: |
| 1683 | if (mKeyguard != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1684 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1685 | } |
| 1686 | mKeyguard = win; |
| 1687 | break; |
| 1688 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1689 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1690 | } |
| 1691 | |
| 1692 | /** {@inheritDoc} */ |
| 1693 | public void removeWindowLw(WindowState win) { |
| 1694 | if (mStatusBar == win) { |
| 1695 | mStatusBar = null; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1696 | } else if (mKeyguard == win) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1697 | mKeyguard = null; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1698 | } else if (mNavigationBar == win) { |
| 1699 | mNavigationBar = null; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1700 | } |
| 1701 | } |
| 1702 | |
| 1703 | static final boolean PRINT_ANIM = false; |
| 1704 | |
| 1705 | /** {@inheritDoc} */ |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1706 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1707 | public int selectAnimationLw(WindowState win, int transit) { |
| 1708 | if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win |
| 1709 | + ": transit=" + transit); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1710 | if (win == mStatusBar) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1711 | if (transit == TRANSIT_EXIT |
| 1712 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1713 | return R.anim.dock_top_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1714 | } else if (transit == TRANSIT_ENTER |
| 1715 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1716 | return R.anim.dock_top_enter; |
| 1717 | } |
| 1718 | } else if (win == mNavigationBar) { |
| 1719 | // This can be on either the bottom or the right. |
| 1720 | if (mNavigationBarOnBottom) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1721 | if (transit == TRANSIT_EXIT |
| 1722 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1723 | return R.anim.dock_bottom_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1724 | } else if (transit == TRANSIT_ENTER |
| 1725 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1726 | return R.anim.dock_bottom_enter; |
| 1727 | } |
| 1728 | } else { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1729 | if (transit == TRANSIT_EXIT |
| 1730 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1731 | return R.anim.dock_right_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1732 | } else if (transit == TRANSIT_ENTER |
| 1733 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1734 | return R.anim.dock_right_enter; |
| 1735 | } |
| 1736 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | if (transit == TRANSIT_PREVIEW_DONE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1740 | if (win.hasAppShownWindows()) { |
| 1741 | if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT"); |
| 1742 | return com.android.internal.R.anim.app_starting_exit; |
| 1743 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 1744 | } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1745 | && transit == TRANSIT_ENTER) { |
| 1746 | // Special case: we are animating in a dream, while the keyguard |
| 1747 | // is shown. We don't want an animation on the dream, because |
| 1748 | // we need it shown immediately with the keyguard animating away |
| 1749 | // to reveal it. |
| 1750 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | return 0; |
| 1754 | } |
| 1755 | |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 1756 | @Override |
| 1757 | public void selectRotationAnimationLw(int anim[]) { |
| 1758 | if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen=" |
| 1759 | + mTopFullscreenOpaqueWindowState + " rotationAnimation=" |
| 1760 | + (mTopFullscreenOpaqueWindowState == null ? |
| 1761 | "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation)); |
| 1762 | if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) { |
| 1763 | switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) { |
| 1764 | case ROTATION_ANIMATION_CROSSFADE: |
| 1765 | anim[0] = R.anim.rotation_animation_xfade_exit; |
| 1766 | anim[1] = R.anim.rotation_animation_enter; |
| 1767 | break; |
| 1768 | case ROTATION_ANIMATION_JUMPCUT: |
| 1769 | anim[0] = R.anim.rotation_animation_jump_exit; |
| 1770 | anim[1] = R.anim.rotation_animation_enter; |
| 1771 | break; |
| 1772 | case ROTATION_ANIMATION_ROTATE: |
| 1773 | default: |
| 1774 | anim[0] = anim[1] = 0; |
| 1775 | break; |
| 1776 | } |
| 1777 | } else { |
| 1778 | anim[0] = anim[1] = 0; |
| 1779 | } |
| 1780 | } |
| 1781 | |
| 1782 | @Override |
| 1783 | public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId, |
| 1784 | boolean forceDefault) { |
| 1785 | switch (exitAnimId) { |
| 1786 | case R.anim.rotation_animation_xfade_exit: |
| 1787 | case R.anim.rotation_animation_jump_exit: |
| 1788 | // These are the only cases that matter. |
| 1789 | if (forceDefault) { |
| 1790 | return false; |
| 1791 | } |
| 1792 | int anim[] = new int[2]; |
| 1793 | selectRotationAnimationLw(anim); |
| 1794 | return (exitAnimId == anim[0] && enterAnimId == anim[1]); |
| 1795 | default: |
| 1796 | return true; |
| 1797 | } |
| 1798 | } |
| 1799 | |
| 1800 | @Override |
Dianne Hackborn | 0c2acff | 2012-04-12 15:17:07 -0700 | [diff] [blame] | 1801 | public Animation createForceHideEnterAnimation(boolean onWallpaper) { |
| 1802 | return AnimationUtils.loadAnimation(mContext, onWallpaper |
| 1803 | ? com.android.internal.R.anim.lock_screen_wallpaper_behind_enter |
| 1804 | : com.android.internal.R.anim.lock_screen_behind_enter); |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1805 | } |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 1806 | |
| 1807 | private static void awakenDreams() { |
| 1808 | IDreamManager dreamManager = getDreamManager(); |
| 1809 | if (dreamManager != null) { |
| 1810 | try { |
| 1811 | dreamManager.awaken(); |
| 1812 | } catch (RemoteException e) { |
| 1813 | // fine, stay asleep then |
| 1814 | } |
| 1815 | } |
| 1816 | } |
| 1817 | |
| 1818 | static IDreamManager getDreamManager() { |
| 1819 | return IDreamManager.Stub.asInterface( |
| 1820 | ServiceManager.checkService(DreamService.DREAM_SERVICE)); |
| 1821 | } |
| 1822 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1823 | static ITelephony getTelephonyService() { |
Mike Lockwood | f5f4ec9 | 2011-11-08 14:05:31 -0800 | [diff] [blame] | 1824 | return ITelephony.Stub.asInterface( |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1825 | ServiceManager.checkService(Context.TELEPHONY_SERVICE)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1826 | } |
| 1827 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1828 | static IAudioService getAudioService() { |
| 1829 | IAudioService audioService = IAudioService.Stub.asInterface( |
| 1830 | ServiceManager.checkService(Context.AUDIO_SERVICE)); |
| 1831 | if (audioService == null) { |
| 1832 | Log.w(TAG, "Unable to find IAudioService interface."); |
| 1833 | } |
| 1834 | return audioService; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1835 | } |
| 1836 | |
| 1837 | boolean keyguardOn() { |
| 1838 | return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode(); |
| 1839 | } |
| 1840 | |
| 1841 | private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = { |
| 1842 | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, |
| 1843 | WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, |
| 1844 | }; |
| 1845 | |
| 1846 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1847 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1848 | public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1849 | final boolean keyguardOn = keyguardOn(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1850 | final int keyCode = event.getKeyCode(); |
| 1851 | final int repeatCount = event.getRepeatCount(); |
| 1852 | final int metaState = event.getMetaState(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1853 | final int flags = event.getFlags(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1854 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 1855 | final boolean canceled = event.isCanceled(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1856 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 1857 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1858 | Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 1859 | + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed |
| 1860 | + " canceled=" + canceled); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1861 | } |
| 1862 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1863 | // If we think we might have a volume down & power key chord on the way |
| 1864 | // but we're not sure, then tell the dispatcher to wait a little while and |
| 1865 | // try again later before dispatching. |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1866 | if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1867 | if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) { |
| 1868 | final long now = SystemClock.uptimeMillis(); |
| 1869 | final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS; |
| 1870 | if (now < timeoutTime) { |
| 1871 | return timeoutTime - now; |
| 1872 | } |
| 1873 | } |
| 1874 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
| 1875 | && mVolumeDownKeyConsumedByScreenshotChord) { |
| 1876 | if (!down) { |
| 1877 | mVolumeDownKeyConsumedByScreenshotChord = false; |
| 1878 | } |
| 1879 | return -1; |
| 1880 | } |
| 1881 | } |
| 1882 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1883 | // First we always handle the home key here, so applications |
| 1884 | // can never break it, although if keyguard is on, we do let |
| 1885 | // it handle it, because that gives us the correct 5 second |
| 1886 | // timeout. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1887 | if (keyCode == KeyEvent.KEYCODE_HOME) { |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1888 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1889 | // If we have released the home key, and didn't do anything else |
| 1890 | // while it was pressed, then it is time to go home! |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1891 | if (!down) { |
| 1892 | final boolean homeWasLongPressed = mHomeLongPressed; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1893 | mHomePressed = false; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1894 | mHomeLongPressed = false; |
| 1895 | if (!homeWasLongPressed) { |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 1896 | if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) { |
Michael Jurka | 01de93d | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 1897 | try { |
| 1898 | IStatusBarService statusbar = getStatusBarService(); |
| 1899 | if (statusbar != null) { |
| 1900 | statusbar.cancelPreloadRecentApps(); |
| 1901 | } |
| 1902 | } catch (RemoteException e) { |
| 1903 | Slog.e(TAG, "RemoteException when showing recent apps", e); |
| 1904 | // re-acquire status bar service next time it is needed. |
| 1905 | mStatusBarService = null; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 1906 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1907 | } |
| 1908 | |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1909 | mHomePressed = false; |
| 1910 | if (!canceled) { |
| 1911 | // If an incoming call is ringing, HOME is totally disabled. |
| 1912 | // (The user is already on the InCallScreen at this point, |
| 1913 | // and his ONLY options are to answer or reject the call.) |
| 1914 | boolean incomingRinging = false; |
| 1915 | try { |
| 1916 | ITelephony telephonyService = getTelephonyService(); |
| 1917 | if (telephonyService != null) { |
| 1918 | incomingRinging = telephonyService.isRinging(); |
| 1919 | } |
| 1920 | } catch (RemoteException ex) { |
| 1921 | Log.w(TAG, "RemoteException from getPhoneInterface()", ex); |
| 1922 | } |
| 1923 | |
| 1924 | if (incomingRinging) { |
| 1925 | Log.i(TAG, "Ignoring HOME; there's a ringing incoming call."); |
| 1926 | } else { |
| 1927 | launchHomeFromHotKey(); |
| 1928 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1929 | } else { |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1930 | Log.i(TAG, "Ignoring HOME; event canceled."); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1931 | } |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1932 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1933 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1934 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1935 | |
| 1936 | // If a system window has focus, then it doesn't make sense |
| 1937 | // right now to interact with applications. |
| 1938 | WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null; |
| 1939 | if (attrs != null) { |
| 1940 | final int type = attrs.type; |
| 1941 | if (type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 1942 | || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) { |
| 1943 | // the "app" is keyguard, so give it the key |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1944 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1945 | } |
| 1946 | final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length; |
| 1947 | for (int i=0; i<typeCount; i++) { |
| 1948 | if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) { |
| 1949 | // 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] | 1950 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1951 | } |
| 1952 | } |
| 1953 | } |
Jeff Brown | 98392ef | 2011-09-12 18:24:59 -0700 | [diff] [blame] | 1954 | if (down) { |
Michael Jurka | 4004033 | 2012-05-29 08:25:32 -0700 | [diff] [blame] | 1955 | if (!mHomePressed && mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) { |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1956 | try { |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 1957 | IStatusBarService statusbar = getStatusBarService(); |
| 1958 | if (statusbar != null) { |
| 1959 | statusbar.preloadRecentApps(); |
| 1960 | } |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1961 | } catch (RemoteException e) { |
| 1962 | Slog.e(TAG, "RemoteException when preloading recent apps", e); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 1963 | // re-acquire status bar service next time it is needed. |
| 1964 | mStatusBarService = null; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1965 | } |
| 1966 | } |
Jeff Brown | 98392ef | 2011-09-12 18:24:59 -0700 | [diff] [blame] | 1967 | if (repeatCount == 0) { |
| 1968 | mHomePressed = true; |
| 1969 | } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) { |
| 1970 | if (!keyguardOn) { |
| 1971 | handleLongPressOnHome(); |
| 1972 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1973 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1974 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1975 | return -1; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1976 | } else if (keyCode == KeyEvent.KEYCODE_MENU) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1977 | // Hijack modified menu keys for debugging features |
| 1978 | final int chordBug = KeyEvent.META_SHIFT_ON; |
| 1979 | |
| 1980 | if (down && repeatCount == 0) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1981 | if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1982 | Intent intent = new Intent(Intent.ACTION_BUG_REPORT); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 1983 | mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, |
| 1984 | null, null, null, 0, null, null); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1985 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1986 | } else if (SHOW_PROCESSES_ON_ALT_MENU && |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1987 | (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1988 | Intent service = new Intent(); |
| 1989 | service.setClassName(mContext, "com.android.server.LoadAverageService"); |
| 1990 | ContentResolver res = mContext.getContentResolver(); |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 1991 | boolean shown = Settings.Global.getInt( |
| 1992 | res, Settings.Global.SHOW_PROCESSES, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1993 | if (!shown) { |
| 1994 | mContext.startService(service); |
| 1995 | } else { |
| 1996 | mContext.stopService(service); |
| 1997 | } |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 1998 | Settings.Global.putInt( |
| 1999 | res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2000 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2001 | } |
| 2002 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2003 | } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2004 | if (down) { |
| 2005 | if (repeatCount == 0) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2006 | mSearchKeyShortcutPending = true; |
| 2007 | mConsumeSearchKeyUp = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2008 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2009 | } else { |
| 2010 | mSearchKeyShortcutPending = false; |
| 2011 | if (mConsumeSearchKeyUp) { |
| 2012 | mConsumeSearchKeyUp = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2013 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2014 | } |
| 2015 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2016 | return 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2017 | } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) { |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2018 | if (!keyguardOn) { |
| 2019 | try { |
| 2020 | IStatusBarService statusbar = getStatusBarService(); |
| 2021 | if (statusbar != null) { |
| 2022 | if (down && repeatCount == 0) { |
| 2023 | statusbar.preloadRecentApps(); |
| 2024 | } else if (!down) { |
| 2025 | statusbar.toggleRecentApps(); |
| 2026 | } |
| 2027 | } |
| 2028 | } catch (RemoteException e) { |
| 2029 | Slog.e(TAG, "RemoteException when preloading recent apps", e); |
| 2030 | // re-acquire status bar service next time it is needed. |
| 2031 | mStatusBarService = null; |
| 2032 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2033 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2034 | return -1; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2035 | } else if (keyCode == KeyEvent.KEYCODE_ASSIST) { |
| 2036 | if (down) { |
| 2037 | if (repeatCount == 0) { |
| 2038 | mAssistKeyLongPressed = false; |
| 2039 | } else if (repeatCount == 1) { |
| 2040 | mAssistKeyLongPressed = true; |
| 2041 | if (!keyguardOn) { |
| 2042 | launchAssistLongPressAction(); |
| 2043 | } |
| 2044 | } |
| 2045 | } else { |
| 2046 | if (mAssistKeyLongPressed) { |
| 2047 | mAssistKeyLongPressed = false; |
| 2048 | } else { |
| 2049 | if (!keyguardOn) { |
| 2050 | launchAssistAction(); |
| 2051 | } |
| 2052 | } |
| 2053 | } |
| 2054 | return -1; |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 2055 | } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) { |
| 2056 | if (down && repeatCount == 0) { |
| 2057 | mHandler.post(mScreenshotRunnable); |
| 2058 | } |
| 2059 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2060 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2061 | |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 2062 | // Shortcuts are invoked through Search+key, so intercept those here |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2063 | // Any printing key that is chorded with Search should be consumed |
| 2064 | // even if no shortcut was invoked. This prevents text from being |
| 2065 | // inadvertently inserted when using a keyboard that has built-in macro |
| 2066 | // 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] | 2067 | if (mSearchKeyShortcutPending) { |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2068 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 2069 | if (kcm.isPrintingKey(keyCode)) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2070 | mConsumeSearchKeyUp = true; |
| 2071 | mSearchKeyShortcutPending = false; |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2072 | if (down && repeatCount == 0 && !keyguardOn) { |
| 2073 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState); |
| 2074 | if (shortcutIntent != null) { |
| 2075 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2076 | try { |
| 2077 | mContext.startActivity(shortcutIntent); |
| 2078 | } catch (ActivityNotFoundException ex) { |
| 2079 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2080 | + "the activity to which it is registered was not found: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2081 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2082 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2083 | } else { |
| 2084 | Slog.i(TAG, "Dropping unregistered shortcut key combination: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2085 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2086 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2087 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2088 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2089 | } |
| 2090 | } |
| 2091 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2092 | // Invoke shortcuts using Meta. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2093 | if (down && repeatCount == 0 && !keyguardOn |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2094 | && (metaState & KeyEvent.META_META_ON) != 0) { |
| 2095 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2096 | if (kcm.isPrintingKey(keyCode)) { |
| 2097 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, |
| 2098 | metaState & ~(KeyEvent.META_META_ON |
| 2099 | | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON)); |
| 2100 | if (shortcutIntent != null) { |
| 2101 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2102 | try { |
| 2103 | mContext.startActivity(shortcutIntent); |
| 2104 | } catch (ActivityNotFoundException ex) { |
| 2105 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2106 | + "the activity to which it is registered was not found: " |
| 2107 | + "META+" + KeyEvent.keyCodeToString(keyCode), ex); |
| 2108 | } |
| 2109 | return -1; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2110 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2111 | } |
| 2112 | } |
| 2113 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2114 | // Handle application launch keys. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2115 | if (down && repeatCount == 0 && !keyguardOn) { |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2116 | String category = sApplicationLaunchKeyCategories.get(keyCode); |
| 2117 | if (category != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 2118 | Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2119 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2120 | try { |
| 2121 | mContext.startActivity(intent); |
| 2122 | } catch (ActivityNotFoundException ex) { |
| 2123 | Slog.w(TAG, "Dropping application launch key because " |
| 2124 | + "the activity to which it is registered was not found: " |
| 2125 | + "keyCode=" + keyCode + ", category=" + category, ex); |
| 2126 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2127 | return -1; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2128 | } |
| 2129 | } |
| 2130 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2131 | // Display task switcher for ALT-TAB or Meta-TAB. |
| 2132 | if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) { |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2133 | if (mRecentAppsDialogHeldModifiers == 0 && !keyguardOn) { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2134 | final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK; |
| 2135 | if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON) |
| 2136 | || KeyEvent.metaStateHasModifiers( |
| 2137 | shiftlessModifiers, KeyEvent.META_META_ON)) { |
| 2138 | mRecentAppsDialogHeldModifiers = shiftlessModifiers; |
| 2139 | showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW); |
| 2140 | return -1; |
| 2141 | } |
| 2142 | } |
| 2143 | } else if (!down && mRecentAppsDialogHeldModifiers != 0 |
| 2144 | && (metaState & mRecentAppsDialogHeldModifiers) == 0) { |
| 2145 | mRecentAppsDialogHeldModifiers = 0; |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2146 | showOrHideRecentAppsDialog(keyguardOn ? RECENT_APPS_BEHAVIOR_DISMISS : |
| 2147 | RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2148 | } |
| 2149 | |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 2150 | // Handle keyboard language switching. |
| 2151 | if (down && repeatCount == 0 |
| 2152 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 2153 | || (keyCode == KeyEvent.KEYCODE_SPACE |
| 2154 | && (metaState & KeyEvent.META_CTRL_MASK) != 0))) { |
| 2155 | int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1; |
| 2156 | mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction); |
| 2157 | return -1; |
| 2158 | } |
| 2159 | if (mLanguageSwitchKeyPressed && !down |
| 2160 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 2161 | || keyCode == KeyEvent.KEYCODE_SPACE)) { |
| 2162 | mLanguageSwitchKeyPressed = false; |
| 2163 | return -1; |
| 2164 | } |
| 2165 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 2166 | if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) { |
| 2167 | return -1; |
| 2168 | } |
| 2169 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2170 | // Let the application handle the key. |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2171 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2172 | } |
| 2173 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2174 | /** {@inheritDoc} */ |
| 2175 | @Override |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2176 | public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 2177 | // Note: This method is only called if the initial down was unhandled. |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2178 | if (DEBUG_INPUT) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2179 | Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction() |
| 2180 | + ", flags=" + event.getFlags() |
| 2181 | + ", keyCode=" + event.getKeyCode() |
| 2182 | + ", scanCode=" + event.getScanCode() |
| 2183 | + ", metaState=" + event.getMetaState() |
| 2184 | + ", repeatCount=" + event.getRepeatCount() |
| 2185 | + ", policyFlags=" + policyFlags); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2186 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2187 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2188 | KeyEvent fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2189 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 2190 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 2191 | final int keyCode = event.getKeyCode(); |
| 2192 | final int metaState = event.getMetaState(); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2193 | final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN |
| 2194 | && event.getRepeatCount() == 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2195 | |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 2196 | // Check for fallback actions specified by the key character map. |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2197 | final FallbackAction fallbackAction; |
| 2198 | if (initialDown) { |
| 2199 | fallbackAction = kcm.getFallbackAction(keyCode, metaState); |
| 2200 | } else { |
| 2201 | fallbackAction = mFallbackActions.get(keyCode); |
| 2202 | } |
| 2203 | |
| 2204 | if (fallbackAction != null) { |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2205 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2206 | Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode |
| 2207 | + " metaState=" + Integer.toHexString(fallbackAction.metaState)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2208 | } |
| 2209 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2210 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 2211 | fallbackEvent = KeyEvent.obtain( |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2212 | event.getDownTime(), event.getEventTime(), |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2213 | event.getAction(), fallbackAction.keyCode, |
| 2214 | event.getRepeatCount(), fallbackAction.metaState, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2215 | event.getDeviceId(), event.getScanCode(), |
| 2216 | flags, event.getSource(), null); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2217 | |
| 2218 | if (!interceptFallback(win, fallbackEvent, policyFlags)) { |
| 2219 | fallbackEvent.recycle(); |
| 2220 | fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2221 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2222 | |
| 2223 | if (initialDown) { |
| 2224 | mFallbackActions.put(keyCode, fallbackAction); |
| 2225 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 2226 | mFallbackActions.remove(keyCode); |
| 2227 | fallbackAction.recycle(); |
| 2228 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2229 | } |
| 2230 | } |
| 2231 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2232 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2233 | if (fallbackEvent == null) { |
| 2234 | Slog.d(TAG, "No fallback."); |
| 2235 | } else { |
| 2236 | Slog.d(TAG, "Performing fallback: " + fallbackEvent); |
| 2237 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2238 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2239 | return fallbackEvent; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2240 | } |
| 2241 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2242 | private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) { |
| 2243 | int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags, true); |
| 2244 | if ((actions & ACTION_PASS_TO_USER) != 0) { |
| 2245 | long delayMillis = interceptKeyBeforeDispatching( |
| 2246 | win, fallbackEvent, policyFlags); |
| 2247 | if (delayMillis == 0) { |
| 2248 | return true; |
| 2249 | } |
| 2250 | } |
| 2251 | return false; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2252 | } |
| 2253 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2254 | private void launchAssistLongPressAction() { |
| 2255 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 2256 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
| 2257 | |
| 2258 | // launch the search activity |
| 2259 | Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS); |
| 2260 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2261 | try { |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2262 | // TODO: This only stops the factory-installed search manager. |
| 2263 | // Need to formalize an API to handle others |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2264 | SearchManager searchManager = getSearchManager(); |
| 2265 | if (searchManager != null) { |
| 2266 | searchManager.stopSearch(); |
| 2267 | } |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 2268 | mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT)); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2269 | } catch (ActivityNotFoundException e) { |
| 2270 | Slog.w(TAG, "No activity to handle assist long press action.", e); |
| 2271 | } |
| 2272 | } |
| 2273 | |
| 2274 | private void launchAssistAction() { |
| 2275 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 2276 | Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)) |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2277 | .getAssistIntent(mContext, true, UserHandle.USER_CURRENT); |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2278 | if (intent != null) { |
| 2279 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 2280 | | Intent.FLAG_ACTIVITY_SINGLE_TOP |
| 2281 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 2282 | try { |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 2283 | mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT)); |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2284 | } catch (ActivityNotFoundException e) { |
| 2285 | Slog.w(TAG, "No activity to handle assist action.", e); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2286 | } |
| 2287 | } |
| 2288 | } |
| 2289 | |
| 2290 | private SearchManager getSearchManager() { |
| 2291 | if (mSearchManager == null) { |
| 2292 | mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE); |
| 2293 | } |
| 2294 | return mSearchManager; |
| 2295 | } |
| 2296 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2297 | /** |
| 2298 | * A home key -> launch home action was detected. Take the appropriate action |
| 2299 | * given the situation with the keyguard. |
| 2300 | */ |
| 2301 | void launchHomeFromHotKey() { |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 2302 | if (mKeyguardMediator != null && mKeyguardMediator.isShowingAndNotHidden()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2303 | // don't launch home if keyguard showing |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2304 | } else if (!mHideLockScreen && mKeyguardMediator.isInputRestricted()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2305 | // when in keyguard restricted mode, must first verify unlock |
| 2306 | // before launching home |
| 2307 | mKeyguardMediator.verifyUnlock(new OnKeyguardExitResult() { |
| 2308 | public void onKeyguardExitResult(boolean success) { |
| 2309 | if (success) { |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 2310 | try { |
| 2311 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 2312 | } catch (RemoteException e) { |
| 2313 | } |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 2314 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2315 | startDockOrHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2316 | } |
| 2317 | } |
| 2318 | }); |
| 2319 | } else { |
| 2320 | // no keyguard stuff to worry about, just launch home! |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 2321 | try { |
| 2322 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 2323 | } catch (RemoteException e) { |
| 2324 | } |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 2325 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2326 | startDockOrHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2327 | } |
| 2328 | } |
| 2329 | |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2330 | /** |
| 2331 | * A delayed callback use to determine when it is okay to re-allow applications |
| 2332 | * to use certain system UI flags. This is used to prevent applications from |
| 2333 | * spamming system UI changes that prevent the navigation bar from being shown. |
| 2334 | */ |
| 2335 | final Runnable mAllowSystemUiDelay = new Runnable() { |
| 2336 | @Override public void run() { |
| 2337 | } |
| 2338 | }; |
| 2339 | |
| 2340 | /** |
| 2341 | * Input handler used while nav bar is hidden. Captures any touch on the screen, |
| 2342 | * to determine when the nav bar should be shown and prevent applications from |
| 2343 | * receiving those touches. |
| 2344 | */ |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2345 | final class HideNavInputEventReceiver extends InputEventReceiver { |
| 2346 | public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 2347 | super(inputChannel, looper); |
| 2348 | } |
| 2349 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2350 | @Override |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2351 | public void onInputEvent(InputEvent event) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2352 | boolean handled = false; |
| 2353 | try { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 2354 | if (event instanceof MotionEvent |
| 2355 | && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 2356 | final MotionEvent motionEvent = (MotionEvent)event; |
| 2357 | if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2358 | // When the user taps down, we re-show the nav bar. |
| 2359 | boolean changed = false; |
| 2360 | synchronized (mLock) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2361 | // Any user activity always causes us to show the |
| 2362 | // navigation controls, if they had been hidden. |
| 2363 | // We also clear the low profile and only content |
| 2364 | // flags so that tapping on the screen will atomically |
| 2365 | // restore all currently hidden screen decorations. |
| 2366 | int newVal = mResettingSystemUiFlags | |
| 2367 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | |
| 2368 | View.SYSTEM_UI_FLAG_LOW_PROFILE | |
| 2369 | View.SYSTEM_UI_FLAG_FULLSCREEN; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2370 | if (mResettingSystemUiFlags != newVal) { |
| 2371 | mResettingSystemUiFlags = newVal; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2372 | changed = true; |
| 2373 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2374 | // We don't allow the system's nav bar to be hidden |
| 2375 | // again for 1 second, to prevent applications from |
| 2376 | // spamming us and keeping it from being shown. |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2377 | newVal = mForceClearedSystemUiFlags | |
| 2378 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2379 | if (mForceClearedSystemUiFlags != newVal) { |
| 2380 | mForceClearedSystemUiFlags = newVal; |
| 2381 | changed = true; |
| 2382 | mHandler.postDelayed(new Runnable() { |
| 2383 | @Override public void run() { |
| 2384 | synchronized (mLock) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2385 | // Clear flags. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2386 | mForceClearedSystemUiFlags &= |
| 2387 | ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 2388 | } |
| 2389 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 2390 | } |
| 2391 | }, 1000); |
| 2392 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2393 | } |
| 2394 | if (changed) { |
| 2395 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 2396 | } |
| 2397 | } |
| 2398 | } |
| 2399 | } finally { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2400 | finishInputEvent(event, handled); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2401 | } |
| 2402 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2403 | } |
| 2404 | final InputEventReceiver.Factory mHideNavInputEventReceiverFactory = |
| 2405 | new InputEventReceiver.Factory() { |
| 2406 | @Override |
| 2407 | public InputEventReceiver createInputEventReceiver( |
| 2408 | InputChannel inputChannel, Looper looper) { |
| 2409 | return new HideNavInputEventReceiver(inputChannel, looper); |
| 2410 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2411 | }; |
| 2412 | |
| 2413 | @Override |
| 2414 | public int adjustSystemUiVisibilityLw(int visibility) { |
| 2415 | // Reset any bits in mForceClearingStatusBarVisibility that |
| 2416 | // are now clear. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2417 | mResettingSystemUiFlags &= visibility; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2418 | // Clear any bits in the new visibility that are currently being |
| 2419 | // force cleared, before reporting it. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2420 | return visibility & ~mResettingSystemUiFlags |
| 2421 | & ~mForceClearedSystemUiFlags; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2422 | } |
| 2423 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2424 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2425 | public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) { |
| 2426 | final int fl = attrs.flags; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2427 | final int systemUiVisibility = (attrs.systemUiVisibility|attrs.subtreeSystemUiVisibility); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2428 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2429 | 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] | 2430 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2431 | int availRight, availBottom; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2432 | if (mCanHideNavigationBar && |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2433 | (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2434 | availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 2435 | availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
| 2436 | } else { |
| 2437 | availRight = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 2438 | availBottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
| 2439 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2440 | if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 2441 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 2442 | contentInset.set(mStableFullscreenLeft, mStableFullscreenTop, |
| 2443 | availRight - mStableFullscreenRight, |
| 2444 | availBottom - mStableFullscreenBottom); |
| 2445 | } else { |
| 2446 | contentInset.set(mStableLeft, mStableTop, |
| 2447 | availRight - mStableRight, availBottom - mStableBottom); |
| 2448 | } |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2449 | } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) { |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2450 | contentInset.setEmpty(); |
| 2451 | } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2452 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) { |
| 2453 | contentInset.set(mCurLeft, mCurTop, |
| 2454 | availRight - mCurRight, availBottom - mCurBottom); |
| 2455 | } else { |
| 2456 | contentInset.set(mCurLeft, mCurTop, |
| 2457 | availRight - mCurRight, availBottom - mCurBottom); |
| 2458 | } |
| 2459 | return; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2460 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2461 | contentInset.setEmpty(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2462 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2463 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2464 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2465 | @Override |
| 2466 | public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight, |
| 2467 | int displayRotation) { |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2468 | final int overscanLeft, overscanTop, overscanRight, overscanBottom; |
| 2469 | if (isDefaultDisplay) { |
| 2470 | switch (displayRotation) { |
| 2471 | case Surface.ROTATION_90: |
| 2472 | overscanLeft = mOverscanTop; |
| 2473 | overscanTop = mOverscanRight; |
| 2474 | overscanRight = mOverscanBottom; |
| 2475 | overscanBottom = mOverscanLeft; |
| 2476 | break; |
| 2477 | case Surface.ROTATION_180: |
| 2478 | overscanLeft = mOverscanRight; |
| 2479 | overscanTop = mOverscanBottom; |
| 2480 | overscanRight = mOverscanLeft; |
| 2481 | overscanBottom = mOverscanTop; |
| 2482 | break; |
| 2483 | case Surface.ROTATION_270: |
| 2484 | overscanLeft = mOverscanBottom; |
| 2485 | overscanTop = mOverscanLeft; |
| 2486 | overscanRight = mOverscanTop; |
| 2487 | overscanBottom = mOverscanRight; |
| 2488 | break; |
| 2489 | default: |
| 2490 | overscanLeft = mOverscanLeft; |
| 2491 | overscanTop = mOverscanTop; |
| 2492 | overscanRight = mOverscanRight; |
| 2493 | overscanBottom = mOverscanBottom; |
| 2494 | break; |
| 2495 | } |
| 2496 | } else { |
| 2497 | overscanLeft = 0; |
| 2498 | overscanTop = 0; |
| 2499 | overscanRight = 0; |
| 2500 | overscanBottom = 0; |
| 2501 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 2502 | mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0; |
| 2503 | mOverscanScreenTop = mRestrictedOverscanScreenTop = 0; |
| 2504 | mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth; |
| 2505 | mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2506 | mSystemLeft = 0; |
| 2507 | mSystemTop = 0; |
| 2508 | mSystemRight = displayWidth; |
| 2509 | mSystemBottom = displayHeight; |
| 2510 | mUnrestrictedScreenLeft = overscanLeft; |
| 2511 | mUnrestrictedScreenTop = overscanTop; |
| 2512 | mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight; |
| 2513 | mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom; |
| 2514 | mRestrictedScreenLeft = mUnrestrictedScreenLeft; |
| 2515 | mRestrictedScreenTop = mUnrestrictedScreenTop; |
| 2516 | mRestrictedScreenWidth = mUnrestrictedScreenWidth; |
| 2517 | mRestrictedScreenHeight = mUnrestrictedScreenHeight; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2518 | mDockLeft = mContentLeft = mStableLeft = mStableFullscreenLeft |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2519 | = mCurLeft = mUnrestrictedScreenLeft; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2520 | mDockTop = mContentTop = mStableTop = mStableFullscreenTop |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2521 | = mCurTop = mUnrestrictedScreenTop; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2522 | mDockRight = mContentRight = mStableRight = mStableFullscreenRight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2523 | = mCurRight = displayWidth - overscanRight; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2524 | mDockBottom = mContentBottom = mStableBottom = mStableFullscreenBottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2525 | = mCurBottom = displayHeight - overscanBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2526 | mDockLayer = 0x10000000; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 2527 | mStatusBarLayer = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2528 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2529 | // start with the current dock rect, which will be (0,0,displayWidth,displayHeight) |
| 2530 | final Rect pf = mTmpParentFrame; |
| 2531 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2532 | final Rect of = mTmpOverscanFrame; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2533 | final Rect vf = mTmpVisibleFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2534 | pf.left = df.left = of.left = vf.left = mDockLeft; |
| 2535 | pf.top = df.top = of.top = vf.top = mDockTop; |
| 2536 | pf.right = df.right = of.right = vf.right = mDockRight; |
| 2537 | pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2538 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2539 | if (isDefaultDisplay) { |
| 2540 | // For purposes of putting out fake window up to steal focus, we will |
| 2541 | // drive nav being hidden only by whether it is requested. |
| 2542 | boolean navVisible = (mLastSystemUiFlags&View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2543 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2544 | // When the navigation bar isn't visible, we put up a fake |
| 2545 | // input window to catch all touch events. This way we can |
| 2546 | // detect when the user presses anywhere to bring back the nav |
| 2547 | // bar and ensure the application doesn't see the event. |
| 2548 | if (navVisible) { |
| 2549 | if (mHideNavFakeWindow != null) { |
| 2550 | mHideNavFakeWindow.dismiss(); |
| 2551 | mHideNavFakeWindow = null; |
| 2552 | } |
| 2553 | } else if (mHideNavFakeWindow == null) { |
| 2554 | mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow( |
| 2555 | mHandler.getLooper(), mHideNavInputEventReceiverFactory, |
| 2556 | "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, |
| 2557 | 0, false, false, true); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2558 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2559 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2560 | // For purposes of positioning and showing the nav bar, if we have |
| 2561 | // decided that it can't be hidden (because of the screen aspect ratio), |
| 2562 | // then take that into account. |
| 2563 | navVisible |= !mCanHideNavigationBar; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2564 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2565 | if (mNavigationBar != null) { |
| 2566 | // Force the navigation bar to its appropriate place and |
| 2567 | // size. We need to do this directly, instead of relying on |
| 2568 | // it to bubble up from the nav bar, because this needs to |
| 2569 | // change atomically with screen rotations. |
| 2570 | mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight); |
| 2571 | if (mNavigationBarOnBottom) { |
| 2572 | // 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] | 2573 | int top = displayHeight - overscanBottom |
| 2574 | - mNavigationBarHeightForRotation[displayRotation]; |
| 2575 | mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2576 | mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top; |
| 2577 | if (navVisible) { |
| 2578 | mNavigationBar.showLw(true); |
| 2579 | mDockBottom = mTmpNavigationFrame.top; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 2580 | mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop; |
| 2581 | mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2582 | } else { |
| 2583 | // We currently want to hide the navigation UI. |
| 2584 | mNavigationBar.hideLw(true); |
| 2585 | } |
| 2586 | if (navVisible && !mNavigationBar.isAnimatingLw()) { |
| 2587 | // If the nav bar is currently requested to be visible, |
| 2588 | // and not in the process of animating on or off, then |
| 2589 | // we can tell the app that it is covered by it. |
| 2590 | mSystemBottom = mTmpNavigationFrame.top; |
| 2591 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2592 | } else { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2593 | // Landscape screen; nav bar goes to the right. |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2594 | int left = displayWidth - overscanRight |
| 2595 | - mNavigationBarWidthForRotation[displayRotation]; |
| 2596 | mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2597 | mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left; |
| 2598 | if (navVisible) { |
| 2599 | mNavigationBar.showLw(true); |
| 2600 | mDockRight = mTmpNavigationFrame.left; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 2601 | mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft; |
| 2602 | mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2603 | } else { |
| 2604 | // We currently want to hide the navigation UI. |
| 2605 | mNavigationBar.hideLw(true); |
| 2606 | } |
| 2607 | if (navVisible && !mNavigationBar.isAnimatingLw()) { |
| 2608 | // If the nav bar is currently requested to be visible, |
| 2609 | // and not in the process of animating on or off, then |
| 2610 | // we can tell the app that it is covered by it. |
| 2611 | mSystemRight = mTmpNavigationFrame.left; |
| 2612 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2613 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2614 | // Make sure the content and current rectangles are updated to |
| 2615 | // account for the restrictions from the navigation bar. |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2616 | mContentTop = mCurTop = mDockTop; |
| 2617 | mContentBottom = mCurBottom = mDockBottom; |
| 2618 | mContentLeft = mCurLeft = mDockLeft; |
| 2619 | mContentRight = mCurRight = mDockRight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2620 | mStatusBarLayer = mNavigationBar.getSurfaceLayer(); |
| 2621 | // And compute the final frame. |
| 2622 | mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame, |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2623 | mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2624 | if (DEBUG_LAYOUT) Log.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2625 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2626 | if (DEBUG_LAYOUT) Log.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)", |
| 2627 | mDockLeft, mDockTop, mDockRight, mDockBottom)); |
| 2628 | |
| 2629 | // decide where the status bar goes ahead of time |
| 2630 | if (mStatusBar != null) { |
| 2631 | // apply any navigation bar insets |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2632 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 2633 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 2634 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 2635 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight |
| 2636 | + mUnrestrictedScreenTop; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2637 | vf.left = mStableLeft; |
| 2638 | vf.top = mStableTop; |
| 2639 | vf.right = mStableRight; |
| 2640 | vf.bottom = mStableBottom; |
| 2641 | |
| 2642 | mStatusBarLayer = mStatusBar.getSurfaceLayer(); |
| 2643 | |
| 2644 | // Let the status bar determine its size. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2645 | mStatusBar.computeFrameLw(pf, df, vf, vf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2646 | |
| 2647 | // For layout, the status bar is always at the top with our fixed height. |
| 2648 | mStableTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 2649 | |
| 2650 | // If the status bar is hidden, we don't want to cause |
| 2651 | // windows behind it to scroll. |
| 2652 | if (mStatusBar.isVisibleLw()) { |
| 2653 | // Status bar may go away, so the screen area it occupies |
| 2654 | // is available to apps but just covering them when the |
| 2655 | // status bar is visible. |
| 2656 | mDockTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 2657 | |
| 2658 | mContentTop = mCurTop = mDockTop; |
| 2659 | mContentBottom = mCurBottom = mDockBottom; |
| 2660 | mContentLeft = mCurLeft = mDockLeft; |
| 2661 | mContentRight = mCurRight = mDockRight; |
| 2662 | |
| 2663 | if (DEBUG_LAYOUT) Log.v(TAG, "Status bar: " + |
| 2664 | String.format( |
| 2665 | "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]", |
| 2666 | mDockLeft, mDockTop, mDockRight, mDockBottom, |
| 2667 | mContentLeft, mContentTop, mContentRight, mContentBottom, |
| 2668 | mCurLeft, mCurTop, mCurRight, mCurBottom)); |
| 2669 | } |
| 2670 | if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()) { |
| 2671 | // If the status bar is currently requested to be visible, |
| 2672 | // and not in the process of animating on or off, then |
| 2673 | // we can tell the app that it is covered by it. |
| 2674 | mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 2675 | } |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 2676 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2677 | } |
| 2678 | } |
| 2679 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 2680 | /** {@inheritDoc} */ |
| 2681 | public int getSystemDecorRectLw(Rect systemRect) { |
| 2682 | systemRect.left = mSystemLeft; |
| 2683 | systemRect.top = mSystemTop; |
| 2684 | systemRect.right = mSystemRight; |
| 2685 | systemRect.bottom = mSystemBottom; |
| 2686 | if (mStatusBar != null) return mStatusBar.getSurfaceLayer(); |
| 2687 | if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer(); |
| 2688 | return 0; |
| 2689 | } |
| 2690 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2691 | void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached, |
| 2692 | 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] | 2693 | if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) { |
| 2694 | // Here's a special case: if this attached window is a panel that is |
| 2695 | // above the dock window, and the window it is attached to is below |
| 2696 | // the dock window, then the frames we computed for the window it is |
| 2697 | // attached to can not be used because the dock is effectively part |
| 2698 | // of the underlying window and the attached window is floating on top |
| 2699 | // of the whole thing. So, we ignore the attached window and explicitly |
| 2700 | // compute the frames that would be appropriate without the dock. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2701 | df.left = of.left = cf.left = vf.left = mDockLeft; |
| 2702 | df.top = of.top = cf.top = vf.top = mDockTop; |
| 2703 | df.right = of.right = cf.right = vf.right = mDockRight; |
| 2704 | df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2705 | } else { |
| 2706 | // The effective display frame of the attached window depends on |
| 2707 | // whether it is taking care of insetting its content. If not, |
| 2708 | // we need to use the parent's content frame so that the entire |
| 2709 | // window is positioned within that content. Otherwise we can use |
| 2710 | // the display frame and let the attached window take care of |
| 2711 | // positioning its content appropriately. |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 2712 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2713 | cf.set(attached.getOverscanFrameLw()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2714 | } else { |
| 2715 | // If the window is resizing, then we want to base the content |
| 2716 | // frame on our attached content frame to resize... however, |
| 2717 | // things can be tricky if the attached window is NOT in resize |
| 2718 | // mode, in which case its content frame will be larger. |
| 2719 | // Ungh. So to deal with that, make sure the content frame |
| 2720 | // we end up using is not covering the IM dock. |
| 2721 | cf.set(attached.getContentFrameLw()); |
| 2722 | if (attached.getSurfaceLayer() < mDockLayer) { |
| 2723 | if (cf.left < mContentLeft) cf.left = mContentLeft; |
| 2724 | if (cf.top < mContentTop) cf.top = mContentTop; |
| 2725 | if (cf.right > mContentRight) cf.right = mContentRight; |
| 2726 | if (cf.bottom > mContentBottom) cf.bottom = mContentBottom; |
| 2727 | } |
| 2728 | } |
| 2729 | df.set(insetDecors ? attached.getDisplayFrameLw() : cf); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2730 | of.set(insetDecors ? attached.getOverscanFrameLw() : cf); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2731 | vf.set(attached.getVisibleFrameLw()); |
| 2732 | } |
| 2733 | // The LAYOUT_IN_SCREEN flag is used to determine whether the attached |
| 2734 | // window should be positioned relative to its parent or the entire |
| 2735 | // screen. |
| 2736 | pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0 |
| 2737 | ? attached.getFrameLw() : df); |
| 2738 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2739 | |
| 2740 | private void applyStableConstraints(int sysui, int fl, Rect r) { |
| 2741 | if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 2742 | // If app is requesting a stable layout, don't let the |
| 2743 | // content insets go below the stable values. |
| 2744 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 2745 | if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft; |
| 2746 | if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop; |
| 2747 | if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight; |
| 2748 | if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom; |
| 2749 | } else { |
| 2750 | if (r.left < mStableLeft) r.left = mStableLeft; |
| 2751 | if (r.top < mStableTop) r.top = mStableTop; |
| 2752 | if (r.right > mStableRight) r.right = mStableRight; |
| 2753 | if (r.bottom > mStableBottom) r.bottom = mStableBottom; |
| 2754 | } |
| 2755 | } |
| 2756 | } |
| 2757 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2758 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2759 | @Override |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 2760 | public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs, |
| 2761 | WindowState attached) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2762 | // we've already done the status bar |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2763 | if (win == mStatusBar || win == mNavigationBar) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2764 | return; |
| 2765 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2766 | final boolean isDefaultDisplay = win.isDefaultDisplay(); |
| 2767 | final boolean needsToOffsetInputMethodTarget = isDefaultDisplay && |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 2768 | (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null); |
| 2769 | if (needsToOffsetInputMethodTarget) { |
| 2770 | if (DEBUG_LAYOUT) { |
| 2771 | Slog.i(TAG, "Offset ime target window by the last ime window state"); |
| 2772 | } |
| 2773 | offsetInputMethodWindowLw(mLastInputMethodWindow); |
| 2774 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2775 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2776 | final int fl = attrs.flags; |
| 2777 | final int sim = attrs.softInputMode; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2778 | final int sysUiFl = win.getSystemUiVisibility(); |
| 2779 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2780 | final Rect pf = mTmpParentFrame; |
| 2781 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2782 | final Rect of = mTmpOverscanFrame; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2783 | final Rect cf = mTmpContentFrame; |
| 2784 | final Rect vf = mTmpVisibleFrame; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2785 | |
| 2786 | final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 2787 | && mNavigationBar != null && mNavigationBar.isVisibleLw()); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2788 | |
Craig Mautner | f683b56 | 2012-10-02 11:10:57 -0700 | [diff] [blame] | 2789 | final int adjust = sim & SOFT_INPUT_MASK_ADJUST; |
| 2790 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2791 | if (!isDefaultDisplay) { |
| 2792 | if (attached != null) { |
| 2793 | // If this window is attached to another, our display |
| 2794 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2795 | setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2796 | } else { |
| 2797 | // Give the window full screen. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2798 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 2799 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 2800 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2801 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2802 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2803 | = mOverscanScreenTop + mOverscanScreenHeight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2804 | } |
| 2805 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2806 | pf.left = df.left = of.left = cf.left = vf.left = mDockLeft; |
| 2807 | pf.top = df.top = of.top = cf.top = vf.top = mDockTop; |
| 2808 | pf.right = df.right = of.right = cf.right = vf.right = mDockRight; |
| 2809 | pf.bottom = df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2810 | // IM dock windows always go to the bottom of the screen. |
| 2811 | attrs.gravity = Gravity.BOTTOM; |
| 2812 | mDockLayer = win.getSurfaceLayer(); |
| 2813 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2814 | if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) |
| 2815 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2816 | if (DEBUG_LAYOUT) |
| 2817 | Log.v(TAG, "layoutWindowLw(" + attrs.getTitle() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2818 | + "): IN_SCREEN, INSET_DECOR"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2819 | // This is the case for a normal activity window: we want it |
| 2820 | // to cover all of the screen space, and it can take care of |
| 2821 | // moving its contents to account for screen decorations that |
| 2822 | // intrude into that space. |
| 2823 | if (attached != null) { |
| 2824 | // If this window is attached to another, our display |
| 2825 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2826 | 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] | 2827 | } else { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2828 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 2829 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2830 | // Status bar panels are the only windows who can go on top of |
| 2831 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 2832 | // permission, so they have the same privileges as the status |
| 2833 | // bar itself. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2834 | // |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 2835 | // However, they should still dodge the navigation bar if it exists. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2836 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2837 | pf.left = df.left = of.left = hasNavBar |
| 2838 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 2839 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 2840 | pf.right = df.right = of.right = hasNavBar |
| 2841 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
| 2842 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 2843 | pf.bottom = df.bottom = of.bottom = hasNavBar |
| 2844 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
| 2845 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2846 | |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 2847 | if (DEBUG_LAYOUT) { |
| 2848 | Log.v(TAG, String.format( |
| 2849 | "Laying out status bar window: (%d,%d - %d,%d)", |
| 2850 | pf.left, pf.top, pf.right, pf.bottom)); |
| 2851 | } |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2852 | } else if ((attrs.flags&FLAG_LAYOUT_IN_OVERSCAN) != 0 |
| 2853 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 2854 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 2855 | // Asking to layout into the overscan region, so give it that pure |
| 2856 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2857 | pf.left = df.left = of.left = mOverscanScreenLeft; |
| 2858 | pf.top = df.top = of.top = mOverscanScreenTop; |
| 2859 | pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 2860 | pf.bottom = df.bottom = of.bottom = mOverscanScreenTop |
| 2861 | + mOverscanScreenHeight; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2862 | } else if (mCanHideNavigationBar |
| 2863 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2864 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 2865 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 2866 | // Asking for layout as if the nav bar is hidden, lets the |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2867 | // application extend into the unrestricted overscan screen area. We |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2868 | // only do this for application windows to ensure no window that |
| 2869 | // can be above the nav bar can do this. |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 2870 | pf.left = df.left = mOverscanScreenLeft; |
| 2871 | pf.top = df.top = mOverscanScreenTop; |
| 2872 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 2873 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2874 | // We need to tell the app about where the frame inside the overscan |
| 2875 | // is, so it can inset its content by that amount -- it didn't ask |
| 2876 | // to actually extend itself into the overscan region. |
| 2877 | of.left = mUnrestrictedScreenLeft; |
| 2878 | of.top = mUnrestrictedScreenTop; |
| 2879 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 2880 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2881 | } else { |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 2882 | pf.left = df.left = mRestrictedOverscanScreenLeft; |
| 2883 | pf.top = df.top = mRestrictedOverscanScreenTop; |
| 2884 | pf.right = df.right = mRestrictedOverscanScreenLeft |
| 2885 | + mRestrictedOverscanScreenWidth; |
| 2886 | pf.bottom = df.bottom = mRestrictedOverscanScreenTop |
| 2887 | + mRestrictedOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2888 | // We need to tell the app about where the frame inside the overscan |
| 2889 | // is, so it can inset its content by that amount -- it didn't ask |
| 2890 | // to actually extend itself into the overscan region. |
| 2891 | of.left = mUnrestrictedScreenLeft; |
| 2892 | of.top = mUnrestrictedScreenTop; |
| 2893 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 2894 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2895 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2896 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2897 | if ((attrs.flags&FLAG_FULLSCREEN) == 0) { |
| 2898 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 2899 | cf.left = mDockLeft; |
| 2900 | cf.top = mDockTop; |
| 2901 | cf.right = mDockRight; |
| 2902 | cf.bottom = mDockBottom; |
| 2903 | } else { |
| 2904 | cf.left = mContentLeft; |
| 2905 | cf.top = mContentTop; |
| 2906 | cf.right = mContentRight; |
| 2907 | cf.bottom = mContentBottom; |
| 2908 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2909 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2910 | // Full screen windows are always given a layout that is as if the |
| 2911 | // status bar and other transient decors are gone. This is to avoid |
| 2912 | // bad states when moving from a window that is not hding the |
| 2913 | // status bar to one that is. |
| 2914 | cf.left = mRestrictedScreenLeft; |
| 2915 | cf.top = mRestrictedScreenTop; |
| 2916 | cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 2917 | cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2918 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2919 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2920 | applyStableConstraints(sysUiFl, fl, cf); |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 2921 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 2922 | vf.left = mCurLeft; |
| 2923 | vf.top = mCurTop; |
| 2924 | vf.right = mCurRight; |
| 2925 | vf.bottom = mCurBottom; |
| 2926 | } else { |
| 2927 | vf.set(cf); |
| 2928 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2929 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2930 | } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl |
| 2931 | & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 2932 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2933 | if (DEBUG_LAYOUT) |
| 2934 | Log.v(TAG, "layoutWindowLw(" + attrs.getTitle() + "): IN_SCREEN"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2935 | // A window that has requested to fill the entire screen just |
| 2936 | // gets everything, period. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2937 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 2938 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2939 | pf.left = df.left = of.left = cf.left = hasNavBar |
| 2940 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 2941 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 2942 | pf.right = df.right = of.right = cf.right = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 2943 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2944 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2945 | pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 2946 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2947 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 2948 | if (DEBUG_LAYOUT) { |
| 2949 | Log.v(TAG, String.format( |
| 2950 | "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)", |
| 2951 | pf.left, pf.top, pf.right, pf.bottom)); |
| 2952 | } |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 2953 | } else if (attrs.type == TYPE_NAVIGATION_BAR |
| 2954 | || attrs.type == TYPE_NAVIGATION_BAR_PANEL) { |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 2955 | // The navigation bar has Real Ultimate Power. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2956 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 2957 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 2958 | pf.right = df.right = of.right = mUnrestrictedScreenLeft |
| 2959 | + mUnrestrictedScreenWidth; |
| 2960 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop |
| 2961 | + mUnrestrictedScreenHeight; |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 2962 | if (DEBUG_LAYOUT) { |
| 2963 | Log.v(TAG, String.format( |
| 2964 | "Laying out navigation bar window: (%d,%d - %d,%d)", |
| 2965 | pf.left, pf.top, pf.right, pf.bottom)); |
| 2966 | } |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 2967 | } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY |
| 2968 | || attrs.type == TYPE_BOOT_PROGRESS) |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 2969 | && ((fl & FLAG_FULLSCREEN) != 0)) { |
| 2970 | // Fullscreen secure system overlays get what they ask for. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2971 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 2972 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 2973 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 2974 | + mOverscanScreenWidth; |
| 2975 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 2976 | + mOverscanScreenHeight; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 2977 | } else if (attrs.type == TYPE_BOOT_PROGRESS |
| 2978 | || attrs.type == TYPE_UNIVERSE_BACKGROUND) { |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 2979 | // Boot progress screen always covers entire display. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2980 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 2981 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 2982 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 2983 | + mOverscanScreenWidth; |
| 2984 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 2985 | + mOverscanScreenHeight; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 2986 | } else if (attrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER) { |
| 2987 | // The wallpaper mostly goes into the overscan region. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2988 | pf.left = df.left = of.left = cf.left = mRestrictedOverscanScreenLeft; |
| 2989 | pf.top = df.top = of.top = cf.top = mRestrictedOverscanScreenTop; |
| 2990 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 2991 | = mRestrictedOverscanScreenLeft + mRestrictedOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2992 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 2993 | = mRestrictedOverscanScreenTop + mRestrictedOverscanScreenHeight; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2994 | } else if ((attrs.flags & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
| 2995 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 2996 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 2997 | // Asking to layout into the overscan region, so give it that pure |
| 2998 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2999 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3000 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3001 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3002 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3003 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3004 | = mOverscanScreenTop + mOverscanScreenHeight; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3005 | } else if (mCanHideNavigationBar |
| 3006 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3007 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3008 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3009 | // Asking for layout as if the nav bar is hidden, lets the |
| 3010 | // application extend into the unrestricted screen area. We |
| 3011 | // only do this for application windows to ensure no window that |
| 3012 | // can be above the nav bar can do this. |
| 3013 | // XXX This assumes that an app asking for this will also |
| 3014 | // ask for layout in only content. We can't currently figure out |
| 3015 | // 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] | 3016 | pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft; |
| 3017 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 3018 | pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft |
| 3019 | + mUnrestrictedScreenWidth; |
| 3020 | pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop |
| 3021 | + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3022 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3023 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 3024 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 3025 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 3026 | + mRestrictedScreenWidth; |
| 3027 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 3028 | + mRestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3029 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3030 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3031 | applyStableConstraints(sysUiFl, fl, cf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3032 | |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3033 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3034 | vf.left = mCurLeft; |
| 3035 | vf.top = mCurTop; |
| 3036 | vf.right = mCurRight; |
| 3037 | vf.bottom = mCurBottom; |
| 3038 | } else { |
| 3039 | vf.set(cf); |
| 3040 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3041 | } else if (attached != null) { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3042 | if (DEBUG_LAYOUT) |
| 3043 | Log.v(TAG, "layoutWindowLw(" + attrs.getTitle() + "): attached to " + attached); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3044 | // A child window should be placed inside of the same visible |
| 3045 | // frame that its parent had. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3046 | 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] | 3047 | } else { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3048 | if (DEBUG_LAYOUT) |
| 3049 | Log.v(TAG, "layoutWindowLw(" + attrs.getTitle() + "): normal window"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3050 | // Otherwise, a normal window must be placed inside the content |
| 3051 | // of all screen decorations. |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3052 | if (attrs.type == TYPE_STATUS_BAR_PANEL) { |
| 3053 | // Status bar panels are the only windows who can go on top of |
| 3054 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 3055 | // permission, so they have the same privileges as the status |
| 3056 | // bar itself. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3057 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 3058 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 3059 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 3060 | + mRestrictedScreenWidth; |
| 3061 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 3062 | + mRestrictedScreenHeight; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3063 | } else { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3064 | pf.left = mContentLeft; |
| 3065 | pf.top = mContentTop; |
| 3066 | pf.right = mContentRight; |
| 3067 | pf.bottom = mContentBottom; |
| 3068 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3069 | df.left = of.left = cf.left = mDockLeft; |
| 3070 | df.top = of.top = cf.top = mDockTop; |
| 3071 | df.right = of.right = cf.right = mDockRight; |
| 3072 | df.bottom = of.bottom = cf.bottom = mDockBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3073 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3074 | df.left = of.left = cf.left = mContentLeft; |
| 3075 | df.top = of.top = cf.top = mContentTop; |
| 3076 | df.right = of.right = cf.right = mContentRight; |
| 3077 | df.bottom = of.bottom = cf.bottom = mContentBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3078 | } |
| 3079 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3080 | vf.left = mCurLeft; |
| 3081 | vf.top = mCurTop; |
| 3082 | vf.right = mCurRight; |
| 3083 | vf.bottom = mCurBottom; |
| 3084 | } else { |
| 3085 | vf.set(cf); |
| 3086 | } |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3087 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3088 | } |
| 3089 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3090 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3091 | if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3092 | df.left = df.top = of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000; |
| 3093 | df.right = df.bottom = of.right = of.bottom = cf.right = cf.bottom |
| 3094 | = vf.right = vf.bottom = 10000; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3095 | } |
| 3096 | |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 3097 | if (DEBUG_LAYOUT) Log.v(TAG, "Compute frame " + attrs.getTitle() |
| 3098 | + ": sim=#" + Integer.toHexString(sim) |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3099 | + " attach=" + attached + " type=" + attrs.type |
| 3100 | + String.format(" flags=0x%08x", fl) |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 3101 | + " pf=" + pf.toShortString() + " df=" + df.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3102 | + " of=" + of.toShortString() |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 3103 | + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3104 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3105 | win.computeFrameLw(pf, df, of, cf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3106 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3107 | // Dock windows carve out the bottom of the screen, so normal windows |
| 3108 | // can't appear underneath them. |
Craig Mautner | 8bd206b | 2012-10-03 10:32:02 -0700 | [diff] [blame] | 3109 | if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw() |
| 3110 | && !win.getGivenInsetsPendingLw()) { |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3111 | setLastInputMethodWindowLw(null, null); |
| 3112 | offsetInputMethodWindowLw(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3113 | } |
| 3114 | } |
| 3115 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3116 | private void offsetInputMethodWindowLw(WindowState win) { |
| 3117 | int top = win.getContentFrameLw().top; |
| 3118 | top += win.getGivenContentInsetsLw().top; |
| 3119 | if (mContentBottom > top) { |
| 3120 | mContentBottom = top; |
| 3121 | } |
| 3122 | top = win.getVisibleFrameLw().top; |
| 3123 | top += win.getGivenVisibleInsetsLw().top; |
| 3124 | if (mCurBottom > top) { |
| 3125 | mCurBottom = top; |
| 3126 | } |
| 3127 | if (DEBUG_LAYOUT) Log.v(TAG, "Input method: mDockBottom=" |
| 3128 | + mDockBottom + " mContentBottom=" |
| 3129 | + mContentBottom + " mCurBottom=" + mCurBottom); |
| 3130 | } |
| 3131 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3132 | /** {@inheritDoc} */ |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 3133 | @Override |
| 3134 | public void finishLayoutLw() { |
| 3135 | return; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3136 | } |
| 3137 | |
| 3138 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3139 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3140 | public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3141 | mTopFullscreenOpaqueWindowState = null; |
| 3142 | mForceStatusBar = false; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3143 | mForceStatusBarFromKeyguard = false; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 3144 | mForcingShowNavBar = false; |
| 3145 | mForcingShowNavBarLayer = -1; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3146 | |
| 3147 | mHideLockScreen = false; |
| 3148 | mAllowLockscreenWhenOn = false; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3149 | mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3150 | mShowingLockscreen = false; |
| 3151 | mShowingDream = false; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3152 | } |
| 3153 | |
| 3154 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3155 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3156 | public void applyPostLayoutPolicyLw(WindowState win, |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3157 | WindowManager.LayoutParams attrs) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 3158 | if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw=" |
| 3159 | + win.isVisibleOrBehindKeyguardLw()); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 3160 | if (mTopFullscreenOpaqueWindowState == null && (win.getAttrs().privateFlags |
| 3161 | &WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_SHOW_NAV_BAR) != 0) { |
| 3162 | if (mForcingShowNavBarLayer < 0) { |
| 3163 | mForcingShowNavBar = true; |
| 3164 | mForcingShowNavBarLayer = win.getSurfaceLayer(); |
| 3165 | } |
| 3166 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3167 | if (mTopFullscreenOpaqueWindowState == null && |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 3168 | win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3169 | if ((attrs.flags & FLAG_FORCE_NOT_FULLSCREEN) != 0) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3170 | if (attrs.type == TYPE_KEYGUARD) { |
| 3171 | mForceStatusBarFromKeyguard = true; |
| 3172 | } else { |
| 3173 | mForceStatusBar = true; |
| 3174 | } |
| 3175 | } |
| 3176 | if (attrs.type == TYPE_KEYGUARD) { |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3177 | mShowingLockscreen = true; |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 3178 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3179 | boolean applyWindow = attrs.type >= FIRST_APPLICATION_WINDOW |
| 3180 | && attrs.type <= LAST_APPLICATION_WINDOW; |
| 3181 | if (attrs.type == TYPE_DREAM) { |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 3182 | // If the lockscreen was showing when the dream started then wait |
| 3183 | // for the dream to draw before hiding the lockscreen. |
| 3184 | if (!mDreamingLockscreen |
| 3185 | || (win.isVisibleLw() && win.hasDrawnLw())) { |
| 3186 | mShowingDream = true; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3187 | applyWindow = true; |
| 3188 | } |
| 3189 | } |
| 3190 | if (applyWindow |
Dianne Hackborn | 6493e64 | 2010-10-01 13:06:30 -0700 | [diff] [blame] | 3191 | && attrs.x == 0 && attrs.y == 0 |
| 3192 | && attrs.width == WindowManager.LayoutParams.MATCH_PARENT |
| 3193 | && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3194 | if (DEBUG_LAYOUT) Log.v(TAG, "Fullscreen window: " + win); |
| 3195 | mTopFullscreenOpaqueWindowState = win; |
| 3196 | if ((attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3197 | if (DEBUG_LAYOUT) Log.v(TAG, "Setting mHideLockScreen to true by win " + win); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3198 | mHideLockScreen = true; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3199 | mForceStatusBarFromKeyguard = false; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3200 | } |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3201 | if ((attrs.flags & FLAG_DISMISS_KEYGUARD) != 0 |
| 3202 | && mDismissKeyguard == DISMISS_KEYGUARD_NONE) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3203 | if (DEBUG_LAYOUT) Log.v(TAG, "Setting mDismissKeyguard to true by win " + win); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3204 | mDismissKeyguard = mWinDismissingKeyguard == win ? |
| 3205 | DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START; |
| 3206 | mWinDismissingKeyguard = win; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3207 | mForceStatusBarFromKeyguard = false; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3208 | } |
| 3209 | if ((attrs.flags & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) { |
| 3210 | mAllowLockscreenWhenOn = true; |
| 3211 | } |
| 3212 | } |
| 3213 | } |
| 3214 | } |
| 3215 | |
| 3216 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3217 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3218 | public int finishPostLayoutPolicyLw() { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3219 | int changes = 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3220 | boolean topIsFullscreen = false; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 3221 | |
| 3222 | final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null) |
| 3223 | ? mTopFullscreenOpaqueWindowState.getAttrs() |
| 3224 | : null; |
| 3225 | |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 3226 | // If we are not currently showing a dream then remember the current |
| 3227 | // lockscreen state. We will use this to determine whether the dream |
| 3228 | // started while the lockscreen was showing and remember this state |
| 3229 | // while the dream is showing. |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3230 | if (!mShowingDream) { |
| 3231 | mDreamingLockscreen = mShowingLockscreen; |
| 3232 | } |
| 3233 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3234 | if (mStatusBar != null) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 3235 | if (DEBUG_LAYOUT) Log.i(TAG, "force=" + mForceStatusBar |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3236 | + " forcefkg=" + mForceStatusBarFromKeyguard |
Dianne Hackborn | d70bc2f | 2009-10-06 23:25:51 -0700 | [diff] [blame] | 3237 | + " top=" + mTopFullscreenOpaqueWindowState); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3238 | if (mForceStatusBar || mForceStatusBarFromKeyguard) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 3239 | if (DEBUG_LAYOUT) Log.v(TAG, "Showing status bar: forced"); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3240 | if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3241 | } else if (mTopFullscreenOpaqueWindowState != null) { |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3242 | if (localLOGV) { |
| 3243 | Log.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw() |
| 3244 | + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw()); |
| 3245 | Log.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs() |
| 3246 | + " lp.flags=0x" + Integer.toHexString(lp.flags)); |
| 3247 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3248 | topIsFullscreen = (lp.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0 |
| 3249 | || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3250 | // The subtle difference between the window for mTopFullscreenOpaqueWindowState |
| 3251 | // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window |
| 3252 | // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the |
| 3253 | // case though. |
| 3254 | if (topIsFullscreen) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3255 | if (DEBUG_LAYOUT) Log.v(TAG, "** HIDING status bar"); |
| 3256 | if (mStatusBar.hideLw(true)) { |
| 3257 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
Daniel Sandler | 9c00d5b | 2011-09-13 14:04:26 -0400 | [diff] [blame] | 3258 | |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3259 | mHandler.post(new Runnable() { |
| 3260 | @Override |
| 3261 | public void run() { |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3262 | try { |
| 3263 | IStatusBarService statusbar = getStatusBarService(); |
| 3264 | if (statusbar != null) { |
Daniel Sandler | 11cf178 | 2012-09-27 14:03:08 -0400 | [diff] [blame] | 3265 | statusbar.collapsePanels(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3266 | } |
| 3267 | } catch (RemoteException ex) { |
| 3268 | // re-acquire status bar service next time it is needed. |
| 3269 | mStatusBarService = null; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3270 | } |
| 3271 | }}); |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 3272 | } else if (DEBUG_LAYOUT) { |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 3273 | Log.v(TAG, "Preventing status bar from hiding by policy"); |
| 3274 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3275 | } else { |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 3276 | if (DEBUG_LAYOUT) Log.v(TAG, "** SHOWING status bar: top is not fullscreen"); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3277 | if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3278 | } |
| 3279 | } |
| 3280 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 3281 | |
Joe Onorato | 644f9c3 | 2011-01-25 12:06:23 -0800 | [diff] [blame] | 3282 | mTopIsFullscreen = topIsFullscreen; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 3283 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3284 | // Hide the key guard if a visible window explicitly specifies that it wants to be |
| 3285 | // displayed when the screen is locked. |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 3286 | if (mKeyguard != null) { |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3287 | if (localLOGV) Log.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard=" |
| 3288 | + mHideLockScreen); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3289 | if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardMediator.isSecure()) { |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3290 | if (mKeyguard.hideLw(true)) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3291 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3292 | | FINISH_LAYOUT_REDO_CONFIG |
| 3293 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3294 | } |
Dianne Hackborn | 0572658 | 2009-09-22 17:28:24 -0700 | [diff] [blame] | 3295 | if (mKeyguardMediator.isShowing()) { |
Dianne Hackborn | b446e97 | 2009-09-20 15:23:25 -0700 | [diff] [blame] | 3296 | mHandler.post(new Runnable() { |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3297 | @Override |
Dianne Hackborn | b446e97 | 2009-09-20 15:23:25 -0700 | [diff] [blame] | 3298 | public void run() { |
Dianne Hackborn | 0572658 | 2009-09-22 17:28:24 -0700 | [diff] [blame] | 3299 | mKeyguardMediator.keyguardDone(false, false); |
Dianne Hackborn | b446e97 | 2009-09-20 15:23:25 -0700 | [diff] [blame] | 3300 | } |
| 3301 | }); |
| 3302 | } |
Dianne Hackborn | 0572658 | 2009-09-22 17:28:24 -0700 | [diff] [blame] | 3303 | } else if (mHideLockScreen) { |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3304 | if (mKeyguard.hideLw(true)) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3305 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3306 | | FINISH_LAYOUT_REDO_CONFIG |
| 3307 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3308 | } |
Mike Lockwood | f3bfed5 | 2010-01-21 16:38:44 -0500 | [diff] [blame] | 3309 | mKeyguardMediator.setHidden(true); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3310 | } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) { |
| 3311 | // This is the case of keyguard isSecure() and not mHideLockScreen. |
| 3312 | if (mDismissKeyguard == DISMISS_KEYGUARD_START) { |
| 3313 | // Only launch the next keyguard unlock window once per window. |
| 3314 | if (mKeyguard.showLw(true)) { |
| 3315 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3316 | | FINISH_LAYOUT_REDO_CONFIG |
| 3317 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3318 | } |
| 3319 | mKeyguardMediator.setHidden(false); |
| 3320 | mHandler.post(new Runnable() { |
| 3321 | @Override |
| 3322 | public void run() { |
| 3323 | mKeyguardMediator.dismiss(); |
| 3324 | } |
| 3325 | }); |
| 3326 | } |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 3327 | } else { |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3328 | mWinDismissingKeyguard = null; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3329 | if (mKeyguard.showLw(true)) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3330 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3331 | | FINISH_LAYOUT_REDO_CONFIG |
| 3332 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3333 | } |
Mike Lockwood | f3bfed5 | 2010-01-21 16:38:44 -0500 | [diff] [blame] | 3334 | mKeyguardMediator.setHidden(false); |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 3335 | } |
| 3336 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 3337 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3338 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3339 | // If the navigation bar has been hidden or shown, we need to do another |
| 3340 | // layout pass to update that window. |
| 3341 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 3342 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 3343 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 3344 | // update since mAllowLockscreenWhenOn might have changed |
| 3345 | updateLockScreenTimeout(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3346 | return changes; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3347 | } |
| 3348 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3349 | public boolean allowAppAnimationsLw() { |
Craig Mautner | f03e4c5 | 2012-06-14 14:11:27 -0700 | [diff] [blame] | 3350 | if (mKeyguard != null && mKeyguard.isVisibleLw() && !mKeyguard.isAnimatingLw()) { |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3351 | // If keyguard is currently visible, no reason to animate |
| 3352 | // behind it. |
| 3353 | return false; |
| 3354 | } |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3355 | return true; |
| 3356 | } |
| 3357 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3358 | public int focusChangedLw(WindowState lastFocus, WindowState newFocus) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 3359 | mFocusedWindow = newFocus; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3360 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3361 | // If the navigation bar has been hidden or shown, we need to do another |
| 3362 | // layout pass to update that window. |
| 3363 | return FINISH_LAYOUT_REDO_LAYOUT; |
| 3364 | } |
| 3365 | return 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 3366 | } |
| 3367 | |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 3368 | /** {@inheritDoc} */ |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3369 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 3370 | // do nothing if headless |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 3371 | if (mHeadless) return; |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 3372 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3373 | // lid changed state |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 3374 | final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED; |
| 3375 | if (newLidState == mLidState) { |
| 3376 | return; |
| 3377 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 3378 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 3379 | mLidState = newLidState; |
| 3380 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 3381 | updateRotation(true); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 3382 | |
| 3383 | if (lidOpen) { |
| 3384 | if (keyguardIsShowingTq()) { |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 3385 | mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(KeyEvent.KEYCODE_POWER); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3386 | } else { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3387 | mPowerManager.wakeUp(SystemClock.uptimeMillis()); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3388 | } |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 3389 | } else if (!mLidControlsSleep) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3390 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3391 | } |
| 3392 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3393 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 3394 | void setHdmiPlugged(boolean plugged) { |
| 3395 | if (mHdmiPlugged != plugged) { |
| 3396 | mHdmiPlugged = plugged; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3397 | updateRotation(true, true); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 3398 | Intent intent = new Intent(ACTION_HDMI_PLUGGED); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 3399 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 3400 | intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 3401 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 3402 | } |
| 3403 | } |
| 3404 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 3405 | void initializeHdmiState() { |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 3406 | boolean plugged = false; |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 3407 | // watch for HDMI plug messages if the hdmi switch exists |
| 3408 | if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) { |
| 3409 | mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi"); |
| 3410 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 3411 | final String filename = "/sys/class/switch/hdmi/state"; |
| 3412 | FileReader reader = null; |
| 3413 | try { |
| 3414 | reader = new FileReader(filename); |
| 3415 | char[] buf = new char[15]; |
| 3416 | int n = reader.read(buf); |
| 3417 | if (n > 1) { |
| 3418 | plugged = 0 != Integer.parseInt(new String(buf, 0, n-1)); |
| 3419 | } |
| 3420 | } catch (IOException ex) { |
| 3421 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 3422 | } catch (NumberFormatException ex) { |
| 3423 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 3424 | } finally { |
| 3425 | if (reader != null) { |
| 3426 | try { |
| 3427 | reader.close(); |
| 3428 | } catch (IOException ex) { |
| 3429 | } |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 3430 | } |
| 3431 | } |
| 3432 | } |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 3433 | // This dance forces the code in setHdmiPlugged to run. |
| 3434 | // Always do this so the sticky intent is stuck (to false) if there is no hdmi. |
| 3435 | mHdmiPlugged = !plugged; |
| 3436 | setHdmiPlugged(!mHdmiPlugged); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 3437 | } |
| 3438 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3439 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3440 | * @return Whether music is being played right now. |
| 3441 | */ |
| 3442 | boolean isMusicActive() { |
Eric Laurent | 413cb9d | 2009-07-17 11:52:43 -0700 | [diff] [blame] | 3443 | final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE); |
| 3444 | if (am == null) { |
| 3445 | Log.w(TAG, "isMusicActive: couldn't get AudioManager reference"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3446 | return false; |
| 3447 | } |
Eric Laurent | 413cb9d | 2009-07-17 11:52:43 -0700 | [diff] [blame] | 3448 | return am.isMusicActive(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3449 | } |
| 3450 | |
| 3451 | /** |
| 3452 | * Tell the audio service to adjust the volume appropriate to the event. |
| 3453 | * @param keycode |
| 3454 | */ |
Mike Lockwood | a53e381 | 2009-09-25 10:51:39 -0400 | [diff] [blame] | 3455 | void handleVolumeKey(int stream, int keycode) { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3456 | IAudioService audioService = getAudioService(); |
| 3457 | if (audioService == null) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3458 | return; |
| 3459 | } |
| 3460 | try { |
| 3461 | // since audio is playing, we shouldn't have to hold a wake lock |
| 3462 | // during the call, but we do it as a precaution for the rare possibility |
| 3463 | // that the music stops right before we call this |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 3464 | // TODO: Actually handle MUTE. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3465 | mBroadcastWakeLock.acquire(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3466 | audioService.adjustStreamVolume(stream, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3467 | keycode == KeyEvent.KEYCODE_VOLUME_UP |
| 3468 | ? AudioManager.ADJUST_RAISE |
| 3469 | : AudioManager.ADJUST_LOWER, |
| 3470 | 0); |
| 3471 | } catch (RemoteException e) { |
| 3472 | Log.w(TAG, "IAudioService.adjustStreamVolume() threw RemoteException " + e); |
| 3473 | } finally { |
| 3474 | mBroadcastWakeLock.release(); |
| 3475 | } |
| 3476 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3477 | |
Dianne Hackborn | c0e3f24 | 2011-08-19 14:19:10 -0700 | [diff] [blame] | 3478 | final Object mScreenshotLock = new Object(); |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 3479 | ServiceConnection mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 3480 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3481 | final Runnable mScreenshotTimeout = new Runnable() { |
| 3482 | @Override public void run() { |
| 3483 | synchronized (mScreenshotLock) { |
| 3484 | if (mScreenshotConnection != null) { |
| 3485 | mContext.unbindService(mScreenshotConnection); |
| 3486 | mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 3487 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 3488 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3489 | } |
| 3490 | }; |
| 3491 | |
| 3492 | // Assume this is called from the Handler thread. |
| 3493 | private void takeScreenshot() { |
| 3494 | synchronized (mScreenshotLock) { |
| 3495 | if (mScreenshotConnection != null) { |
| 3496 | return; |
| 3497 | } |
| 3498 | ComponentName cn = new ComponentName("com.android.systemui", |
| 3499 | "com.android.systemui.screenshot.TakeScreenshotService"); |
| 3500 | Intent intent = new Intent(); |
| 3501 | intent.setComponent(cn); |
| 3502 | ServiceConnection conn = new ServiceConnection() { |
| 3503 | @Override |
| 3504 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 3505 | synchronized (mScreenshotLock) { |
| 3506 | if (mScreenshotConnection != this) { |
| 3507 | return; |
| 3508 | } |
| 3509 | Messenger messenger = new Messenger(service); |
| 3510 | Message msg = Message.obtain(null, 1); |
| 3511 | final ServiceConnection myConn = this; |
| 3512 | Handler h = new Handler(mHandler.getLooper()) { |
| 3513 | @Override |
| 3514 | public void handleMessage(Message msg) { |
| 3515 | synchronized (mScreenshotLock) { |
| 3516 | if (mScreenshotConnection == myConn) { |
| 3517 | mContext.unbindService(mScreenshotConnection); |
| 3518 | mScreenshotConnection = null; |
| 3519 | mHandler.removeCallbacks(mScreenshotTimeout); |
| 3520 | } |
| 3521 | } |
| 3522 | } |
| 3523 | }; |
| 3524 | msg.replyTo = new Messenger(h); |
Winson Chung | a63bb84 | 2011-10-17 10:26:28 -0700 | [diff] [blame] | 3525 | msg.arg1 = msg.arg2 = 0; |
| 3526 | if (mStatusBar != null && mStatusBar.isVisibleLw()) |
| 3527 | msg.arg1 = 1; |
| 3528 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) |
| 3529 | msg.arg2 = 1; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3530 | try { |
| 3531 | messenger.send(msg); |
| 3532 | } catch (RemoteException e) { |
| 3533 | } |
| 3534 | } |
| 3535 | } |
| 3536 | @Override |
| 3537 | public void onServiceDisconnected(ComponentName name) {} |
| 3538 | }; |
Amith Yamasani | 27b89e6 | 2013-01-16 12:30:11 -0800 | [diff] [blame] | 3539 | if (mContext.bindServiceAsUser( |
| 3540 | intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3541 | mScreenshotConnection = conn; |
| 3542 | mHandler.postDelayed(mScreenshotTimeout, 10000); |
| 3543 | } |
| 3544 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 3545 | } |
| 3546 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3547 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3548 | @Override |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 3549 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3550 | if (!mSystemBooted) { |
| 3551 | // If we have not yet booted, don't let key events do anything. |
| 3552 | return 0; |
| 3553 | } |
| 3554 | |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 3555 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 3556 | final boolean canceled = event.isCanceled(); |
| 3557 | final int keyCode = event.getKeyCode(); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 3558 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 3559 | final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 3560 | |
Mike Lockwood | c72b15f | 2009-11-28 20:58:22 -0500 | [diff] [blame] | 3561 | // If screen is off then we treat the case where the keyguard is open but hidden |
| 3562 | // the same as if it were open and in front. |
| 3563 | // This will prevent any keys other than the power button from waking the screen |
| 3564 | // when the keyguard is hidden by another activity. |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 3565 | final boolean keyguardActive = (mKeyguardMediator == null ? false : |
| 3566 | (isScreenOn ? |
| 3567 | mKeyguardMediator.isShowingAndNotHidden() : |
| 3568 | mKeyguardMediator.isShowing())); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3569 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3570 | if (keyCode == KeyEvent.KEYCODE_POWER) { |
| 3571 | policyFlags |= WindowManagerPolicy.FLAG_WAKE; |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 3572 | } |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3573 | final boolean isWakeKey = (policyFlags & (WindowManagerPolicy.FLAG_WAKE |
| 3574 | | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0; |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 3575 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3576 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3577 | Log.d(TAG, "interceptKeyTq keycode=" + keyCode |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3578 | + " screenIsOn=" + isScreenOn + " keyguardActive=" + keyguardActive |
| 3579 | + " policyFlags=" + Integer.toHexString(policyFlags) |
| 3580 | + " isWakeKey=" + isWakeKey); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3581 | } |
| 3582 | |
Jeff Brown | 98392ef | 2011-09-12 18:24:59 -0700 | [diff] [blame] | 3583 | if (down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0 |
| 3584 | && event.getRepeatCount() == 0) { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3585 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 3586 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3587 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3588 | // Basic policy based on screen state and keyguard. |
| 3589 | // FIXME: This policy isn't quite correct. We shouldn't care whether the screen |
| 3590 | // is on or off, really. We should care about whether the device is in an |
| 3591 | // interactive state or is in suspend pretending to be "off". |
| 3592 | // The primary screen might be turned off due to proximity sensor or |
| 3593 | // because we are presenting media on an auxiliary screen or remotely controlling |
| 3594 | // the device some other way (which is why we have an exemption here for injected |
| 3595 | // events). |
| 3596 | int result; |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 3597 | if ((isScreenOn && !mHeadless) || (isInjected && !isWakeKey)) { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3598 | // When the screen is on or if the key is injected pass the key to the application. |
| 3599 | result = ACTION_PASS_TO_USER; |
| 3600 | } else { |
| 3601 | // When the screen is off and the key is not injected, determine whether |
| 3602 | // to wake the device but don't pass the key to the application. |
| 3603 | result = 0; |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 3604 | if (down && isWakeKey && isWakeKeyWhenScreenOff(keyCode)) { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3605 | if (keyguardActive) { |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 3606 | // If the keyguard is showing, let it wake the device when ready. |
| 3607 | mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(keyCode); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3608 | } else { |
| 3609 | // Otherwise, wake the device ourselves. |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3610 | result |= ACTION_WAKE_UP; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3611 | } |
| 3612 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3613 | } |
| 3614 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 3615 | // If the key would be handled globally, just return the result, don't worry about special |
| 3616 | // key processing. |
| 3617 | if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) { |
| 3618 | return result; |
| 3619 | } |
| 3620 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3621 | // Handle special keys. |
| 3622 | switch (keyCode) { |
| 3623 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 3624 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 3625 | case KeyEvent.KEYCODE_VOLUME_MUTE: { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3626 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { |
| 3627 | if (down) { |
| 3628 | if (isScreenOn && !mVolumeDownKeyTriggered |
| 3629 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 3630 | mVolumeDownKeyTriggered = true; |
| 3631 | mVolumeDownKeyTime = event.getDownTime(); |
| 3632 | mVolumeDownKeyConsumedByScreenshotChord = false; |
| 3633 | cancelPendingPowerKeyAction(); |
| 3634 | interceptScreenshotChord(); |
| 3635 | } |
| 3636 | } else { |
| 3637 | mVolumeDownKeyTriggered = false; |
| 3638 | cancelPendingScreenshotChordAction(); |
| 3639 | } |
| 3640 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { |
| 3641 | if (down) { |
| 3642 | if (isScreenOn && !mVolumeUpKeyTriggered |
| 3643 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 3644 | mVolumeUpKeyTriggered = true; |
| 3645 | cancelPendingPowerKeyAction(); |
| 3646 | cancelPendingScreenshotChordAction(); |
| 3647 | } |
| 3648 | } else { |
| 3649 | mVolumeUpKeyTriggered = false; |
| 3650 | cancelPendingScreenshotChordAction(); |
| 3651 | } |
| 3652 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3653 | if (down) { |
| 3654 | ITelephony telephonyService = getTelephonyService(); |
| 3655 | if (telephonyService != null) { |
| 3656 | try { |
| 3657 | if (telephonyService.isRinging()) { |
| 3658 | // If an incoming call is ringing, either VOLUME key means |
| 3659 | // "silence ringer". We handle these keys here, rather than |
| 3660 | // in the InCallScreen, to make sure we'll respond to them |
| 3661 | // even if the InCallScreen hasn't come to the foreground yet. |
| 3662 | // Look for the DOWN event here, to agree with the "fallback" |
| 3663 | // behavior in the InCallScreen. |
| 3664 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 3665 | + " VOLUME key-down while ringing: Silence ringer!"); |
| 3666 | |
| 3667 | // Silence the ringer. (It's safe to call this |
| 3668 | // even if the ringer has already been silenced.) |
| 3669 | telephonyService.silenceRinger(); |
| 3670 | |
| 3671 | // And *don't* pass this key thru to the current activity |
| 3672 | // (which is probably the InCallScreen.) |
| 3673 | result &= ~ACTION_PASS_TO_USER; |
| 3674 | break; |
| 3675 | } |
| 3676 | if (telephonyService.isOffhook() |
| 3677 | && (result & ACTION_PASS_TO_USER) == 0) { |
| 3678 | // If we are in call but we decided not to pass the key to |
| 3679 | // the application, handle the volume change here. |
| 3680 | handleVolumeKey(AudioManager.STREAM_VOICE_CALL, keyCode); |
| 3681 | break; |
| 3682 | } |
| 3683 | } catch (RemoteException ex) { |
| 3684 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
| 3685 | } |
| 3686 | } |
| 3687 | |
| 3688 | if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) { |
| 3689 | // If music is playing but we decided not to pass the key to the |
| 3690 | // application, handle the volume change here. |
| 3691 | handleVolumeKey(AudioManager.STREAM_MUSIC, keyCode); |
| 3692 | break; |
| 3693 | } |
| 3694 | } |
| 3695 | break; |
| 3696 | } |
| 3697 | |
| 3698 | case KeyEvent.KEYCODE_ENDCALL: { |
| 3699 | result &= ~ACTION_PASS_TO_USER; |
| 3700 | if (down) { |
| 3701 | ITelephony telephonyService = getTelephonyService(); |
| 3702 | boolean hungUp = false; |
| 3703 | if (telephonyService != null) { |
| 3704 | try { |
| 3705 | hungUp = telephonyService.endCall(); |
| 3706 | } catch (RemoteException ex) { |
| 3707 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
| 3708 | } |
| 3709 | } |
| 3710 | interceptPowerKeyDown(!isScreenOn || hungUp); |
| 3711 | } else { |
| 3712 | if (interceptPowerKeyUp(canceled)) { |
| 3713 | if ((mEndcallBehavior |
| 3714 | & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) { |
| 3715 | if (goHome()) { |
| 3716 | break; |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 3717 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3718 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3719 | if ((mEndcallBehavior |
| 3720 | & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3721 | result = (result & ~ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3722 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3723 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3724 | } |
| 3725 | break; |
| 3726 | } |
| 3727 | |
| 3728 | case KeyEvent.KEYCODE_POWER: { |
| 3729 | result &= ~ACTION_PASS_TO_USER; |
| 3730 | if (down) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3731 | if (isScreenOn && !mPowerKeyTriggered |
| 3732 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 3733 | mPowerKeyTriggered = true; |
| 3734 | mPowerKeyTime = event.getDownTime(); |
| 3735 | interceptScreenshotChord(); |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 3736 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 3737 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3738 | ITelephony telephonyService = getTelephonyService(); |
| 3739 | boolean hungUp = false; |
| 3740 | if (telephonyService != null) { |
| 3741 | try { |
| 3742 | if (telephonyService.isRinging()) { |
| 3743 | // Pressing Power while there's a ringing incoming |
| 3744 | // call should silence the ringer. |
| 3745 | telephonyService.silenceRinger(); |
| 3746 | } else if ((mIncallPowerBehavior |
| 3747 | & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 |
| 3748 | && telephonyService.isOffhook()) { |
| 3749 | // Otherwise, if "Power button ends call" is enabled, |
| 3750 | // the Power button will hang up any current active call. |
| 3751 | hungUp = telephonyService.endCall(); |
| 3752 | } |
| 3753 | } catch (RemoteException ex) { |
| 3754 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
| 3755 | } |
| 3756 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3757 | interceptPowerKeyDown(!isScreenOn || hungUp |
| 3758 | || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3759 | } else { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3760 | mPowerKeyTriggered = false; |
| 3761 | cancelPendingScreenshotChordAction(); |
| 3762 | if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3763 | result = (result & ~ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3764 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3765 | mPendingPowerKeyUpCanceled = false; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3766 | } |
| 3767 | break; |
| 3768 | } |
| 3769 | |
| 3770 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 3771 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 3772 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 3773 | if (down) { |
| 3774 | ITelephony telephonyService = getTelephonyService(); |
| 3775 | if (telephonyService != null) { |
| 3776 | try { |
| 3777 | if (!telephonyService.isIdle()) { |
| 3778 | // Suppress PLAY/PAUSE toggle when phone is ringing or in-call |
| 3779 | // to avoid music playback. |
| 3780 | break; |
| 3781 | } |
| 3782 | } catch (RemoteException ex) { |
| 3783 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 3784 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3785 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3786 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3787 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 3788 | case KeyEvent.KEYCODE_MUTE: |
| 3789 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 3790 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 3791 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 3792 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 3793 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
| 3794 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: { |
| 3795 | if ((result & ACTION_PASS_TO_USER) == 0) { |
| 3796 | // Only do this if we would otherwise not pass it to the user. In that |
| 3797 | // case, the PhoneWindow class will do the same thing, except it will |
| 3798 | // 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] | 3799 | // Note that we need to make a copy of the key event here because the |
| 3800 | // original key event will be recycled when we return. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3801 | mBroadcastWakeLock.acquire(); |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3802 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK, |
| 3803 | new KeyEvent(event)); |
| 3804 | msg.setAsynchronous(true); |
| 3805 | msg.sendToTarget(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3806 | } |
| 3807 | break; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3808 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3809 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3810 | case KeyEvent.KEYCODE_CALL: { |
| 3811 | if (down) { |
| 3812 | ITelephony telephonyService = getTelephonyService(); |
| 3813 | if (telephonyService != null) { |
| 3814 | try { |
| 3815 | if (telephonyService.isRinging()) { |
| 3816 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 3817 | + " CALL key-down while ringing: Answer the call!"); |
| 3818 | telephonyService.answerRingingCall(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3819 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3820 | // And *don't* pass this key thru to the current activity |
| 3821 | // (which is presumably the InCallScreen.) |
| 3822 | result &= ~ACTION_PASS_TO_USER; |
| 3823 | } |
| 3824 | } catch (RemoteException ex) { |
| 3825 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3826 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3827 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3828 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3829 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3830 | } |
| 3831 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3832 | return result; |
| 3833 | } |
| 3834 | |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 3835 | /** |
| 3836 | * When the screen is off we ignore some keys that might otherwise typically |
| 3837 | * be considered wake keys. We filter them out here. |
| 3838 | * |
| 3839 | * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it |
| 3840 | * is always considered a wake key. |
| 3841 | */ |
| 3842 | private boolean isWakeKeyWhenScreenOff(int keyCode) { |
| 3843 | switch (keyCode) { |
| 3844 | // ignore volume keys unless docked |
| 3845 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 3846 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 3847 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 3848 | return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 3849 | |
| 3850 | // ignore media and camera keys |
| 3851 | case KeyEvent.KEYCODE_MUTE: |
| 3852 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 3853 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 3854 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 3855 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 3856 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 3857 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 3858 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 3859 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 3860 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
| 3861 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
| 3862 | case KeyEvent.KEYCODE_CAMERA: |
| 3863 | return false; |
| 3864 | } |
| 3865 | return true; |
| 3866 | } |
| 3867 | |
| 3868 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 3869 | /** {@inheritDoc} */ |
| 3870 | @Override |
| 3871 | public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) { |
| 3872 | int result = 0; |
| 3873 | |
| 3874 | final boolean isWakeMotion = (policyFlags |
| 3875 | & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0; |
| 3876 | if (isWakeMotion) { |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 3877 | if (mKeyguardMediator != null && mKeyguardMediator.isShowing()) { |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 3878 | // If the keyguard is showing, let it decide what to do with the wake motion. |
| 3879 | mKeyguardMediator.onWakeMotionWhenKeyguardShowingTq(); |
| 3880 | } else { |
| 3881 | // Otherwise, wake the device ourselves. |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3882 | result |= ACTION_WAKE_UP; |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 3883 | } |
| 3884 | } |
| 3885 | return result; |
| 3886 | } |
| 3887 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3888 | void dispatchMediaKeyWithWakeLock(KeyEvent event) { |
| 3889 | if (DEBUG_INPUT) { |
| 3890 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3891 | } |
| 3892 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3893 | if (mHavePendingMediaKeyRepeatWithWakeLock) { |
| 3894 | if (DEBUG_INPUT) { |
| 3895 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat"); |
| 3896 | } |
| 3897 | |
| 3898 | mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK); |
| 3899 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 3900 | mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock |
| 3901 | } |
| 3902 | |
| 3903 | dispatchMediaKeyWithWakeLockToAudioService(event); |
| 3904 | |
| 3905 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 3906 | && event.getRepeatCount() == 0) { |
| 3907 | mHavePendingMediaKeyRepeatWithWakeLock = true; |
| 3908 | |
| 3909 | Message msg = mHandler.obtainMessage( |
| 3910 | MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event); |
| 3911 | msg.setAsynchronous(true); |
| 3912 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout()); |
| 3913 | } else { |
| 3914 | mBroadcastWakeLock.release(); |
| 3915 | } |
| 3916 | } |
| 3917 | |
| 3918 | void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) { |
| 3919 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 3920 | |
| 3921 | KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event, |
| 3922 | SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 3923 | if (DEBUG_INPUT) { |
| 3924 | Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent); |
| 3925 | } |
| 3926 | |
| 3927 | dispatchMediaKeyWithWakeLockToAudioService(repeatEvent); |
| 3928 | mBroadcastWakeLock.release(); |
| 3929 | } |
| 3930 | |
| 3931 | void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) { |
| 3932 | if (ActivityManagerNative.isSystemReady()) { |
| 3933 | IAudioService audioService = getAudioService(); |
| 3934 | if (audioService != null) { |
| 3935 | try { |
| 3936 | audioService.dispatchMediaKeyEventUnderWakelock(event); |
| 3937 | } catch (RemoteException e) { |
| 3938 | Log.e(TAG, "dispatchMediaKeyEvent threw exception " + e); |
Jean-Michel Trivi | c680222 | 2012-04-30 11:15:03 -0700 | [diff] [blame] | 3939 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3940 | } |
| 3941 | } |
| 3942 | } |
| 3943 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 3944 | BroadcastReceiver mDockReceiver = new BroadcastReceiver() { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 3945 | @Override |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 3946 | public void onReceive(Context context, Intent intent) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 3947 | if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) { |
| 3948 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 3949 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
Dianne Hackborn | 80fa166 | 2009-10-07 14:02:10 -0700 | [diff] [blame] | 3950 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 3951 | updateRotation(true); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 3952 | synchronized (mLock) { |
| 3953 | updateOrientationListenerLp(); |
| 3954 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 3955 | } |
| 3956 | }; |
| 3957 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 3958 | BroadcastReceiver mDreamReceiver = new BroadcastReceiver() { |
| 3959 | @Override |
| 3960 | public void onReceive(Context context, Intent intent) { |
| 3961 | if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) { |
| 3962 | if (mKeyguardMediator != null) { |
| 3963 | mKeyguardMediator.onDreamingStarted(); |
| 3964 | } |
| 3965 | } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) { |
| 3966 | if (mKeyguardMediator != null) { |
| 3967 | mKeyguardMediator.onDreamingStopped(); |
| 3968 | } |
| 3969 | } |
| 3970 | } |
| 3971 | }; |
| 3972 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 3973 | BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() { |
| 3974 | @Override |
| 3975 | public void onReceive(Context context, Intent intent) { |
| 3976 | if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) { |
| 3977 | // tickle the settings observer: this first ensures that we're |
| 3978 | // observing the relevant settings for the newly-active user, |
| 3979 | // and then updates our own bookkeeping based on the now- |
| 3980 | // current user. |
| 3981 | mSettingsObserver.onChange(false); |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 3982 | |
| 3983 | // force a re-application of focused window sysui visibility. |
| 3984 | // the window may never have been shown for this user |
| 3985 | // e.g. the keyguard when going through the new-user setup flow |
| 3986 | synchronized(mLock) { |
| 3987 | mLastSystemUiFlags = 0; |
| 3988 | updateSystemUiVisibilityLw(); |
| 3989 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 3990 | } |
| 3991 | } |
| 3992 | }; |
| 3993 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 3994 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3995 | public void screenTurnedOff(int why) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 3996 | EventLog.writeEvent(70000, 0); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 3997 | synchronized (mLock) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 3998 | mScreenOnEarly = false; |
| 3999 | mScreenOnFully = false; |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 4000 | } |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4001 | if (mKeyguardMediator != null) { |
| 4002 | mKeyguardMediator.onScreenTurnedOff(why); |
| 4003 | } |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 4004 | synchronized (mLock) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4005 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4006 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4007 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4008 | } |
| 4009 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4010 | @Override |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 4011 | public void screenTurningOn(final ScreenOnListener screenOnListener) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 4012 | EventLog.writeEvent(70000, 1); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 4013 | if (false) { |
| 4014 | RuntimeException here = new RuntimeException("here"); |
| 4015 | here.fillInStackTrace(); |
| 4016 | Slog.i(TAG, "Screen turning on...", here); |
| 4017 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4018 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4019 | synchronized (mLock) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4020 | mScreenOnEarly = true; |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4021 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4022 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4023 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4024 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4025 | waitForKeyguard(screenOnListener); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4026 | } |
| 4027 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4028 | private void waitForKeyguard(final ScreenOnListener screenOnListener) { |
| 4029 | if (mKeyguardMediator != null) { |
| 4030 | if (screenOnListener != null) { |
| 4031 | mKeyguardMediator.onScreenTurnedOn(new KeyguardViewManager.ShowListener() { |
| 4032 | @Override |
| 4033 | public void onShown(IBinder windowToken) { |
| 4034 | waitForKeyguardWindowDrawn(windowToken, screenOnListener); |
| 4035 | } |
| 4036 | }); |
| 4037 | return; |
| 4038 | } else { |
| 4039 | mKeyguardMediator.onScreenTurnedOn(null); |
| 4040 | } |
| 4041 | } else { |
| 4042 | Slog.i(TAG, "No keyguard mediator!"); |
| 4043 | } |
| 4044 | finishScreenTurningOn(screenOnListener); |
| 4045 | } |
| 4046 | |
| 4047 | private void waitForKeyguardWindowDrawn(IBinder windowToken, |
| 4048 | final ScreenOnListener screenOnListener) { |
| 4049 | if (windowToken != null) { |
| 4050 | try { |
| 4051 | if (mWindowManager.waitForWindowDrawn( |
| 4052 | windowToken, new IRemoteCallback.Stub() { |
| 4053 | @Override |
| 4054 | public void sendResult(Bundle data) { |
| 4055 | Slog.i(TAG, "Lock screen displayed!"); |
| 4056 | finishScreenTurningOn(screenOnListener); |
| 4057 | } |
| 4058 | })) { |
| 4059 | return; |
| 4060 | } |
| 4061 | } catch (RemoteException ex) { |
| 4062 | // Can't happen in system process. |
| 4063 | } |
| 4064 | } |
| 4065 | |
| 4066 | Slog.i(TAG, "No lock screen!"); |
| 4067 | finishScreenTurningOn(screenOnListener); |
| 4068 | } |
| 4069 | |
| 4070 | private void finishScreenTurningOn(ScreenOnListener screenOnListener) { |
| 4071 | synchronized (mLock) { |
| 4072 | mScreenOnFully = true; |
| 4073 | } |
| 4074 | |
Jeff Brown | 4fc4527 | 2012-10-10 18:28:14 -0700 | [diff] [blame] | 4075 | try { |
| 4076 | mWindowManager.setEventDispatching(true); |
| 4077 | } catch (RemoteException unhandled) { |
| 4078 | } |
| 4079 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4080 | if (screenOnListener != null) { |
| 4081 | screenOnListener.onScreenOn(); |
| 4082 | } |
| 4083 | } |
| 4084 | |
| 4085 | @Override |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4086 | public boolean isScreenOnEarly() { |
| 4087 | return mScreenOnEarly; |
| 4088 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4089 | |
| 4090 | @Override |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4091 | public boolean isScreenOnFully() { |
| 4092 | return mScreenOnFully; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4093 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4094 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4095 | /** {@inheritDoc} */ |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4096 | public void enableKeyguard(boolean enabled) { |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4097 | if (mKeyguardMediator != null) { |
| 4098 | mKeyguardMediator.setKeyguardEnabled(enabled); |
| 4099 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4100 | } |
| 4101 | |
| 4102 | /** {@inheritDoc} */ |
| 4103 | public void exitKeyguardSecurely(OnKeyguardExitResult callback) { |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4104 | if (mKeyguardMediator != null) { |
| 4105 | mKeyguardMediator.verifyUnlock(callback); |
| 4106 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4107 | } |
| 4108 | |
Mike Lockwood | f791330 | 2009-11-28 22:27:10 -0500 | [diff] [blame] | 4109 | private boolean keyguardIsShowingTq() { |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4110 | if (mKeyguardMediator == null) return false; |
Dianne Hackborn | 9dc06cc | 2009-11-17 18:19:23 -0800 | [diff] [blame] | 4111 | return mKeyguardMediator.isShowingAndNotHidden(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4112 | } |
| 4113 | |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 4114 | |
| 4115 | /** {@inheritDoc} */ |
| 4116 | public boolean isKeyguardLocked() { |
| 4117 | return keyguardOn(); |
| 4118 | } |
| 4119 | |
| 4120 | /** {@inheritDoc} */ |
| 4121 | public boolean isKeyguardSecure() { |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4122 | if (mKeyguardMediator == null) return false; |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 4123 | return mKeyguardMediator.isSecure(); |
| 4124 | } |
| 4125 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4126 | /** {@inheritDoc} */ |
| 4127 | public boolean inKeyguardRestrictedKeyInputMode() { |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4128 | if (mKeyguardMediator == null) return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4129 | return mKeyguardMediator.isInputRestricted(); |
| 4130 | } |
| 4131 | |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 4132 | public void dismissKeyguardLw() { |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 4133 | if (mKeyguardMediator.isShowing()) { |
| 4134 | mHandler.post(new Runnable() { |
| 4135 | public void run() { |
| 4136 | if (mKeyguardMediator.isDismissable()) { |
| 4137 | // Can we just finish the keyguard straight away? |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 4138 | mKeyguardMediator.keyguardDone(false, true); |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 4139 | } else { |
| 4140 | // ask the keyguard to prompt the user to authenticate if necessary |
| 4141 | mKeyguardMediator.dismiss(); |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 4142 | } |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 4143 | } |
| 4144 | }); |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 4145 | } |
| 4146 | } |
| 4147 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4148 | void sendCloseSystemWindows() { |
| 4149 | sendCloseSystemWindows(mContext, null); |
| 4150 | } |
| 4151 | |
| 4152 | void sendCloseSystemWindows(String reason) { |
| 4153 | sendCloseSystemWindows(mContext, reason); |
| 4154 | } |
| 4155 | |
| 4156 | static void sendCloseSystemWindows(Context context, String reason) { |
| 4157 | if (ActivityManagerNative.isSystemReady()) { |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 4158 | try { |
| 4159 | ActivityManagerNative.getDefault().closeSystemDialogs(reason); |
| 4160 | } catch (RemoteException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4161 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4162 | } |
| 4163 | } |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 4164 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4165 | @Override |
| 4166 | public int rotationForOrientationLw(int orientation, int lastRotation) { |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 4167 | if (false) { |
| 4168 | Slog.v(TAG, "rotationForOrientationLw(orient=" |
| 4169 | + orientation + ", last=" + lastRotation |
| 4170 | + "); user=" + mUserRotation + " " |
| 4171 | + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) |
| 4172 | ? "USER_ROTATION_LOCKED" : "") |
| 4173 | ); |
| 4174 | } |
| 4175 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4176 | synchronized (mLock) { |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4177 | int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1 |
| 4178 | if (sensorRotation < 0) { |
Jeff Brown | 0f862b4 | 2012-09-27 21:11:01 -0700 | [diff] [blame] | 4179 | sensorRotation = lastRotation; |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4180 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4181 | |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4182 | final int preferredRotation; |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 4183 | if (mLidState == LID_OPEN && mLidOpenRotation >= 0) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4184 | // Ignore sensor when lid switch is open and rotation is forced. |
| 4185 | preferredRotation = mLidOpenRotation; |
| 4186 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4187 | && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4188 | // Ignore sensor when in car dock unless explicitly enabled. |
| 4189 | // This case can override the behavior of NOSENSOR, and can also |
| 4190 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4191 | preferredRotation = mCarDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4192 | ? sensorRotation : mCarDockRotation; |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 4193 | } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 4194 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 4195 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK) |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4196 | && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4197 | // Ignore sensor when in desk dock unless explicitly enabled. |
| 4198 | // This case can override the behavior of NOSENSOR, and can also |
| 4199 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4200 | preferredRotation = mDeskDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4201 | ? sensorRotation : mDeskDockRotation; |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 4202 | } else if (mHdmiPlugged && mHdmiRotationLock) { |
Jeff Brown | eb3e4b9 | 2011-12-06 19:54:24 -0800 | [diff] [blame] | 4203 | // Ignore sensor when plugged into HDMI. |
| 4204 | // Note that the dock orientation overrides the HDMI orientation. |
| 4205 | preferredRotation = mHdmiRotation; |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame^] | 4206 | } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) { |
| 4207 | // Application just wants to remain locked in the last rotation. |
| 4208 | preferredRotation = lastRotation; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 4209 | } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4210 | && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame^] | 4211 | || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 4212 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE |
| 4213 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT |
| 4214 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER)) |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4215 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 4216 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 4217 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE |
| 4218 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { |
| 4219 | // Otherwise, use sensor only if requested by the application or enabled |
| 4220 | // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR. |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 4221 | if (mAllowAllRotations < 0) { |
| 4222 | // Can't read this during init() because the context doesn't |
| 4223 | // have display metrics at that time so we cannot determine |
| 4224 | // tablet vs. phone then. |
| 4225 | mAllowAllRotations = mContext.getResources().getBoolean( |
| 4226 | com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0; |
| 4227 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4228 | if (sensorRotation != Surface.ROTATION_180 |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 4229 | || mAllowAllRotations == 1 |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame^] | 4230 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 4231 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4232 | preferredRotation = sensorRotation; |
| 4233 | } else { |
| 4234 | preferredRotation = lastRotation; |
| 4235 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 4236 | } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED |
| 4237 | && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { |
| 4238 | // Apply rotation lock. Does not apply to NOSENSOR. |
| 4239 | // The idea is that the user rotation expresses a weak preference for the direction |
| 4240 | // of gravity and as NOSENSOR is never affected by gravity, then neither should |
| 4241 | // 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] | 4242 | preferredRotation = mUserRotation; |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4243 | } else { |
| 4244 | // No overriding preference. |
| 4245 | // We will do exactly what the application asked us to do. |
| 4246 | preferredRotation = -1; |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4247 | } |
| 4248 | |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4249 | switch (orientation) { |
| 4250 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4251 | // Return portrait unless overridden. |
| 4252 | if (isAnyPortrait(preferredRotation)) { |
| 4253 | return preferredRotation; |
| 4254 | } |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4255 | return mPortraitRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4256 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4257 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4258 | // Return landscape unless overridden. |
| 4259 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 4260 | return preferredRotation; |
| 4261 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4262 | return mLandscapeRotation; |
| 4263 | |
| 4264 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4265 | // Return reverse portrait unless overridden. |
| 4266 | if (isAnyPortrait(preferredRotation)) { |
| 4267 | return preferredRotation; |
| 4268 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4269 | return mUpsideDownRotation; |
| 4270 | |
| 4271 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4272 | // Return seascape unless overridden. |
| 4273 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 4274 | return preferredRotation; |
| 4275 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4276 | return mSeascapeRotation; |
| 4277 | |
| 4278 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame^] | 4279 | case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4280 | // Return either landscape rotation. |
| 4281 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 4282 | return preferredRotation; |
| 4283 | } |
| 4284 | if (isLandscapeOrSeascape(lastRotation)) { |
Jeff Brown | 4519f07 | 2011-01-23 13:16:01 -0800 | [diff] [blame] | 4285 | return lastRotation; |
| 4286 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4287 | return mLandscapeRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4288 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4289 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame^] | 4290 | case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4291 | // Return either portrait rotation. |
| 4292 | if (isAnyPortrait(preferredRotation)) { |
| 4293 | return preferredRotation; |
| 4294 | } |
| 4295 | if (isAnyPortrait(lastRotation)) { |
| 4296 | return lastRotation; |
| 4297 | } |
| 4298 | return mPortraitRotation; |
| 4299 | |
| 4300 | default: |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 4301 | // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR, |
| 4302 | // just return the preferred orientation we already calculated. |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4303 | if (preferredRotation >= 0) { |
| 4304 | return preferredRotation; |
| 4305 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 4306 | return Surface.ROTATION_0; |
Daniel Sandler | e7e5ac2 | 2011-02-22 16:10:21 -0500 | [diff] [blame] | 4307 | } |
| 4308 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 4309 | } |
| 4310 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4311 | @Override |
| 4312 | public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) { |
| 4313 | switch (orientation) { |
| 4314 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
| 4315 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
| 4316 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
| 4317 | return isAnyPortrait(rotation); |
| 4318 | |
| 4319 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
| 4320 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
| 4321 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
| 4322 | return isLandscapeOrSeascape(rotation); |
| 4323 | |
| 4324 | default: |
| 4325 | return true; |
| 4326 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 4327 | } |
| 4328 | |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4329 | @Override |
| 4330 | public void setRotationLw(int rotation) { |
| 4331 | mOrientationListener.setCurrentRotation(rotation); |
| 4332 | } |
| 4333 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4334 | private boolean isLandscapeOrSeascape(int rotation) { |
| 4335 | return rotation == mLandscapeRotation || rotation == mSeascapeRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4336 | } |
| 4337 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4338 | private boolean isAnyPortrait(int rotation) { |
| 4339 | return rotation == mPortraitRotation || rotation == mUpsideDownRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4340 | } |
| 4341 | |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 4342 | public int getUserRotationMode() { |
| 4343 | return Settings.System.getIntForUser(mContext.getContentResolver(), |
| 4344 | Settings.System.USER_ROTATION, WindowManagerPolicy.USER_ROTATION_FREE, |
| 4345 | UserHandle.USER_CURRENT); |
| 4346 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4347 | |
| 4348 | // User rotation: to be used when all else fails in assigning an orientation to the device |
| 4349 | public void setUserRotationMode(int mode, int rot) { |
| 4350 | ContentResolver res = mContext.getContentResolver(); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 4351 | |
| 4352 | // mUserRotationMode and mUserRotation will be assigned by the content observer |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4353 | if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4354 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4355 | Settings.System.USER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4356 | rot, |
| 4357 | UserHandle.USER_CURRENT); |
| 4358 | Settings.System.putIntForUser(res, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 4359 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4360 | 0, |
| 4361 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4362 | } else { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4363 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4364 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4365 | 1, |
| 4366 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4367 | } |
| 4368 | } |
| 4369 | |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 4370 | public void setSafeMode(boolean safeMode) { |
| 4371 | mSafeMode = safeMode; |
| 4372 | performHapticFeedbackLw(null, safeMode |
| 4373 | ? HapticFeedbackConstants.SAFE_MODE_ENABLED |
| 4374 | : HapticFeedbackConstants.SAFE_MODE_DISABLED, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4375 | } |
| 4376 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 4377 | static long[] getLongIntArray(Resources r, int resid) { |
| 4378 | int[] ar = r.getIntArray(resid); |
| 4379 | if (ar == null) { |
| 4380 | return null; |
| 4381 | } |
| 4382 | long[] out = new long[ar.length]; |
| 4383 | for (int i=0; i<ar.length; i++) { |
| 4384 | out[i] = ar[i]; |
| 4385 | } |
| 4386 | return out; |
| 4387 | } |
| 4388 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4389 | /** {@inheritDoc} */ |
| 4390 | public void systemReady() { |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4391 | if (mKeyguardMediator != null) { |
| 4392 | // tell the keyguard |
| 4393 | mKeyguardMediator.onSystemReady(); |
| 4394 | } |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 4395 | synchronized (mLock) { |
| 4396 | updateOrientationListenerLp(); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 4397 | mSystemReady = true; |
| 4398 | mHandler.post(new Runnable() { |
| 4399 | public void run() { |
| 4400 | updateSettings(); |
| 4401 | } |
| 4402 | }); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4403 | } |
| 4404 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4405 | |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 4406 | /** {@inheritDoc} */ |
| 4407 | public void systemBooted() { |
| 4408 | synchronized (mLock) { |
| 4409 | mSystemBooted = true; |
| 4410 | } |
| 4411 | } |
| 4412 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4413 | ProgressDialog mBootMsgDialog = null; |
| 4414 | |
| 4415 | /** {@inheritDoc} */ |
| 4416 | public void showBootMessage(final CharSequence msg, final boolean always) { |
Mike Lockwood | aa5bf14 | 2011-09-21 13:03:40 -0400 | [diff] [blame] | 4417 | if (mHeadless) return; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4418 | mHandler.post(new Runnable() { |
| 4419 | @Override public void run() { |
| 4420 | if (mBootMsgDialog == null) { |
Dianne Hackborn | 295e3c2 | 2011-08-25 13:19:08 -0700 | [diff] [blame] | 4421 | mBootMsgDialog = new ProgressDialog(mContext) { |
| 4422 | // This dialog will consume all events coming in to |
| 4423 | // it, to avoid it trying to do things too early in boot. |
| 4424 | @Override public boolean dispatchKeyEvent(KeyEvent event) { |
| 4425 | return true; |
| 4426 | } |
| 4427 | @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 4428 | return true; |
| 4429 | } |
| 4430 | @Override public boolean dispatchTouchEvent(MotionEvent ev) { |
| 4431 | return true; |
| 4432 | } |
| 4433 | @Override public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 4434 | return true; |
| 4435 | } |
| 4436 | @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 4437 | return true; |
| 4438 | } |
| 4439 | @Override public boolean dispatchPopulateAccessibilityEvent( |
| 4440 | AccessibilityEvent event) { |
| 4441 | return true; |
| 4442 | } |
| 4443 | }; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4444 | mBootMsgDialog.setTitle(R.string.android_upgrading_title); |
| 4445 | mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
| 4446 | mBootMsgDialog.setIndeterminate(true); |
| 4447 | mBootMsgDialog.getWindow().setType( |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 4448 | WindowManager.LayoutParams.TYPE_BOOT_PROGRESS); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4449 | mBootMsgDialog.getWindow().addFlags( |
| 4450 | WindowManager.LayoutParams.FLAG_DIM_BEHIND |
| 4451 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); |
| 4452 | mBootMsgDialog.getWindow().setDimAmount(1); |
Dianne Hackborn | d9efb95 | 2011-12-07 14:56:51 -0800 | [diff] [blame] | 4453 | WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes(); |
| 4454 | lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; |
| 4455 | mBootMsgDialog.getWindow().setAttributes(lp); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4456 | mBootMsgDialog.setCancelable(false); |
| 4457 | mBootMsgDialog.show(); |
| 4458 | } |
| 4459 | mBootMsgDialog.setMessage(msg); |
| 4460 | } |
| 4461 | }); |
| 4462 | } |
| 4463 | |
| 4464 | /** {@inheritDoc} */ |
| 4465 | public void hideBootMessages() { |
| 4466 | mHandler.post(new Runnable() { |
| 4467 | @Override public void run() { |
| 4468 | if (mBootMsgDialog != null) { |
| 4469 | mBootMsgDialog.dismiss(); |
| 4470 | mBootMsgDialog = null; |
| 4471 | } |
| 4472 | } |
| 4473 | }); |
| 4474 | } |
| 4475 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4476 | /** {@inheritDoc} */ |
| 4477 | public void userActivity() { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4478 | // *************************************** |
| 4479 | // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE |
| 4480 | // *************************************** |
| 4481 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 4482 | // WITH ITS LOCKS HELD. |
| 4483 | // |
| 4484 | // This code must be VERY careful about the locks |
| 4485 | // it acquires. |
| 4486 | // In fact, the current code acquires way too many, |
| 4487 | // and probably has lurking deadlocks. |
| 4488 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4489 | synchronized (mScreenLockTimeout) { |
| 4490 | if (mLockScreenTimerActive) { |
| 4491 | // reset the timer |
| 4492 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 4493 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 4494 | } |
| 4495 | } |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 4496 | } |
| 4497 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 4498 | class ScreenLockTimeout implements Runnable { |
| 4499 | Bundle options; |
| 4500 | |
| 4501 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4502 | public void run() { |
| 4503 | synchronized (this) { |
| 4504 | if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard"); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4505 | if (mKeyguardMediator != null) { |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 4506 | mKeyguardMediator.doKeyguardTimeout(options); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4507 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4508 | mLockScreenTimerActive = false; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 4509 | options = null; |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4510 | } |
| 4511 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4512 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 4513 | public void setLockOptions(Bundle options) { |
| 4514 | this.options = options; |
| 4515 | } |
| 4516 | } |
| 4517 | |
| 4518 | ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout(); |
| 4519 | |
| 4520 | public void lockNow(Bundle options) { |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 4521 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); |
| 4522 | mHandler.removeCallbacks(mScreenLockTimeout); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 4523 | if (options != null) { |
| 4524 | // In case multiple calls are made to lockNow, we don't wipe out the options |
| 4525 | // until the runnable actually executes. |
| 4526 | mScreenLockTimeout.setLockOptions(options); |
| 4527 | } |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 4528 | mHandler.post(mScreenLockTimeout); |
| 4529 | } |
| 4530 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4531 | private void updateLockScreenTimeout() { |
| 4532 | synchronized (mScreenLockTimeout) { |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4533 | boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly && |
| 4534 | mKeyguardMediator != null && mKeyguardMediator.isSecure()); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4535 | if (mLockScreenTimerActive != enable) { |
| 4536 | if (enable) { |
| 4537 | if (localLOGV) Log.v(TAG, "setting lockscreen timer"); |
| 4538 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 4539 | } else { |
| 4540 | if (localLOGV) Log.v(TAG, "clearing lockscreen timer"); |
| 4541 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 4542 | } |
| 4543 | mLockScreenTimerActive = enable; |
| 4544 | } |
| 4545 | } |
| 4546 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4547 | |
| 4548 | /** {@inheritDoc} */ |
| 4549 | public void enableScreenAfterBoot() { |
| 4550 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4551 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4552 | updateRotation(true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4553 | } |
Dianne Hackborn | f54c8f9 | 2009-09-19 14:03:57 -0700 | [diff] [blame] | 4554 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4555 | private void applyLidSwitchState() { |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4556 | if (mLidState == LID_CLOSED && mLidControlsSleep) { |
| 4557 | mPowerManager.goToSleep(SystemClock.uptimeMillis()); |
| 4558 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4559 | } |
| 4560 | |
| 4561 | void updateRotation(boolean alwaysSendConfiguration) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4562 | try { |
| 4563 | //set orientation on WindowManager |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4564 | mWindowManager.updateRotation(alwaysSendConfiguration, false); |
| 4565 | } catch (RemoteException e) { |
| 4566 | // Ignore |
| 4567 | } |
| 4568 | } |
| 4569 | |
| 4570 | void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) { |
| 4571 | try { |
| 4572 | //set orientation on WindowManager |
| 4573 | mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4574 | } catch (RemoteException e) { |
| 4575 | // Ignore |
| 4576 | } |
| 4577 | } |
| 4578 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4579 | void startDockOrHome() { |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 4580 | awakenDreams(); |
Daniel Sandler | 7c13520 | 2012-09-28 14:04:59 -0400 | [diff] [blame] | 4581 | // We don't have dock home anymore. Home is home. If you lived here, you'd be home by now. |
Dianne Hackborn | d888399 | 2012-09-07 15:58:52 -0700 | [diff] [blame] | 4582 | mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4583 | } |
| 4584 | |
| 4585 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4586 | * goes to the home screen |
| 4587 | * @return whether it did anything |
| 4588 | */ |
| 4589 | boolean goHome() { |
| 4590 | if (false) { |
| 4591 | // This code always brings home to the front. |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 4592 | try { |
| 4593 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 4594 | } catch (RemoteException e) { |
| 4595 | } |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 4596 | sendCloseSystemWindows(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4597 | startDockOrHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4598 | } else { |
| 4599 | // This code brings home to the front or, if it is already |
| 4600 | // at the front, puts the device to sleep. |
| 4601 | try { |
Wink Saville | d2e6a33 | 2010-02-12 12:12:06 -0800 | [diff] [blame] | 4602 | if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) { |
| 4603 | /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry. |
| 4604 | Log.d(TAG, "UTS-TEST-MODE"); |
| 4605 | } else { |
| 4606 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 4607 | sendCloseSystemWindows(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4608 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4609 | int result = ActivityManagerNative.getDefault() |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 4610 | .startActivityAsUser(null, null, mHomeIntent, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4611 | mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4612 | null, null, 0, |
| 4613 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Dianne Hackborn | 5e03e2c | 2012-09-06 14:21:19 -0700 | [diff] [blame] | 4614 | null, null, null, UserHandle.USER_CURRENT); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4615 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4616 | return false; |
| 4617 | } |
| 4618 | } catch (RemoteException ex) { |
| 4619 | // bummer, the activity manager, which is in this process, is dead |
| 4620 | } |
| 4621 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4622 | return true; |
| 4623 | } |
| 4624 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4625 | public void setCurrentOrientationLw(int newOrientation) { |
| 4626 | synchronized (mLock) { |
| 4627 | if (newOrientation != mCurrentAppOrientation) { |
| 4628 | mCurrentAppOrientation = newOrientation; |
| 4629 | updateOrientationListenerLp(); |
| 4630 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4631 | } |
| 4632 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4633 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 4634 | private void performAuditoryFeedbackForAccessibilityIfNeed() { |
| 4635 | if (!isGlobalAccessibilityGestureEnabled()) { |
| 4636 | return; |
| 4637 | } |
| 4638 | AudioManager audioManager = (AudioManager) mContext.getSystemService( |
| 4639 | Context.AUDIO_SERVICE); |
| 4640 | if (audioManager.isSilentMode()) { |
| 4641 | return; |
| 4642 | } |
| 4643 | Ringtone ringTone = RingtoneManager.getRingtone(mContext, |
| 4644 | Settings.System.DEFAULT_NOTIFICATION_URI); |
| 4645 | ringTone.setStreamType(AudioManager.STREAM_MUSIC); |
| 4646 | ringTone.play(); |
| 4647 | } |
| 4648 | private boolean isGlobalAccessibilityGestureEnabled() { |
| 4649 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 4650 | Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1; |
| 4651 | } |
| 4652 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4653 | public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) { |
Svetoslav Ganov | 9617921 | 2012-10-10 14:17:45 -0700 | [diff] [blame] | 4654 | if (!mVibrator.hasVibrator()) { |
| 4655 | return false; |
| 4656 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4657 | final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 4658 | Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0; |
Dianne Hackborn | 9dc06cc | 2009-11-17 18:19:23 -0800 | [diff] [blame] | 4659 | if (!always && (hapticsDisabled || mKeyguardMediator.isShowingAndNotHidden())) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4660 | return false; |
| 4661 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4662 | long[] pattern = null; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4663 | switch (effectId) { |
| 4664 | case HapticFeedbackConstants.LONG_PRESS: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4665 | pattern = mLongPressVibePattern; |
| 4666 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 4667 | case HapticFeedbackConstants.VIRTUAL_KEY: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4668 | pattern = mVirtualKeyVibePattern; |
| 4669 | break; |
| 4670 | case HapticFeedbackConstants.KEYBOARD_TAP: |
| 4671 | pattern = mKeyboardTapVibePattern; |
| 4672 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 4673 | case HapticFeedbackConstants.SAFE_MODE_DISABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4674 | pattern = mSafeModeDisabledVibePattern; |
| 4675 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 4676 | case HapticFeedbackConstants.SAFE_MODE_ENABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4677 | pattern = mSafeModeEnabledVibePattern; |
| 4678 | break; |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4679 | default: |
| 4680 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4681 | } |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 4682 | int owningUid; |
| 4683 | String owningPackage; |
| 4684 | if (win != null) { |
| 4685 | owningUid = win.getOwningUid(); |
| 4686 | owningPackage = win.getOwningPackage(); |
| 4687 | } else { |
| 4688 | owningUid = android.os.Process.myUid(); |
| 4689 | owningPackage = mContext.getBasePackageName(); |
| 4690 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4691 | if (pattern.length == 1) { |
| 4692 | // One-shot vibration |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 4693 | mVibrator.vibrate(owningUid, owningPackage, pattern[0]); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4694 | } else { |
| 4695 | // Pattern vibration |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 4696 | mVibrator.vibrate(owningUid, owningPackage, pattern, -1); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4697 | } |
| 4698 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4699 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4700 | |
| 4701 | @Override |
| 4702 | public void keepScreenOnStartedLw() { |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 4703 | } |
| 4704 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4705 | @Override |
| 4706 | public void keepScreenOnStoppedLw() { |
| 4707 | if (mKeyguardMediator != null && !mKeyguardMediator.isShowingAndNotHidden()) { |
| 4708 | long curTime = SystemClock.uptimeMillis(); |
| 4709 | mPowerManager.userActivity(curTime, false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4710 | } |
| 4711 | } |
Mike Lockwood | fcb3924 | 2009-10-21 23:01:07 -0400 | [diff] [blame] | 4712 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4713 | private int updateSystemUiVisibilityLw() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4714 | // If there is no window focused, there will be nobody to handle the events |
| 4715 | // anyway, so just hang on in whatever state we're in until things settle down. |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4716 | if (mFocusedWindow == null) { |
| 4717 | return 0; |
| 4718 | } |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4719 | if (mFocusedWindow.getAttrs().type == TYPE_KEYGUARD && mHideLockScreen == true) { |
| 4720 | // We are updating at a point where the keyguard has gotten |
| 4721 | // focus, but we were last in a state where the top window is |
| 4722 | // hiding it. This is probably because the keyguard as been |
| 4723 | // shown while the top window was displayed, so we want to ignore |
| 4724 | // it here because this is just a very transient change and it |
| 4725 | // will quickly lose focus once it correctly gets hidden. |
| 4726 | return 0; |
| 4727 | } |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 4728 | int tmpVisibility = mFocusedWindow.getSystemUiVisibility() |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4729 | & ~mResettingSystemUiFlags |
| 4730 | & ~mForceClearedSystemUiFlags; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 4731 | if (mForcingShowNavBar && mFocusedWindow.getSurfaceLayer() < mForcingShowNavBarLayer) { |
| 4732 | tmpVisibility &= ~View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 4733 | } |
| 4734 | final int visibility = tmpVisibility; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4735 | int diff = visibility ^ mLastSystemUiFlags; |
Dianne Hackborn | 73ab6a4 | 2011-12-13 11:16:23 -0800 | [diff] [blame] | 4736 | final boolean needsMenu = mFocusedWindow.getNeedsMenuLw(mTopFullscreenOpaqueWindowState); |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 4737 | if (diff == 0 && mLastFocusNeedsMenu == needsMenu |
| 4738 | && mFocusedApp == mFocusedWindow.getAppToken()) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4739 | return 0; |
| 4740 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4741 | mLastSystemUiFlags = visibility; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 4742 | mLastFocusNeedsMenu = needsMenu; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 4743 | mFocusedApp = mFocusedWindow.getAppToken(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4744 | mHandler.post(new Runnable() { |
| 4745 | public void run() { |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4746 | try { |
| 4747 | IStatusBarService statusbar = getStatusBarService(); |
| 4748 | if (statusbar != null) { |
| 4749 | statusbar.setSystemUiVisibility(visibility, 0xffffffff); |
| 4750 | statusbar.topAppWindowChanged(needsMenu); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4751 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4752 | } catch (RemoteException e) { |
| 4753 | // re-acquire status bar service next time it is needed. |
| 4754 | mStatusBarService = null; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4755 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4756 | } |
| 4757 | }); |
| 4758 | return diff; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4759 | } |
| 4760 | |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 4761 | // Use this instead of checking config_showNavigationBar so that it can be consistently |
| 4762 | // overridden by qemu.hw.mainkeys in the emulator. |
| 4763 | public boolean hasNavigationBar() { |
| 4764 | return mHasNavigationBar; |
| 4765 | } |
| 4766 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4767 | @Override |
| 4768 | public void setLastInputMethodWindowLw(WindowState ime, WindowState target) { |
| 4769 | mLastInputMethodWindow = ime; |
| 4770 | mLastInputMethodTargetWindow = target; |
| 4771 | } |
| 4772 | |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 4773 | @Override |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 4774 | public void setCurrentUserLw(int newUserId) { |
| 4775 | if (mKeyguardMediator != null) { |
| 4776 | mKeyguardMediator.setCurrentUser(newUserId); |
| 4777 | } |
John Spurlock | 13451a2 | 2012-09-28 14:40:41 -0400 | [diff] [blame] | 4778 | if (mStatusBarService != null) { |
| 4779 | try { |
| 4780 | mStatusBarService.setCurrentUser(newUserId); |
| 4781 | } catch (RemoteException e) { |
| 4782 | // oh well |
| 4783 | } |
| 4784 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 4785 | setLastInputMethodWindowLw(null, null); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 4786 | } |
| 4787 | |
| 4788 | @Override |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 4789 | public void showAssistant() { |
| 4790 | mKeyguardMediator.showAssistant(); |
| 4791 | } |
| 4792 | |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 4793 | @Override |
| 4794 | public boolean canMagnifyWindow(int windowType) { |
| 4795 | switch (windowType) { |
| 4796 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD: |
| 4797 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG: |
| 4798 | case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR: |
| 4799 | case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: { |
| 4800 | return false; |
| 4801 | } |
| 4802 | } |
| 4803 | return true; |
| 4804 | } |
| 4805 | |
| 4806 | @Override |
| 4807 | public boolean isTopLevelWindow(int windowType) { |
| 4808 | if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW |
| 4809 | && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 4810 | return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG); |
| 4811 | } |
| 4812 | return true; |
| 4813 | } |
| 4814 | |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 4815 | @Override |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 4816 | public void dump(String prefix, PrintWriter pw, String[] args) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4817 | pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 4818 | pw.print(" mSystemReady="); pw.print(mSystemReady); |
| 4819 | pw.print(" mSystemBooted="); pw.println(mSystemBooted); |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 4820 | pw.print(prefix); pw.print("mLidState="); pw.print(mLidState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4821 | pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation); |
| 4822 | pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 4823 | if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0 |
| 4824 | || mForceClearedSystemUiFlags != 0) { |
| 4825 | pw.print(prefix); pw.print("mLastSystemUiFlags=0x"); |
| 4826 | pw.print(Integer.toHexString(mLastSystemUiFlags)); |
| 4827 | pw.print(" mResettingSystemUiFlags=0x"); |
| 4828 | pw.print(Integer.toHexString(mResettingSystemUiFlags)); |
| 4829 | pw.print(" mForceClearedSystemUiFlags=0x"); |
| 4830 | pw.println(Integer.toHexString(mForceClearedSystemUiFlags)); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4831 | } |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 4832 | if (mLastFocusNeedsMenu) { |
| 4833 | pw.print(prefix); pw.print("mLastFocusNeedsMenu="); |
| 4834 | pw.println(mLastFocusNeedsMenu); |
| 4835 | } |
Daniel Sandler | 7c13520 | 2012-09-28 14:04:59 -0400 | [diff] [blame] | 4836 | pw.print(prefix); pw.print("mDockMode="); pw.print(mDockMode); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4837 | pw.print(" mCarDockRotation="); pw.print(mCarDockRotation); |
| 4838 | pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation); |
| 4839 | pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode); |
| 4840 | pw.print(" mUserRotation="); pw.print(mUserRotation); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 4841 | pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 4842 | pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4843 | pw.print(prefix); pw.print("mCarDockEnablesAccelerometer="); |
| 4844 | pw.print(mCarDockEnablesAccelerometer); |
| 4845 | pw.print(" mDeskDockEnablesAccelerometer="); |
| 4846 | pw.println(mDeskDockEnablesAccelerometer); |
| 4847 | pw.print(prefix); pw.print("mLidKeyboardAccessibility="); |
| 4848 | pw.print(mLidKeyboardAccessibility); |
| 4849 | pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 4850 | pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep); |
| 4851 | pw.print(prefix); pw.print("mLongPressOnPowerBehavior="); |
| 4852 | pw.print(mLongPressOnPowerBehavior); |
| 4853 | pw.print(" mHasSoftInput="); pw.println(mHasSoftInput); |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4854 | pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly); |
| 4855 | pw.print(" mScreenOnFully="); pw.print(mScreenOnFully); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 4856 | pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4857 | pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft); |
| 4858 | pw.print(","); pw.print(mOverscanScreenTop); |
| 4859 | pw.print(") "); pw.print(mOverscanScreenWidth); |
| 4860 | pw.print("x"); pw.println(mOverscanScreenHeight); |
| 4861 | if (mOverscanLeft != 0 || mOverscanTop != 0 |
| 4862 | || mOverscanRight != 0 || mOverscanBottom != 0) { |
| 4863 | pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft); |
| 4864 | pw.print(" top="); pw.print(mOverscanTop); |
| 4865 | pw.print(" right="); pw.print(mOverscanRight); |
| 4866 | pw.print(" bottom="); pw.println(mOverscanBottom); |
| 4867 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 4868 | pw.print(prefix); pw.print("mRestrictedOverscanScreen=("); |
| 4869 | pw.print(mRestrictedOverscanScreenLeft); |
| 4870 | pw.print(","); pw.print(mRestrictedOverscanScreenTop); |
| 4871 | pw.print(") "); pw.print(mRestrictedOverscanScreenWidth); |
| 4872 | pw.print("x"); pw.println(mRestrictedOverscanScreenHeight); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4873 | pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft); |
| 4874 | pw.print(","); pw.print(mUnrestrictedScreenTop); |
| 4875 | pw.print(") "); pw.print(mUnrestrictedScreenWidth); |
| 4876 | pw.print("x"); pw.println(mUnrestrictedScreenHeight); |
| 4877 | pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft); |
| 4878 | pw.print(","); pw.print(mRestrictedScreenTop); |
| 4879 | pw.print(") "); pw.print(mRestrictedScreenWidth); |
| 4880 | pw.print("x"); pw.println(mRestrictedScreenHeight); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4881 | pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft); |
| 4882 | pw.print(","); pw.print(mStableFullscreenTop); |
| 4883 | pw.print(")-("); pw.print(mStableFullscreenRight); |
| 4884 | pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")"); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4885 | pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft); |
| 4886 | pw.print(","); pw.print(mStableTop); |
| 4887 | pw.print(")-("); pw.print(mStableRight); |
| 4888 | pw.print(","); pw.print(mStableBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 4889 | pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft); |
| 4890 | pw.print(","); pw.print(mSystemTop); |
| 4891 | pw.print(")-("); pw.print(mSystemRight); |
| 4892 | pw.print(","); pw.print(mSystemBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4893 | pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft); |
| 4894 | pw.print(","); pw.print(mCurTop); |
| 4895 | pw.print(")-("); pw.print(mCurRight); |
| 4896 | pw.print(","); pw.print(mCurBottom); pw.println(")"); |
| 4897 | pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft); |
| 4898 | pw.print(","); pw.print(mContentTop); |
| 4899 | pw.print(")-("); pw.print(mContentRight); |
| 4900 | pw.print(","); pw.print(mContentBottom); pw.println(")"); |
| 4901 | pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft); |
| 4902 | pw.print(","); pw.print(mDockTop); |
| 4903 | pw.print(")-("); pw.print(mDockRight); |
| 4904 | pw.print(","); pw.print(mDockBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 4905 | pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer); |
| 4906 | pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer); |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4907 | pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen); |
| 4908 | pw.print(" mShowingDream="); pw.print(mShowingDream); |
| 4909 | pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 4910 | if (mLastInputMethodWindow != null) { |
| 4911 | pw.print(prefix); pw.print("mLastInputMethodWindow="); |
| 4912 | pw.println(mLastInputMethodWindow); |
| 4913 | } |
| 4914 | if (mLastInputMethodTargetWindow != null) { |
| 4915 | pw.print(prefix); pw.print("mLastInputMethodTargetWindow="); |
| 4916 | pw.println(mLastInputMethodTargetWindow); |
| 4917 | } |
| 4918 | if (mStatusBar != null) { |
| 4919 | pw.print(prefix); pw.print("mStatusBar="); |
| 4920 | pw.println(mStatusBar); |
| 4921 | } |
| 4922 | if (mNavigationBar != null) { |
| 4923 | pw.print(prefix); pw.print("mNavigationBar="); |
| 4924 | pw.println(mNavigationBar); |
| 4925 | } |
| 4926 | if (mKeyguard != null) { |
| 4927 | pw.print(prefix); pw.print("mKeyguard="); |
| 4928 | pw.println(mKeyguard); |
| 4929 | } |
| 4930 | if (mFocusedWindow != null) { |
| 4931 | pw.print(prefix); pw.print("mFocusedWindow="); |
| 4932 | pw.println(mFocusedWindow); |
| 4933 | } |
| 4934 | if (mFocusedApp != null) { |
| 4935 | pw.print(prefix); pw.print("mFocusedApp="); |
| 4936 | pw.println(mFocusedApp); |
| 4937 | } |
| 4938 | if (mWinDismissingKeyguard != null) { |
| 4939 | pw.print(prefix); pw.print("mWinDismissingKeyguard="); |
| 4940 | pw.println(mWinDismissingKeyguard); |
| 4941 | } |
| 4942 | if (mTopFullscreenOpaqueWindowState != null) { |
| 4943 | pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState="); |
| 4944 | pw.println(mTopFullscreenOpaqueWindowState); |
| 4945 | } |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 4946 | if (mForcingShowNavBar) { |
| 4947 | pw.print(prefix); pw.print("mForcingShowNavBar="); |
| 4948 | pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer="); |
| 4949 | pw.println(mForcingShowNavBarLayer); |
| 4950 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4951 | pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4952 | pw.print(" mHideLockScreen="); pw.println(mHideLockScreen); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4953 | pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar); |
| 4954 | pw.print(" mForceStatusBarFromKeyguard="); |
| 4955 | pw.println(mForceStatusBarFromKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4956 | pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4957 | pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4958 | pw.print(" mHomePressed="); pw.println(mHomePressed); |
| 4959 | pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn); |
| 4960 | pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout); |
| 4961 | pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive); |
| 4962 | pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior); |
| 4963 | pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior); |
| 4964 | pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior); |
| 4965 | pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation); |
| 4966 | pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation); |
| 4967 | pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation); |
| 4968 | pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation); |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 4969 | pw.print(prefix); pw.print("mHdmiRotation="); pw.print(mHdmiRotation); |
| 4970 | pw.print(" mHdmiRotationLock="); pw.println(mHdmiRotationLock); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4971 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4972 | } |